Files
twenty/packages/twenty-website/src/github/fetch-and-save-github-data.ts
Ady Beraud 5ad59b5845 Create congratulations bot (#5404)
- Created congratulations bot :
<img width="939" alt="Screenshot 2024-05-14 at 12 47 13"
src="https://github.com/twentyhq/twenty/assets/102751374/5138515f-fe4d-4c6d-9c7a-0240accbfca9">

- Modified OG image

- Added png extension to OG image route

To be noted: The bot will not work until the new API route is not
deployed. Please check OG image with Cloudflare cache.

---------

Co-authored-by: Ady Beraud <a.beraud96@gmail.com>
2024-05-21 22:56:25 +02:00

47 lines
1.5 KiB
TypeScript

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 () => {
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!');
};