Skip to content

The open alternative to Salesforce, designed for AI.

Fix contributor website import script (#8404)

Félix Malfaitb2004fe6b490
diff --git a/packages/twenty-website/src/database/database.ts b/packages/twenty-website/src/database/database.ts
index 69b30d2ebf0..7b43e4715d5 100644
--- a/packages/twenty-website/src/database/database.ts
+++ b/packages/twenty-website/src/database/database.ts
@@ -35,6 +35,7 @@ const insertMany = async (
options?: {
onConflictKey?: string;
onConflictUpdateObject?: any;
+ onConflictDoNothing?: boolean;
},
) => {
const query = pgDb.insert(model).values(data);
@@ -50,6 +51,10 @@ const insertMany = async (
}
}
+ if (options?.onConflictDoNothing && !options?.onConflictKey) {
+ return query.onConflictDoNothing().execute();
+ }
+
if (options?.onConflictKey) {
return query
.onConflictDoNothing({
diff --git a/packages/twenty-website/src/github/contributors/get-latest-update.tsx b/packages/twenty-website/src/github/contributors/get-latest-update.tsx
index 9b2e03e7272..9f8a87ead13 100644
--- a/packages/twenty-website/src/github/contributors/get-latest-update.tsx
+++ b/packages/twenty-website/src/github/contributors/get-latest-update.tsx
@@ -9,7 +9,11 @@ export async function getLatestUpdate() {
desc(pullRequestModel.updatedAt),
);
const latestIssue = await findOne(issueModel, desc(issueModel.updatedAt));
- const prDate = new Date(latestPR[0].updatedAt);
- const issueDate = new Date(latestIssue[0].updatedAt);
+ const prDate = latestPR[0]
+ ? new Date(latestPR[0].updatedAt)
+ : new Date('2023-01-01');
+ const issueDate = latestIssue[0]
+ ? new Date(latestIssue[0].updatedAt)
+ : new Date('2023-01-01');
return (prDate > issueDate ? prDate : issueDate).toISOString();
}
diff --git a/packages/twenty-website/src/github/contributors/save-issues-to-db.tsx b/packages/twenty-website/src/github/contributors/save-issues-to-db.tsx
index 0b8e70e2878..2fe358c5f15 100644
--- a/packages/twenty-website/src/github/contributors/save-issues-to-db.tsx
+++ b/packages/twenty-website/src/github/contributors/save-issues-to-db.tsx
@@ -82,12 +82,18 @@ export async function saveIssuesToDB(
},
},
);
- await insertMany(issueLabelModel, [
+ await insertMany(
+ issueLabelModel,
+ [
+ {
+ issueId: issue.id,
+ labelId: label.id,
+ },
+ ],
{
- pullRequestId: issue.id,
- labelId: label.id,
+ onConflictDoNothing: true,
},
- ]);
+ );
}
}
}
diff --git a/packages/twenty-website/src/github/contributors/save-prs-to-db.tsx b/packages/twenty-website/src/github/contributors/save-prs-to-db.tsx
index abc5f7088e6..35642300794 100644
--- a/packages/twenty-website/src/github/contributors/save-prs-to-db.tsx
+++ b/packages/twenty-website/src/github/contributors/save-prs-to-db.tsx
@@ -85,12 +85,18 @@ export async function savePRsToDB(
},
},
);
- await insertMany(pullRequestLabelModel, [
+ await insertMany(
+ pullRequestLabelModel,
+ [
+ {
+ pullRequestId: pr.id,
+ labelId: label.id,
+ },
+ ],
{
- pullRequestId: pr.id,
- labelId: label.id,
+ onConflictDoNothing: true,
},
- ]);
+ );
}
}
}
diff --git a/packages/twenty-website/src/github/execute-partial-sync.ts b/packages/twenty-website/src/github/execute-partial-sync.ts
index 77922d67340..16b250de685 100644
--- a/packages/twenty-website/src/github/execute-partial-sync.ts
+++ b/packages/twenty-website/src/github/execute-partial-sync.ts
@@ -13,7 +13,7 @@ export const executePartialSync = async () => {
return new Error('No GitHub token provided');
}
- console.log('Synching data..');
+ console.log('Syncing data... (partial sync)');
const query = graphql.defaults({
headers: {
diff --git a/packages/twenty-website/src/github/fetch-and-save-github-data.ts b/packages/twenty-website/src/github/fetch-and-save-github-data.ts
index 42e902fe14d..ddfc7783073 100644
--- a/packages/twenty-website/src/github/fetch-and-save-github-data.ts
+++ b/packages/twenty-website/src/github/fetch-and-save-github-data.ts
@@ -14,7 +14,7 @@ export const fetchAndSaveGithubData = async () => {
return new Error('No GitHub token provided');
}
- console.log('Synching data..');
+ console.log('Syncing data...');
const query = graphql.defaults({
headers: {