Make Github stars dynamic and improve database init (#5000)
I extracted the init database logic into its own file. You can now run it with yarn database:init. Added database entry for GitHub stars. Do you want me to remove the init route or is it used for something else ? --------- Co-authored-by: Ady Beraud <a.beraud96@gmail.com> Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
@ -0,0 +1,44 @@
|
||||
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 { 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);
|
||||
|
||||
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>;
|
||||
|
||||
savePRsToDB(fetchedPRs, assignableUsers);
|
||||
saveIssuesToDB(fetchedIssues, assignableUsers);
|
||||
|
||||
console.log('data synched!');
|
||||
};
|
||||
Reference in New Issue
Block a user