Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create congratulations bot #5404

Merged
merged 10 commits into from
May 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix sync
ady-beraud committed May 16, 2024
commit f97d3c20ac80d83cc3b4f8f487d1c37bd8769b1f
Original file line number Diff line number Diff line change
@@ -54,7 +54,6 @@ interface ProfileProps {
}

export const ProfileSharing = ({ username }: ProfileProps) => {

const [loading, setLoading] = useState(false);
const baseUrl = 'https://twenty.com';
const contributorUrl = `${baseUrl}/contributors/${username}`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getContributorActivity } from '@/app/contributors/utils/get-contributor-activity';
import { executePartialSync } from '@/github-sync/execute-partial-sync';
import { executePartialSync } from '@/github/execute-partial-sync';

export const dynamic = 'force-dynamic';

Original file line number Diff line number Diff line change
@@ -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;
15 changes: 7 additions & 8 deletions packages/twenty-website/src/github/execute-partial-sync.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { global } from '@apollo/client/utilities/globals';
import { graphql } from '@octokit/graphql';

import { fetchAssignableUsers } from '@/github-sync/contributors/fetch-assignable-users';
import { saveIssuesToDB } from '@/github-sync/contributors/save-issues-to-db';
import { savePRsToDB } from '@/github-sync/contributors/save-prs-to-db';
import { searchIssuesPRs } from '@/github-sync/contributors/search-issues-prs';
import { IssueNode, PullRequestNode } from '@/github-sync/contributors/types';
import { fetchAndSaveGithubReleases } from '@/github-sync/github-releases/fetch-and-save-github-releases';
import { fetchAndSaveGithubStars } from '@/github-sync/github-stars/fetch-and-save-github-stars';
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) {
Original file line number Diff line number Diff line change
@@ -9,11 +9,7 @@ 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 ({
pageLimit,
}: {
pageLimit: number;
}) => {
export const fetchAndSaveGithubData = async () => {
if (!global.process.env.GITHUB_TOKEN) {
return new Error('No GitHub token provided');
}
@@ -35,14 +31,12 @@ export const fetchAndSaveGithubData = async ({
null,
false,
[],
pageLimit,
)) as Array<PullRequestNode>;
const fetchedIssues = (await fetchIssuesPRs(
query,
null,
true,
[],
pageLimit,
)) as Array<IssueNode>;

await savePRsToDB(fetchedPRs, assignableUsers);
8 changes: 0 additions & 8 deletions packages/twenty-website/src/github/github-init.ts

This file was deleted.