Files
twenty/packages/twenty-website/src/github-sync/fetch-and-save-github-data.ts
Ady Beraud 3052b49031 Fixed incomplete GitHub sync (#5310)
- Added await when fetching Github data to prevent the process from
exiting before saving to database

Co-authored-by: Ady Beraud <a.beraud96@gmail.com>
2024-05-07 08:59:56 +02:00

47 lines
1.5 KiB
TypeScript

import { global } from '@apollo/client/utilities/globals';
import { graphql } from '@octokit/graphql';
import { fetchAssignableUsers } from '@/github-sync/contributors/fetch-assignable-users';
import { fetchIssuesPRs } from '@/github-sync/contributors/fetch-issues-prs';
import { saveIssuesToDB } from '@/github-sync/contributors/save-issues-to-db';
import { savePRsToDB } from '@/github-sync/contributors/save-prs-to-db';
import { IssueNode, PullRequestNode } from '@/github-sync/contributors/types';
import { fetchAndSaveGithubReleases } from '@/github-sync/github-releases/fetch-and-save-github-releases';
import { fetchAndSaveGithubStars } from '@/github-sync/github-stars/fetch-and-save-github-stars';
export const fetchAndSaveGithubData = async () => {
if (!global.process.env.GITHUB_TOKEN) {
return new Error('No GitHub token provided');
}
console.log('Synching data..');
const query = graphql.defaults({
headers: {
Authorization: 'bearer ' + global.process.env.GITHUB_TOKEN,
},
});
await fetchAndSaveGithubStars(query);
await fetchAndSaveGithubReleases(query);
const assignableUsers = await fetchAssignableUsers(query);
const fetchedPRs = (await fetchIssuesPRs(
query,
null,
false,
[],
)) as Array<PullRequestNode>;
const fetchedIssues = (await fetchIssuesPRs(
query,
null,
true,
[],
)) as Array<IssueNode>;
await savePRsToDB(fetchedPRs, assignableUsers);
await saveIssuesToDB(fetchedIssues, assignableUsers);
console.log('data synched!');
};