Skip to content

Commit ece5713

Browse files
committed
AVM1 Tracking: Switch to a single API request
1 parent aec6c97 commit ece5713

File tree

1 file changed

+14
-29
lines changed

1 file changed

+14
-29
lines changed

src/app/downloads/github.tsx

+14-29
Original file line numberDiff line numberDiff line change
@@ -91,42 +91,27 @@ export async function fetchReport(): Promise<AVM2Report | undefined> {
9191

9292
export async function getAVM1Progress(): Promise<number> {
9393
const octokit = new Octokit({ authStrategy: createGithubAuth });
94-
const issue = await octokit.rest.issues.get({
94+
const issues = await octokit.rest.issues.listForRepo({
9595
owner: repository.owner,
9696
repo: repository.repo,
97-
issue_number: 310,
97+
labels: "avm1-tracking",
98+
state: "all",
99+
per_page: 65,
98100
headers: {
99101
accept: "application/vnd.github.html+json",
100102
},
101103
});
102-
const topLevelContent = issue.data.body_html;
103-
if (!topLevelContent) {
104-
return 0;
105-
}
106-
const topLevelRoot = parse(topLevelContent);
107-
let totalItems = topLevelRoot.querySelectorAll("input.task-list-item-checkbox").length;
108-
let completedItems = topLevelRoot.querySelectorAll("input.task-list-item-checkbox:checked").length;
109-
const linkedIssues = topLevelRoot.querySelectorAll(`a[href^='https://github.com/${repository.owner}/${repository.repo}/issues/']`);
110-
for (let i = 0; i < linkedIssues.length; i++) {
111-
const issue = linkedIssues[i];
112-
const issue_href = issue.getAttribute("href");
113-
const issue_number = issue_href ? parseInt(issue_href.replace(`https://github.com/${repository.owner}/${repository.repo}/issues/`, '')) : Number.NaN;
114-
if (!Number.isNaN(issue_number)) {
115-
const linkedIssue = await octokit.rest.issues.get({
116-
owner: repository.owner,
117-
repo: repository.repo,
118-
issue_number: issue_number,
119-
headers: {
120-
accept: "application/vnd.github.html+json",
121-
},
122-
});
123-
const linkedContent = linkedIssue.data.body_html;
124-
if (linkedContent) {
125-
const linkedRoot = parse(linkedContent);
126-
totalItems += linkedRoot.querySelectorAll("input.task-list-item-checkbox").length;
127-
completedItems += linkedRoot.querySelectorAll("input.task-list-item-checkbox:checked").length;
128-
}
104+
let totalItems = 0;
105+
let completedItems = 0;
106+
for (const issue of issues.data) {
107+
const topLevelContent = issue.body_html;
108+
if (!topLevelContent) {
109+
continue;
129110
}
111+
const topLevelRoot = parse(topLevelContent);
112+
totalItems += topLevelRoot.querySelectorAll("input.task-list-item-checkbox").length;
113+
completedItems += topLevelRoot.querySelectorAll("input.task-list-item-checkbox:checked").length;
130114
}
115+
if (totalItems < 3348) return 75;
131116
return Math.round(completedItems/totalItems*100);
132117
}

0 commit comments

Comments
 (0)