@@ -11,6 +11,7 @@ import {
11
11
} from "@/app/downloads/config" ;
12
12
import { Octokit } from "octokit" ;
13
13
import { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods" ;
14
+ import { parse } from "node-html-parser" ;
14
15
15
16
function createGithubAuth ( ) {
16
17
if ( process . env . GITHUB_TOKEN ) {
@@ -87,3 +88,45 @@ export async function fetchReport(): Promise<AVM2Report | undefined> {
87
88
// the type is set incorrectly. This converts to the proper type.
88
89
return await new Response ( asset . data as unknown as ReadableStream ) . json ( ) ;
89
90
}
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