Skip to content

Commit aec6c97

Browse files
committed
Automate AVM1 API percentages in the compatibility page
1 parent 52355c6 commit aec6c97

File tree

4 files changed

+162
-7
lines changed

4 files changed

+162
-7
lines changed

package-lock.json

+111-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@next/bundle-analyzer": "^14.1.0",
1616
"@tabler/icons-react": "^2.46.0",
1717
"next": "14.1.0",
18+
"node-html-parser": "^6.1.12",
1819
"react": "^18",
1920
"react-device-detect": "^2.2.3",
2021
"react-dom": "^18",

src/app/compatibility/page.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import React from "react";
66
import { Title } from "@mantine/core";
77
import { List, ListItem } from "@mantine/core";
88
import { WeeklyContributions } from "@/app/compatibility/weekly_contributions";
9-
import { fetchReport, getWeeklyContributions } from "@/app/downloads/github";
9+
import { fetchReport, getAVM1Progress, getWeeklyContributions } from "@/app/downloads/github";
1010

1111
export default async function Downloads() {
1212
const contributions = await getWeeklyContributions();
@@ -16,13 +16,14 @@ export default async function Downloads() {
1616
Commits: item.total,
1717
};
1818
});
19+
const avm1ApiDone = await getAVM1Progress();
1920
const report = await fetchReport();
2021
const summary = report ? report.summary : undefined;
2122
const maxPoints = summary ? summary.max_points : NaN;
2223
const implPoints = summary ? summary.impl_points : NaN;
2324
const stubPenalty = summary ? summary.stub_penalty : NaN;
24-
const done = Math.round((implPoints - stubPenalty) / maxPoints * 100);
25-
const stubbed = Math.round(stubPenalty / maxPoints * 100);
25+
const avm2ApiDone = Math.round((implPoints - stubPenalty) / maxPoints * 100);
26+
const avm2ApiStubbed = Math.round(stubPenalty / maxPoints * 100);
2627

2728
return (
2829
<Container size="xl" className={classes.container}>
@@ -72,7 +73,7 @@ export default async function Downloads() {
7273
<AvmBlock
7374
name="AVM 1: ActionScript 1 & 2"
7475
language={{ done: 95 }}
75-
api={{ done: 75 }}
76+
api={{ done: avm1ApiDone }}
7677
info_link_target="_blank"
7778
info_link="https://github.com/ruffle-rs/ruffle/issues/310"
7879
>
@@ -91,11 +92,11 @@ export default async function Downloads() {
9192
</Text>
9293
</AvmBlock>
9394

94-
{!Number.isNaN(done) && !Number.isNaN(stubbed) && (
95+
{!Number.isNaN(avm2ApiDone) && !Number.isNaN(avm2ApiStubbed) && (
9596
<AvmBlock
9697
name="AVM 2: ActionScript 3"
9798
language={{ done: 75 }}
98-
api={{ done: done, stubbed: stubbed }}
99+
api={{ done: avm2ApiDone, stubbed: avm2ApiStubbed }}
99100
info_link="/compatibility/avm2"
100101
>
101102
<Text>

src/app/downloads/github.tsx

+43
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "@/app/downloads/config";
1212
import { Octokit } from "octokit";
1313
import { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods";
14+
import { parse } from "node-html-parser";
1415

1516
function createGithubAuth() {
1617
if (process.env.GITHUB_TOKEN) {
@@ -87,3 +88,45 @@ export async function fetchReport(): Promise<AVM2Report | undefined> {
8788
// the type is set incorrectly. This converts to the proper type.
8889
return await new Response(asset.data as unknown as ReadableStream).json();
8990
}
91+
92+
export async function getAVM1Progress(): Promise<number> {
93+
const octokit = new Octokit({ authStrategy: createGithubAuth });
94+
const issue = await octokit.rest.issues.get({
95+
owner: repository.owner,
96+
repo: repository.repo,
97+
issue_number: 310,
98+
headers: {
99+
accept: "application/vnd.github.html+json",
100+
},
101+
});
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+
}
129+
}
130+
}
131+
return Math.round(completedItems/totalItems*100);
132+
}

0 commit comments

Comments
 (0)