mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-23 03:51:36 +03:00
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:
parent
3deda2f29a
commit
5ad59b5845
14
.github/workflows/ci-utils.yaml
vendored
14
.github/workflows/ci-utils.yaml
vendored
@ -5,6 +5,7 @@ on:
|
|||||||
# see: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
|
# see: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
|
||||||
# and: https://github.com/facebook/react-native/pull/34370/files
|
# and: https://github.com/facebook/react-native/pull/34370/files
|
||||||
pull_request_target:
|
pull_request_target:
|
||||||
|
types: [opened, synchronize, reopened, closed]
|
||||||
permissions:
|
permissions:
|
||||||
actions: write
|
actions: write
|
||||||
checks: write
|
checks: write
|
||||||
@ -19,6 +20,7 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
danger-js:
|
danger-js:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event.action != 'closed'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
@ -27,3 +29,15 @@ jobs:
|
|||||||
run: cd packages/twenty-utils && npx nx danger:ci
|
run: cd packages/twenty-utils && npx nx danger:ci
|
||||||
env:
|
env:
|
||||||
DANGER_GITHUB_API_TOKEN: ${{ github.token }}
|
DANGER_GITHUB_API_TOKEN: ${{ github.token }}
|
||||||
|
|
||||||
|
congratulate:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event.action == 'closed' && github.event.pull_request.merged == true
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Install dependencies
|
||||||
|
uses: ./.github/workflows/actions/yarn-install
|
||||||
|
- name: Run congratulate-dangerfile.js
|
||||||
|
run: cd packages/twenty-utils && npx nx danger:congratulate
|
||||||
|
env:
|
||||||
|
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
109
packages/twenty-utils/congratulate-dangerfile.ts
Normal file
109
packages/twenty-utils/congratulate-dangerfile.ts
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
import { danger } from 'danger';
|
||||||
|
|
||||||
|
const ordinalSuffix = (number) => {
|
||||||
|
const v = number % 100;
|
||||||
|
if (v === 11 || v === 12 || v === 13) {
|
||||||
|
return number + 'th';
|
||||||
|
}
|
||||||
|
const suffixes = { 1: 'st', 2: 'nd', 3: 'rd' };
|
||||||
|
return number + (suffixes[v % 10] || 'th');
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchContributorStats = async (username: string) => {
|
||||||
|
const apiUrl = `https://twenty.com/api/contributors/contributorStats/${username}`;
|
||||||
|
|
||||||
|
const response = await fetch(apiUrl);
|
||||||
|
const data = await response.json();
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchContributorImage = async (username: string) => {
|
||||||
|
const apiUrl = `https://twenty.com/api/contributors/${username}/og.png`;
|
||||||
|
|
||||||
|
await fetch(apiUrl);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getTeamMembers = async () => {
|
||||||
|
const org = 'twentyhq';
|
||||||
|
const team_slug = 'core-team';
|
||||||
|
const response = await danger.github.api.teams.listMembersInOrg({
|
||||||
|
org,
|
||||||
|
team_slug,
|
||||||
|
});
|
||||||
|
return response.data.map((user) => user.login);
|
||||||
|
};
|
||||||
|
|
||||||
|
const runCongratulate = async () => {
|
||||||
|
const pullRequest = danger.github.pr;
|
||||||
|
const userName = pullRequest.user.login;
|
||||||
|
|
||||||
|
const staticExcludedUsers = [
|
||||||
|
'dependabot',
|
||||||
|
'cyborch',
|
||||||
|
'emilienchvt',
|
||||||
|
'Samox',
|
||||||
|
'charlesBochet',
|
||||||
|
'gitstart-app',
|
||||||
|
'thaisguigon',
|
||||||
|
'lucasbordeau',
|
||||||
|
'magrinj',
|
||||||
|
'Weiko',
|
||||||
|
'gitstart-twenty',
|
||||||
|
'bosiraphael',
|
||||||
|
'martmull',
|
||||||
|
'FelixMalfait',
|
||||||
|
'thomtrp',
|
||||||
|
'Bonapara',
|
||||||
|
'nimraahmed',
|
||||||
|
'ady-beraud',
|
||||||
|
];
|
||||||
|
|
||||||
|
const teamMembers = await getTeamMembers();
|
||||||
|
|
||||||
|
const excludedUsers = new Set([...staticExcludedUsers, ...teamMembers]);
|
||||||
|
|
||||||
|
if (excludedUsers.has(userName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data: pullRequests } =
|
||||||
|
await danger.github.api.rest.search.issuesAndPullRequests({
|
||||||
|
q: `is:pr author:${userName} is:closed repo:twentyhq/twenty`,
|
||||||
|
per_page: 2,
|
||||||
|
page: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
const isFirstPR = pullRequests.total_count === 1;
|
||||||
|
|
||||||
|
if (isFirstPR) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const stats = await fetchContributorStats(userName);
|
||||||
|
const contributorUrl = `https://twenty.com/contributors/${userName}`;
|
||||||
|
|
||||||
|
// Pre-fetch to trigger cloudflare cache
|
||||||
|
await fetchContributorImage(userName);
|
||||||
|
|
||||||
|
const message =
|
||||||
|
`Thanks @${userName} for your contribution!\n` +
|
||||||
|
`This marks your **${ordinalSuffix(
|
||||||
|
stats.mergedPRsCount,
|
||||||
|
)}** PR on the repo. ` +
|
||||||
|
`You're **top ${stats.rank}%** of all our contributors 🎉\n` +
|
||||||
|
`[See contributor page](${contributorUrl}) - ` +
|
||||||
|
`[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=${contributorUrl}) - ` +
|
||||||
|
`[Share on Twitter](https://www.twitter.com/share?url=${contributorUrl})\n\n` +
|
||||||
|
`![Contributions](https://twenty.com/api/contributors/${userName}/og.png)`;
|
||||||
|
|
||||||
|
await danger.github.api.rest.issues.createComment({
|
||||||
|
owner: danger.github.thisPR.owner,
|
||||||
|
repo: danger.github.thisPR.repo,
|
||||||
|
issue_number: danger.github.thisPR.pull_number,
|
||||||
|
body: message,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (danger.github && danger.github.pr.merged) {
|
||||||
|
runCongratulate();
|
||||||
|
}
|
@ -4,6 +4,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"nx": "NX_DEFAULT_PROJECT=twenty-front node ../../node_modules/nx/bin/nx.js",
|
"nx": "NX_DEFAULT_PROJECT=twenty-front node ../../node_modules/nx/bin/nx.js",
|
||||||
"danger:ci": "danger ci --use-github-checks --failOnErrors",
|
"danger:ci": "danger ci --use-github-checks --failOnErrors",
|
||||||
|
"danger:congratulate": "danger ci --dangerfile ./congratulate-dangerfile.ts --use-github-checks --failOnErrors",
|
||||||
"release": "node release.js"
|
"release": "node release.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
"build": "npx next build",
|
"build": "npx next build",
|
||||||
"start": "npx next start",
|
"start": "npx next start",
|
||||||
"lint": "npx next lint",
|
"lint": "npx next lint",
|
||||||
"github:sync": "npx tsx src/github/github-sync.ts --pageLimit 1",
|
"github:sync": "npx tsx src/github/github-sync.ts",
|
||||||
"github:init": "npx tsx src/github/github-sync.ts",
|
"github:init": "npx tsx src/github/github-sync.ts --isFullSync",
|
||||||
"database:migrate": "npx tsx src/database/migrate-database.ts",
|
"database:migrate": "npx tsx src/database/migrate-database.ts",
|
||||||
"database:generate:pg": "npx drizzle-kit generate:pg --config=src/database/drizzle-posgres.config.ts"
|
"database:generate:pg": "npx drizzle-kit generate:pg --config=src/database/drizzle-posgres.config.ts"
|
||||||
},
|
},
|
||||||
|
@ -55,7 +55,7 @@ interface ProfileProps {
|
|||||||
|
|
||||||
export const ProfileSharing = ({ username }: ProfileProps) => {
|
export const ProfileSharing = ({ username }: ProfileProps) => {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const baseUrl = `${window.location.protocol}//${window.location.host}`;
|
const baseUrl = 'https://twenty.com';
|
||||||
const contributorUrl = `${baseUrl}/contributors/${username}`;
|
const contributorUrl = `${baseUrl}/contributors/${username}`;
|
||||||
|
|
||||||
const handleDownload = async () => {
|
const handleDownload = async () => {
|
||||||
@ -101,7 +101,7 @@ export const ProfileSharing = ({ username }: ProfileProps) => {
|
|||||||
)}
|
)}
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
<StyledButton
|
<StyledButton
|
||||||
href={`http://www.twitter.com/share?url=${contributorUrl}`}
|
href={`https://www.twitter.com/share?url=${contributorUrl}`}
|
||||||
target="blank"
|
target="blank"
|
||||||
>
|
>
|
||||||
<XIcon color="black" size="24px" /> Share on X
|
<XIcon color="black" size="24px" /> Share on X
|
||||||
|
@ -2,7 +2,7 @@ import { format } from 'date-fns';
|
|||||||
import { ImageResponse } from 'next/og';
|
import { ImageResponse } from 'next/og';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
bottomBackgroundImage,
|
backgroundImage,
|
||||||
container,
|
container,
|
||||||
contributorInfo,
|
contributorInfo,
|
||||||
contributorInfoBox,
|
contributorInfoBox,
|
||||||
@ -15,8 +15,7 @@ import {
|
|||||||
profileInfoContainer,
|
profileInfoContainer,
|
||||||
profileUsernameHeader,
|
profileUsernameHeader,
|
||||||
styledContributorAvatar,
|
styledContributorAvatar,
|
||||||
topBackgroundImage,
|
} from '@/app/api/contributors/[slug]/og.png/style';
|
||||||
} from '@/app/api/contributors/og-image/[slug]/style';
|
|
||||||
import { getContributorActivity } from '@/app/contributors/utils/get-contributor-activity';
|
import { getContributorActivity } from '@/app/contributors/utils/get-contributor-activity';
|
||||||
|
|
||||||
const GABARITO_FONT_CDN_URL =
|
const GABARITO_FONT_CDN_URL =
|
||||||
@ -33,8 +32,10 @@ const getGabarito = async () => {
|
|||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
try {
|
try {
|
||||||
const url = request.url;
|
const url = request.url;
|
||||||
|
const splitUrl = url.split('/');
|
||||||
const username = url.split('/')?.pop() || '';
|
const usernameIndex =
|
||||||
|
splitUrl.findIndex((part) => part === 'contributors') + 1;
|
||||||
|
const username = splitUrl[usernameIndex];
|
||||||
|
|
||||||
const contributorActivity = await getContributorActivity(username);
|
const contributorActivity = await getContributorActivity(username);
|
||||||
if (contributorActivity) {
|
if (contributorActivity) {
|
||||||
@ -45,11 +46,11 @@ export async function GET(request: Request) {
|
|||||||
activeDays,
|
activeDays,
|
||||||
contributorAvatar,
|
contributorAvatar,
|
||||||
} = contributorActivity;
|
} = contributorActivity;
|
||||||
return await new ImageResponse(
|
|
||||||
|
const imageResponse = await new ImageResponse(
|
||||||
(
|
(
|
||||||
<div style={container}>
|
<div style={container}>
|
||||||
<div style={topBackgroundImage}></div>
|
<div style={backgroundImage}></div>
|
||||||
<div style={bottomBackgroundImage}></div>
|
|
||||||
<div style={profileContainer}>
|
<div style={profileContainer}>
|
||||||
<img src={contributorAvatar} style={styledContributorAvatar} />
|
<img src={contributorAvatar} style={styledContributorAvatar} />
|
||||||
<div style={profileInfoContainer}>
|
<div style={profileInfoContainer}>
|
||||||
@ -59,8 +60,8 @@ export async function GET(request: Request) {
|
|||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
<svg
|
<svg
|
||||||
width="96"
|
width="134"
|
||||||
height="96"
|
height="134"
|
||||||
viewBox="0 0 136 136"
|
viewBox="0 0 136 136"
|
||||||
fill="none"
|
fill="none"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
@ -122,6 +123,7 @@ export async function GET(request: Request) {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
return imageResponse;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return new Response(`error: ${error}`, {
|
return new Response(`error: ${error}`, {
|
@ -14,42 +14,36 @@ export const container: CSSProperties = {
|
|||||||
fontFamily: 'Gabarito',
|
fontFamily: 'Gabarito',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const topBackgroundImage: CSSProperties = {
|
export const backgroundImage: CSSProperties = {
|
||||||
backgroundImage: `url(${BACKGROUND_IMAGE_URL})`,
|
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
zIndex: '-1',
|
width: '1250px',
|
||||||
width: '1300px',
|
height: '850px',
|
||||||
height: '250px',
|
transform: 'rotate(-7deg)',
|
||||||
transform: 'rotate(-11deg)',
|
opacity: '0.8',
|
||||||
opacity: '0.2',
|
backgroundImage: `
|
||||||
top: '-100',
|
linear-gradient(
|
||||||
left: '-25',
|
158.4deg,
|
||||||
};
|
rgba(255, 255, 255, 0.8) 30.69%,
|
||||||
|
#FFFFFF 35.12%,
|
||||||
export const bottomBackgroundImage: CSSProperties = {
|
rgba(255, 255, 255, 0.8) 60.27%,
|
||||||
backgroundImage: `url(${BACKGROUND_IMAGE_URL})`,
|
rgba(255, 255, 255, 0.64) 38.88%
|
||||||
position: 'absolute',
|
),
|
||||||
zIndex: '-1',
|
url(${BACKGROUND_IMAGE_URL})`,
|
||||||
width: '1300px',
|
|
||||||
height: '250px',
|
|
||||||
transform: 'rotate(-11deg)',
|
|
||||||
opacity: '0.2',
|
|
||||||
bottom: '-120',
|
|
||||||
right: '-40',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const profileContainer: CSSProperties = {
|
export const profileContainer: CSSProperties = {
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
justifyContent: 'space-between',
|
justifyContent: 'space-between',
|
||||||
width: '780px',
|
width: '970px',
|
||||||
margin: '0px 0px 40px',
|
height: '134px',
|
||||||
|
margin: '0px 0px 55px',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const styledContributorAvatar = {
|
export const styledContributorAvatar = {
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
width: '96px',
|
width: '134px',
|
||||||
height: '96px',
|
height: '134px',
|
||||||
margin: '0px',
|
margin: '0px',
|
||||||
border: '3px solid #141414',
|
border: '3px solid #141414',
|
||||||
borderRadius: '16px',
|
borderRadius: '16px',
|
||||||
@ -65,7 +59,7 @@ export const profileInfoContainer: CSSProperties = {
|
|||||||
|
|
||||||
export const profileUsernameHeader: CSSProperties = {
|
export const profileUsernameHeader: CSSProperties = {
|
||||||
margin: '0px',
|
margin: '0px',
|
||||||
fontSize: '28px',
|
fontSize: '39px',
|
||||||
fontWeight: '700',
|
fontWeight: '700',
|
||||||
color: '#141414',
|
color: '#141414',
|
||||||
fontFamily: 'Gabarito',
|
fontFamily: 'Gabarito',
|
||||||
@ -74,7 +68,7 @@ export const profileUsernameHeader: CSSProperties = {
|
|||||||
export const profileContributionHeader: CSSProperties = {
|
export const profileContributionHeader: CSSProperties = {
|
||||||
margin: '0px',
|
margin: '0px',
|
||||||
color: '#818181',
|
color: '#818181',
|
||||||
fontSize: '20px',
|
fontSize: '27px',
|
||||||
fontWeight: '400',
|
fontWeight: '400',
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -84,8 +78,8 @@ export const contributorInfoContainer: CSSProperties = {
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
justifyContent: 'space-around',
|
justifyContent: 'space-around',
|
||||||
width: '780px',
|
width: '970px',
|
||||||
height: '149px',
|
height: '209px',
|
||||||
backgroundColor: '#F1F1F1',
|
backgroundColor: '#F1F1F1',
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -110,14 +104,14 @@ export const contributorInfoTitle = {
|
|||||||
color: '#B3B3B3',
|
color: '#B3B3B3',
|
||||||
margin: '0px',
|
margin: '0px',
|
||||||
fontWeight: '500',
|
fontWeight: '500',
|
||||||
fontSize: '24px',
|
fontSize: '33px',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const contributorInfoStats = {
|
export const contributorInfoStats = {
|
||||||
color: '#474747',
|
color: '#474747',
|
||||||
margin: '0px',
|
margin: '0px',
|
||||||
fontWeight: '700',
|
fontWeight: '700',
|
||||||
fontSize: '40px',
|
fontSize: '55px',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const infoSeparator: CSSProperties = {
|
export const infoSeparator: CSSProperties = {
|
||||||
@ -125,6 +119,6 @@ export const infoSeparator: CSSProperties = {
|
|||||||
right: 0,
|
right: 0,
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
width: '2px',
|
width: '2px',
|
||||||
height: '85px',
|
height: '120px',
|
||||||
backgroundColor: '#141414',
|
backgroundColor: '#141414',
|
||||||
};
|
};
|
@ -0,0 +1,26 @@
|
|||||||
|
import { getContributorActivity } from '@/app/contributors/utils/get-contributor-activity';
|
||||||
|
import { executePartialSync } from '@/github/execute-partial-sync';
|
||||||
|
|
||||||
|
export const dynamic = 'force-dynamic';
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
try {
|
||||||
|
const url = request.url;
|
||||||
|
|
||||||
|
const username = url.split('/')?.pop() || '';
|
||||||
|
|
||||||
|
await executePartialSync();
|
||||||
|
|
||||||
|
const contributorActivity = await getContributorActivity(username);
|
||||||
|
|
||||||
|
if (contributorActivity) {
|
||||||
|
const mergedPRsCount = contributorActivity.mergedPRsCount;
|
||||||
|
const rank = contributorActivity.rank;
|
||||||
|
return Response.json({ mergedPRsCount, rank });
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
return new Response(`Contributor stats error: ${error?.message}`, {
|
||||||
|
status: 500,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -19,13 +19,14 @@ export function generateMetadata({
|
|||||||
params: { slug: string };
|
params: { slug: string };
|
||||||
}): Metadata {
|
}): Metadata {
|
||||||
return {
|
return {
|
||||||
|
metadataBase: new URL(`https://twenty.com`),
|
||||||
title: 'Twenty - ' + params.slug,
|
title: 'Twenty - ' + params.slug,
|
||||||
description:
|
description:
|
||||||
'Explore the impactful contributions of ' +
|
'Explore the impactful contributions of ' +
|
||||||
params.slug +
|
params.slug +
|
||||||
' on the Twenty Github Repo. Discover their merged pull requests, ongoing work, and top ranking. Join and contribute to the #1 Open-Source CRM thriving community!',
|
' on the Twenty Github Repo. Discover their merged pull requests, ongoing work, and top ranking. Join and contribute to the #1 Open-Source CRM thriving community!',
|
||||||
openGraph: {
|
openGraph: {
|
||||||
images: [`/api/contributors/og-image/${params.slug}`],
|
images: [`https://twenty.com/api/contributors/${params.slug}/og.png`],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -6,22 +6,17 @@ import {
|
|||||||
Repository,
|
Repository,
|
||||||
} from '@/github/contributors/types';
|
} 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(
|
export async function fetchIssuesPRs(
|
||||||
query: typeof graphql,
|
query: typeof graphql,
|
||||||
cursor: string | null = null,
|
cursor: string | null = null,
|
||||||
isIssues = false,
|
isIssues = false,
|
||||||
accumulatedData: Array<PullRequestNode | IssueNode> = [],
|
accumulatedData: Array<PullRequestNode | IssueNode> = [],
|
||||||
pageLimit: number,
|
|
||||||
currentPage = 0,
|
|
||||||
): Promise<Array<PullRequestNode | IssueNode>> {
|
): Promise<Array<PullRequestNode | IssueNode>> {
|
||||||
const { repository } = await query<Repository>(
|
const { repository } = await query<Repository>(
|
||||||
`
|
`
|
||||||
query ($cursor: String) {
|
query ($cursor: String) {
|
||||||
repository(owner: "twentyhq", name: "twenty") {
|
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 {
|
nodes {
|
||||||
id
|
id
|
||||||
title
|
title
|
||||||
@ -94,16 +89,12 @@ export async function fetchIssuesPRs(
|
|||||||
? repository.issues.pageInfo
|
? repository.issues.pageInfo
|
||||||
: repository.pullRequests.pageInfo;
|
: repository.pullRequests.pageInfo;
|
||||||
|
|
||||||
const newCurrentPage = currentPage + 1;
|
if (pageInfo.hasNextPage) {
|
||||||
|
|
||||||
if ((!pageLimit || newCurrentPage < pageLimit) && pageInfo.hasNextPage) {
|
|
||||||
return fetchIssuesPRs(
|
return fetchIssuesPRs(
|
||||||
query,
|
query,
|
||||||
pageInfo.endCursor,
|
pageInfo.endCursor,
|
||||||
isIssues,
|
isIssues,
|
||||||
newAccumulatedData,
|
newAccumulatedData,
|
||||||
pageLimit,
|
|
||||||
currentPage + 1,
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return newAccumulatedData;
|
return newAccumulatedData;
|
||||||
|
@ -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();
|
||||||
|
}
|
@ -42,7 +42,10 @@ export async function saveIssuesToDB(
|
|||||||
authorId: issue.author.login,
|
authorId: issue.author.login,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
{ onConflictKey: 'id' },
|
{
|
||||||
|
onConflictKey: 'id',
|
||||||
|
onConflictUpdateObject: { updatedAt: issue.updatedAt },
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const label of issue.labels.nodes) {
|
for (const label of issue.labels.nodes) {
|
||||||
|
@ -44,7 +44,10 @@ export async function savePRsToDB(
|
|||||||
authorId: pr.author.login,
|
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) {
|
for (const label of pr.labels.nodes) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { graphql } from '@octokit/graphql';
|
import { graphql } from '@octokit/graphql';
|
||||||
|
|
||||||
|
import { getLatestUpdate } from '@/github/contributors/get-latest-update';
|
||||||
import {
|
import {
|
||||||
IssueNode,
|
IssueNode,
|
||||||
PullRequestNode,
|
PullRequestNode,
|
||||||
@ -12,12 +13,13 @@ export async function searchIssuesPRs(
|
|||||||
isIssues = false,
|
isIssues = false,
|
||||||
accumulatedData: Array<PullRequestNode | IssueNode> = [],
|
accumulatedData: Array<PullRequestNode | IssueNode> = [],
|
||||||
): Promise<Array<PullRequestNode | IssueNode>> {
|
): Promise<Array<PullRequestNode | IssueNode>> {
|
||||||
|
const since = await getLatestUpdate();
|
||||||
const { search } = await query<SearchIssuesPRsQuery>(
|
const { search } = await query<SearchIssuesPRsQuery>(
|
||||||
`
|
`
|
||||||
query searchPullRequestsAndIssues($cursor: String) {
|
query searchPullRequestsAndIssues($cursor: String) {
|
||||||
search(query: "repo:twentyhq/twenty ${
|
search(query: "repo:twentyhq/twenty ${
|
||||||
isIssues ? 'is:issue' : 'is:pr'
|
isIssues ? 'is:issue' : 'is:pr'
|
||||||
} updated:>2024-02-27", type: ISSUE, first: 100, after: $cursor) {
|
} updated:>${since}", type: ISSUE, first: 100, after: $cursor) {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
... on PullRequest {
|
... on PullRequest {
|
||||||
@ -80,6 +82,7 @@ export async function searchIssuesPRs(
|
|||||||
cursor,
|
cursor,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const newAccumulatedData: Array<PullRequestNode | IssueNode> = [
|
const newAccumulatedData: Array<PullRequestNode | IssueNode> = [
|
||||||
...accumulatedData,
|
...accumulatedData,
|
||||||
...search.edges.map(({ node }) => node),
|
...search.edges.map(({ node }) => node),
|
||||||
|
46
packages/twenty-website/src/github/execute-partial-sync.ts
Normal file
46
packages/twenty-website/src/github/execute-partial-sync.ts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import { graphql } from '@octokit/graphql';
|
||||||
|
|
||||||
|
import { fetchAssignableUsers } from '@/github/contributors/fetch-assignable-users';
|
||||||
|
import { saveIssuesToDB } from '@/github/contributors/save-issues-to-db';
|
||||||
|
import { savePRsToDB } from '@/github/contributors/save-prs-to-db';
|
||||||
|
import { searchIssuesPRs } from '@/github/contributors/search-issues-prs';
|
||||||
|
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 executePartialSync = 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 searchIssuesPRs(
|
||||||
|
query,
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
[],
|
||||||
|
)) as Array<PullRequestNode>;
|
||||||
|
const fetchedIssues = (await searchIssuesPRs(
|
||||||
|
query,
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
[],
|
||||||
|
)) as Array<IssueNode>;
|
||||||
|
|
||||||
|
await savePRsToDB(fetchedPRs, assignableUsers);
|
||||||
|
await saveIssuesToDB(fetchedIssues, assignableUsers);
|
||||||
|
|
||||||
|
console.log('data synched!');
|
||||||
|
};
|
@ -9,11 +9,7 @@ import { IssueNode, PullRequestNode } from '@/github/contributors/types';
|
|||||||
import { fetchAndSaveGithubReleases } from '@/github/github-releases/fetch-and-save-github-releases';
|
import { fetchAndSaveGithubReleases } from '@/github/github-releases/fetch-and-save-github-releases';
|
||||||
import { fetchAndSaveGithubStars } from '@/github/github-stars/fetch-and-save-github-stars';
|
import { fetchAndSaveGithubStars } from '@/github/github-stars/fetch-and-save-github-stars';
|
||||||
|
|
||||||
export const fetchAndSaveGithubData = async ({
|
export const fetchAndSaveGithubData = async () => {
|
||||||
pageLimit,
|
|
||||||
}: {
|
|
||||||
pageLimit: number;
|
|
||||||
}) => {
|
|
||||||
if (!global.process.env.GITHUB_TOKEN) {
|
if (!global.process.env.GITHUB_TOKEN) {
|
||||||
return new Error('No GitHub token provided');
|
return new Error('No GitHub token provided');
|
||||||
}
|
}
|
||||||
@ -35,14 +31,12 @@ export const fetchAndSaveGithubData = async ({
|
|||||||
null,
|
null,
|
||||||
false,
|
false,
|
||||||
[],
|
[],
|
||||||
pageLimit,
|
|
||||||
)) as Array<PullRequestNode>;
|
)) as Array<PullRequestNode>;
|
||||||
const fetchedIssues = (await fetchIssuesPRs(
|
const fetchedIssues = (await fetchIssuesPRs(
|
||||||
query,
|
query,
|
||||||
null,
|
null,
|
||||||
true,
|
true,
|
||||||
[],
|
[],
|
||||||
pageLimit,
|
|
||||||
)) as Array<IssueNode>;
|
)) as Array<IssueNode>;
|
||||||
|
|
||||||
await savePRsToDB(fetchedPRs, assignableUsers);
|
await savePRsToDB(fetchedPRs, assignableUsers);
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
|
import { executePartialSync } from '@/github/execute-partial-sync';
|
||||||
import { fetchAndSaveGithubData } from '@/github/fetch-and-save-github-data';
|
import { fetchAndSaveGithubData } from '@/github/fetch-and-save-github-data';
|
||||||
|
|
||||||
export const githubSync = async () => {
|
export const githubSync = async () => {
|
||||||
const pageLimitFlagIndex = process.argv.indexOf('--pageLimit');
|
const isFullSyncFlagIndex = process.argv.indexOf('--isFullSync');
|
||||||
let pageLimit = 0;
|
const isFullSync = isFullSyncFlagIndex > -1;
|
||||||
|
|
||||||
if (pageLimitFlagIndex > -1) {
|
if (isFullSync) {
|
||||||
pageLimit = parseInt(process.argv[pageLimitFlagIndex + 1], 10);
|
await fetchAndSaveGithubData();
|
||||||
|
} else {
|
||||||
|
await executePartialSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
await fetchAndSaveGithubData({ pageLimit });
|
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user