Files
twenty_crm/packages/twenty-website/src/github/contributors/search-issues-prs.tsx
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

103 lines
2.6 KiB
TypeScript

import { graphql } from '@octokit/graphql';
import { getLatestUpdate } from '@/github/contributors/get-latest-update';
import {
IssueNode,
PullRequestNode,
SearchIssuesPRsQuery,
} from '@/github/contributors/types';
export async function searchIssuesPRs(
query: typeof graphql,
cursor: string | null = null,
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:>${since}", type: ISSUE, first: 100, after: $cursor) {
edges {
node {
... on PullRequest {
id
title
body
url
createdAt
updatedAt
closedAt
mergedAt
author {
resourcePath
login
avatarUrl(size: 460)
url
}
labels(first: 100) {
nodes {
id
name
color
description
}
}
}
... on Issue {
id
title
body
url
createdAt
updatedAt
closedAt
author {
resourcePath
login
avatarUrl
url
}
labels(first: 100) {
nodes {
id
name
color
description
}
}
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
`,
{
cursor,
},
);
const newAccumulatedData: Array<PullRequestNode | IssueNode> = [
...accumulatedData,
...search.edges.map(({ node }) => node),
];
const pageInfo = search.pageInfo;
if (pageInfo.hasNextPage) {
return searchIssuesPRs(
query,
pageInfo.endCursor,
isIssues,
newAccumulatedData,
);
} else {
return newAccumulatedData;
}
}