From decfb7b93a2a540e341ca3c99f7d352fe3ab3917 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Wed, 12 Aug 2026 15:45:45 +0200 Subject: [PATCH] feat: optimized github progress tracking requests --- server/utils/getGithubProgress.ts | 102 +++++++++++------------------- 1 file changed, 38 insertions(+), 64 deletions(-) diff --git a/server/utils/getGithubProgress.ts b/server/utils/getGithubProgress.ts index b758823..144c019 100644 --- a/server/utils/getGithubProgress.ts +++ b/server/utils/getGithubProgress.ts @@ -19,10 +19,10 @@ const orgName = 'PretendoNetwork'; const cacheMaxAgeMs = 60 * 60 * 1000; // 1 hour let cache: { response: GithubProjectResponse; createdAt: Date } | null = null; -const getProjectsV2GQL = ` +const getProjectsWithItemsV2GQL = ` query getProjectsV2($orgName: String!, $cursor: String) { organization(login: $orgName) { - projectsV2(first: 10, after: $cursor) { + projectsV2(first: 50, after: $cursor) { nodes { id title @@ -31,6 +31,30 @@ query getProjectsV2($orgName: String!, $cursor: String) { url } } + items(first: 100) { + nodes { + content { + ... on DraftIssue { + title + } + ... on Issue { + title + } + } + fieldValues(first: 20) { + nodes { + ... on ProjectV2ItemFieldSingleSelectValue { + name + field { + ... on ProjectV2SingleSelectField { + name + } + } + } + } + } + } + } } pageInfo { hasNextPage @@ -41,80 +65,32 @@ query getProjectsV2($orgName: String!, $cursor: String) { } `; -const getProjectsV2FieldsGQL = ` -query getProjectsV2Fields($id: ID!, $cursor: String) { - node(id: $id) { - ... on ProjectV2 { - items(first: 10, after: $cursor) { - nodes { - content { - ... on DraftIssue { - title - } - ... on Issue { - title - } - } - fieldValues(first: 20) { - nodes { - ... on ProjectV2ItemFieldSingleSelectValue { - name - field { - ... on ProjectV2SingleSelectField { - name - } - } - } - } - } - } - pageInfo { - hasNextPage - endCursor - } - } - } - } -} -`; +async function getGitHubProjectsWithItemsV2(octokit: Octokit) { + const projects: Array<{ id: string; title: string; url: string | null; items: Array<{ title: string; column: string }> }> = []; -async function getGitHubProjectsV2(octokit: Octokit) { - const projects: Array<{ id: string; title: string; url: string | null }> = []; - - const data = await octokit.graphql.paginate(getProjectsV2GQL, { + console.log('Get projects'); + const data = await octokit.graphql.paginate(getProjectsWithItemsV2GQL, { orgName: orgName }); + console.log('Finished get projects'); for (const node of data.organization.projectsV2.nodes) { projects.push({ id: node.id, title: node.title, - url: node.repositories.nodes[0]?.url ?? null + url: node.repositories.nodes[0]?.url ?? null, + items: node.items.nodes.map((item: any) => ({ + title: item.content.title, + column: item.fieldValues.nodes.find((fieldValue: any) => fieldValue.field?.name === 'Status')?.name + })) }); } return projects; } -async function getGitHubProjectsV2Fields(octokit: Octokit, id: string) { - const output: Array<{ title: string; column: string }> = []; - - const data: any = await octokit.graphql.paginate(getProjectsV2FieldsGQL, { - id: id - }); - - for (const node of data.node.items.nodes) { - output.push({ - title: node.content.title, - column: node.fieldValues.nodes.find((fieldValue: any) => fieldValue.field?.name === 'Status')?.name - }); - } - - return output; -} - async function getGithubProjectsData(octokit: Octokit): Promise { - const projects = await getGitHubProjectsV2(octokit); + const projects = await getGitHubProjectsWithItemsV2(octokit); const output: GithubProject[] = []; for (const project of projects) { @@ -128,15 +104,13 @@ async function getGithubProjectsData(octokit: Octokit): Promise = { done: 'completed', in_progress: 'inprogress', todo: 'notstarted' }; - for (const field of fields) { + for (const field of project.items) { const normalizedStatus = field.column.toLowerCase().replace(' ', '_'); const status = fieldMap[normalizedStatus]; if (!status) {