@@ -9,6 +9,18 @@ export const REPO_ROOT = resolve(fileURLToPath(new URL("..", import.meta.url)));
99export const BASELINE_PATH = resolve ( REPO_ROOT , "tools" , "upstream_baseline.json" ) ;
1010const UPSTREAM_REF_PREFIX = "refs/upstream-check" ;
1111const REQUIRED_FIELDS = [ "repo" , "branch" , "reviewed_through" , "reviewed_date" ] as const ;
12+ /**
13+ * Upstream tickets the fork tracks.
14+ *
15+ * Not all of them: upstream runs ~40 open pull requests and ~55 open issues at
16+ * any moment, all of it arriving here through releases on `main` anyway (see
17+ * `docs/fork/DECISIONS.md`). Reporting that stream weekly would be a check that
18+ * cries wolf, and one that cries wolf gets ignored.
19+ *
20+ * `platform` is the label whose issues change what this fork has to verify on
21+ * Windows, so it is the one worth a standing question.
22+ */
23+ const TRACKED_ISSUE_LABEL = "platform" ;
1224const FULL_SHA_LENGTH = 40 ;
1325const UNIT_SEPARATOR = "\u001f" ;
1426
@@ -19,6 +31,14 @@ export type Baseline = {
1931 branch : string ;
2032 reviewed_through : string ;
2133 reviewed_date : string ;
34+ /** Highest upstream issue number already triaged; only higher ones are reported. */
35+ reviewed_issue_through ?: number ;
36+ } ;
37+
38+ export type Ticket = {
39+ number : number ;
40+ title : string ;
41+ labels : string [ ] ;
2242} ;
2343
2444export type Commit = {
@@ -109,10 +129,87 @@ export function collectNewCommits(
109129 return commits ;
110130}
111131
132+ /** Owner/name from the upstream clone URL, for `gh --repo`. */
133+ export function upstreamSlug ( repoUrl : string ) : string | undefined {
134+ const match = / g i t h u b \. c o m [: / ] (?< owner > [ ^ / ] + ) \/ (?< name > [ ^ / ] + ?) (?: \. g i t ) ? $ / . exec ( repoUrl ) ;
135+ const { owner, name } = match ?. groups ?? { } ;
136+ return owner && name ? `${ owner } /${ name } ` : undefined ;
137+ }
138+
139+ /**
140+ * Open upstream issues above the watermark that carry the tracked label.
141+ *
142+ * Returns `undefined` — not an empty list — when `gh` cannot answer, so a
143+ * missing CLI or an unauthenticated shell reads as "not checked" in the report
144+ * instead of the much worse "nothing to review".
145+ */
146+ export function collectNewIssues ( baseline : Baseline ) : Ticket [ ] | undefined {
147+ const slug = upstreamSlug ( baseline . repo ) ;
148+ if ( ! slug ) return undefined ;
149+ const result = Bun . spawnSync (
150+ [ "gh" , "issue" , "list" , "--repo" , slug , "--state" , "open" , "--label" , TRACKED_ISSUE_LABEL ,
151+ "--limit" , "100" , "--json" , "number,title,labels" ] ,
152+ { stdout : "pipe" , stderr : "pipe" } ,
153+ ) ;
154+ if ( result . exitCode !== 0 ) return undefined ;
155+ let parsed : { number : number ; title : string ; labels ?: { name : string } [ ] } [ ] ;
156+ try {
157+ parsed = JSON . parse ( new TextDecoder ( ) . decode ( result . stdout ) ) ;
158+ } catch {
159+ return undefined ;
160+ }
161+ const watermark = Number ( baseline . reviewed_issue_through ?? 0 ) ;
162+ return parsed
163+ . filter ( ( item ) => item . number > watermark )
164+ . sort ( ( left , right ) => left . number - right . number )
165+ . map ( ( item ) => ( {
166+ number : item . number ,
167+ title : item . title ,
168+ labels : ( item . labels ?? [ ] ) . map ( ( label ) => label . name ) ,
169+ } ) ) ;
170+ }
171+
172+ /** The issue section: what still needs a human's judgement, or why it was not asked. */
173+ export function renderIssueSection ( baseline : Baseline , issues : Ticket [ ] | undefined ) : string [ ] {
174+ const watermark = baseline . reviewed_issue_through ?? 0 ;
175+ const lines = [ "## Upstream platform issues" , "" , `Triaged through \`#${ watermark } \`.` , "" ] ;
176+ if ( issues === undefined ) {
177+ lines . push (
178+ "Not checked: `gh` was unavailable or unauthenticated. This is reported rather than" ,
179+ "treated as \"nothing to review\" — the difference matters." ,
180+ "" ,
181+ ) ;
182+ return lines ;
183+ }
184+ if ( issues . length === 0 ) {
185+ lines . push ( "No new `platform` issues since that number." , "" ) ;
186+ return lines ;
187+ }
188+ lines . push (
189+ `${ issues . length } new \`platform\` issue(s) to triage.` ,
190+ "" ,
191+ "| Issue | Labels | Title |" ,
192+ "| --- | --- | --- |" ,
193+ ) ;
194+ for ( const issue of issues ) {
195+ lines . push (
196+ `| #${ issue . number } | ${ issue . labels . join ( ", " ) } | ${ issue . title . replaceAll ( "|" , "\|" ) } |` ,
197+ ) ;
198+ }
199+ lines . push (
200+ "" ,
201+ "Record the verdict in `docs/fork/UPSTREAM.md`, then raise `reviewed_issue_through`" ,
202+ "so the same issue is never re-triaged." ,
203+ "" ,
204+ ) ;
205+ return lines ;
206+ }
207+
112208export function renderMarkdown (
113209 baseline : Baseline ,
114210 commits : Commit [ ] ,
115211 error ?: string ,
212+ issues ?: Ticket [ ] | undefined ,
116213) : string {
117214 const lines = [
118215 "# Upstream review report" ,
@@ -128,6 +225,7 @@ export function renderMarkdown(
128225 }
129226 if ( commits . length === 0 ) {
130227 lines . push ( "## Result" , "" , "No new upstream commits. Nothing to review." , "" ) ;
228+ lines . push ( ...renderIssueSection ( baseline , issues ) ) ;
131229 return `${ lines . join ( "\n" ) } \n` ;
132230 }
133231 lines . push (
@@ -191,26 +289,28 @@ export function main(args = Bun.argv.slice(2)): number {
191289 reviewed_date : "unknown" ,
192290 } ;
193291 let commits : Commit [ ] = [ ] ;
292+ let issues : Ticket [ ] | undefined ;
194293 let error : string | undefined ;
195294
196295 try {
197296 baseline = loadBaseline ( ) ;
198297 const ref = fetchUpstream ( baseline , options . repoDir ) ;
199298 commits = collectNewCommits ( baseline , options . repoDir , ref ) ;
299+ issues = collectNewIssues ( baseline ) ;
200300 } catch ( caught ) {
201301 if ( ! ( caught instanceof UpstreamCheckError ) ) throw caught ;
202302 error = caught . message ;
203303 }
204304
205- const report = renderMarkdown ( baseline , commits , error ) ;
305+ const report = renderMarkdown ( baseline , commits , error , issues ) ;
206306 writeFileSync ( options . output , report , "utf8" ) ;
207307 process . stdout . write ( report ) ;
208308
209309 if ( options . githubOutput && process . env . GITHUB_OUTPUT ) {
210310 appendFileSync (
211311 process . env . GITHUB_OUTPUT ,
212312 [
213- `needs_attention=${ commits . length > 0 || Boolean ( error ) ? "true" : "false" } ` ,
313+ `needs_attention=${ commits . length > 0 || ( issues ?. length ?? 0 ) > 0 || Boolean ( error ) ? "true" : "false" } ` ,
214314 `check_failed=${ error ? "true" : "false" } ` ,
215315 `report_path=${ options . output } ` ,
216316 "" ,
@@ -219,7 +319,10 @@ export function main(args = Bun.argv.slice(2)): number {
219319 }
220320
221321 if ( error ) return 2 ;
222- if ( options . strict && commits . length > 0 ) return 1 ;
322+ // A new `platform` issue upstream changes what this fork has to verify on
323+ // Windows, so it fails the weekly check the same way a new commit does.
324+ // Clearing it means triaging the issue and raising the watermark, not muting.
325+ if ( options . strict && ( commits . length > 0 || ( issues ?. length ?? 0 ) > 0 ) ) return 1 ;
223326 return 0 ;
224327}
225328
0 commit comments