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>
This commit is contained in:
Ady Beraud
2024-05-21 23:56:25 +03:00
committed by GitHub
parent 3deda2f29a
commit 5ad59b5845
17 changed files with 277 additions and 73 deletions

View File

@ -6,22 +6,17 @@ import {
Repository,
} from '@/github/contributors/types';
// TODO: We should implement a true partial sync instead of using pageLimit.
// Check search-issues-prs.tsx and modify "updated:>2024-02-27" to make it dynamic
export async function fetchIssuesPRs(
query: typeof graphql,
cursor: string | null = null,
isIssues = false,
accumulatedData: Array<PullRequestNode | IssueNode> = [],
pageLimit: number,
currentPage = 0,
): Promise<Array<PullRequestNode | IssueNode>> {
const { repository } = await query<Repository>(
`
query ($cursor: String) {
repository(owner: "twentyhq", name: "twenty") {
pullRequests(first: 30, after: $cursor, orderBy: {field: CREATED_AT, direction: DESC}) @skip(if: ${isIssues}) {
pullRequests(first: 100, after: $cursor, orderBy: {field: CREATED_AT, direction: DESC}) @skip(if: ${isIssues}) {
nodes {
id
title
@ -94,16 +89,12 @@ export async function fetchIssuesPRs(
? repository.issues.pageInfo
: repository.pullRequests.pageInfo;
const newCurrentPage = currentPage + 1;
if ((!pageLimit || newCurrentPage < pageLimit) && pageInfo.hasNextPage) {
if (pageInfo.hasNextPage) {
return fetchIssuesPRs(
query,
pageInfo.endCursor,
isIssues,
newAccumulatedData,
pageLimit,
currentPage + 1,
);
} else {
return newAccumulatedData;

View File

@ -0,0 +1,15 @@
import { desc } from 'drizzle-orm';
import { findOne } from '@/database/database';
import { issueModel, pullRequestModel } from '@/database/model';
export async function getLatestUpdate() {
const latestPR = await findOne(
pullRequestModel,
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);
return (prDate > issueDate ? prDate : issueDate).toISOString();
}

View File

@ -42,7 +42,10 @@ export async function saveIssuesToDB(
authorId: issue.author.login,
},
],
{ onConflictKey: 'id' },
{
onConflictKey: 'id',
onConflictUpdateObject: { updatedAt: issue.updatedAt },
},
);
for (const label of issue.labels.nodes) {

View File

@ -44,7 +44,10 @@ export async function savePRsToDB(
authorId: pr.author.login,
},
],
{ onConflictKey: 'id', onConflictUpdateObject: { title: pr.title } },
{
onConflictKey: 'id',
onConflictUpdateObject: { title: pr.title, updatedAt: pr.updatedAt },
},
);
for (const label of pr.labels.nodes) {

View File

@ -1,5 +1,6 @@
import { graphql } from '@octokit/graphql';
import { getLatestUpdate } from '@/github/contributors/get-latest-update';
import {
IssueNode,
PullRequestNode,
@ -12,12 +13,13 @@ export async function searchIssuesPRs(
isIssues = false,
accumulatedData: Array<PullRequestNode | IssueNode> = [],
): Promise<Array<PullRequestNode | IssueNode>> {
const since = await getLatestUpdate();
const { search } = await query<SearchIssuesPRsQuery>(
`
query searchPullRequestsAndIssues($cursor: String) {
search(query: "repo:twentyhq/twenty ${
isIssues ? 'is:issue' : 'is:pr'
} updated:>2024-02-27", type: ISSUE, first: 100, after: $cursor) {
} updated:>${since}", type: ISSUE, first: 100, after: $cursor) {
edges {
node {
... on PullRequest {
@ -80,6 +82,7 @@ export async function searchIssuesPRs(
cursor,
},
);
const newAccumulatedData: Array<PullRequestNode | IssueNode> = [
...accumulatedData,
...search.edges.map(({ node }) => node),