Added GitHub init (#5317)

- Added github:init to allow full import, as opposed to gitHub:sync
which allows partial sync and therefore respecting Github API Limit
quota.

---------

Co-authored-by: Ady Beraud <a.beraud96@gmail.com>
This commit is contained in:
Ady Beraud
2024-05-13 10:55:30 +03:00
committed by GitHub
parent 321ce72ec7
commit 4a7aabd060
12 changed files with 49 additions and 26 deletions

View File

@@ -0,0 +1,52 @@
import { global } from '@apollo/client/utilities/globals';
import { graphql } from '@octokit/graphql';
import { fetchAssignableUsers } from '@/github/contributors/fetch-assignable-users';
import { fetchIssuesPRs } from '@/github/contributors/fetch-issues-prs';
import { saveIssuesToDB } from '@/github/contributors/save-issues-to-db';
import { savePRsToDB } from '@/github/contributors/save-prs-to-db';
import { IssueNode, PullRequestNode } from '@/github/contributors/types';
import { fetchAndSaveGithubReleases } from '@/github/github-releases/fetch-and-save-github-releases';
import { fetchAndSaveGithubStars } from '@/github/github-stars/fetch-and-save-github-stars';
export const fetchAndSaveGithubData = async ({
pageLimit,
}: {
pageLimit: number;
}) => {
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,
[],
pageLimit,
)) as Array<PullRequestNode>;
const fetchedIssues = (await fetchIssuesPRs(
query,
null,
true,
[],
pageLimit,
)) as Array<IssueNode>;
await savePRsToDB(fetchedPRs, assignableUsers);
await saveIssuesToDB(fetchedIssues, assignableUsers);
console.log('data synched!');
};