mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-08-22 16:47:16 -05:00
feat: optimized github progress tracking requests
This commit is contained in:
@@ -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<GithubProjectResponse> {
|
||||
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<GithubProjectRes
|
||||
tasks: []
|
||||
};
|
||||
|
||||
const fields = await getGitHubProjectsV2Fields(octokit, project.id);
|
||||
|
||||
const fieldMap: Record<string, GithubProjectTaskStatus> = {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user