@@ -9,16 +9,18 @@ const NOTICE_MS = 72 * HOUR_MS;
99const MAX_REQUESTS_PER_RUN = 100 ;
1010const MAX_CLOSES_PER_RUN = 50 ;
1111const WRITE_PAUSE_MS = 1_000 ;
12- const MERGEABLE_WAIT_MS = 60_000 ;
12+ // Measured here: about two and a half minutes until every open PR has an answer.
13+ const MERGEABLE_WAIT_MS = 150_000 ;
1314// GitHub stamps a label event and the PR's updatedAt a second or two apart.
1415const SAME_MOMENT_MS = 15_000 ;
1516
1617const REBASE_LABEL = "needs-rebase" ;
1718const CLOSING_LABEL = "triage:closing" ;
1819const KEEP_OPEN_LABEL = "triage:keep-open" ;
1920const UNVOUCHED_LABEL = "vouch:unvouched" ;
20- const TRUSTED_VOUCH_STATUSES = new Set ( [ "bot " , "collaborator " , "vouched " ] ) ;
21+ const WRITE_PERMISSIONS = new Set ( [ "admin " , "maintain " , "write " ] ) ;
2122const EXEMPTIONS_PATH = ".github/TRIAGE_EXEMPTIONS.td" ;
23+ const VOUCHED_PATH = ".github/VOUCHED.td" ;
2224const LOGIN_PATTERN = / ^ g i t h u b : ( [ A - Z a - z 0 - 9 ] (?: [ A - Z a - z 0 - 9 ] | - (? = [ A - Z a - z 0 - 9 ] ) ) { 0 , 38 } ) $ / ;
2325
2426// `labels` matches a PR that carries any one of them.
@@ -45,7 +47,12 @@ const SWEEP_QUERY = `
4547const RECHECK_QUERY = `
4648 query ($owner: String!, $repo: String!, $number: Int!) {
4749 repository(owner: $owner, name: $repo) {
48- pullRequest(number: $number) { state updatedAt labels(first: 100) { nodes { name } } }
50+ pullRequest(number: $number) {
51+ state
52+ mergeable
53+ updatedAt
54+ labels(first: 100) { nodes { name } }
55+ }
4956 }
5057 }` ;
5158
@@ -72,6 +79,17 @@ function parseExemptions(text) {
7279 return logins ;
7380}
7481
82+ // VOUCHED.td: one `github:login` per line, `#` comments, and `-github:login reason` to denounce.
83+ function vouchedLogins ( text ) {
84+ const logins = new Set ( ) ;
85+ for ( const raw of text . split ( "\n" ) ) {
86+ const entry = raw . trim ( ) . split ( / \s + / ) [ 0 ] ;
87+ if ( entry . startsWith ( "github:" ) ) logins . add ( entry . slice ( "github:" . length ) . toLowerCase ( ) ) ;
88+ }
89+ if ( logins . size === 0 ) throw new Error ( `${ VOUCHED_PATH } : no entries` ) ;
90+ return logins ;
91+ }
92+
7593function labeledAt ( pr , name ) {
7694 const last = pr . timelineItems . nodes . filter ( ( event ) => event . label ?. name === name ) . at ( - 1 ) ;
7795 return last ? Date . parse ( last . createdAt ) : undefined ;
@@ -167,7 +185,9 @@ async function sweep({ github, context, core, dryRun }) {
167185 const fresh = ( await github . graphql ( RECHECK_QUERY , { ...repo , number } ) ) . repository
168186 . pullRequest ;
169187 if ( fresh . state !== "OPEN" ) continue ;
170- action = decide ( { ...pr , updatedAt : fresh . updatedAt , labels : fresh . labels } , exemptions , now ) ;
188+ // A merge to the base can resolve a conflict without touching the PR, so this is re-read
189+ // too. An answer that is not ready yet reads as "not conflicting" and waits for tomorrow.
190+ action = decide ( { ...pr , ...fresh } , exemptions , now ) ;
171191 if ( ! action . startsWith ( "close" ) ) continue ;
172192 }
173193
@@ -229,13 +249,16 @@ async function sweep({ github, context, core, dryRun }) {
229249async function enforceOpenLimit ( { github, context, core, dryRun } ) {
230250 const pr = context . payload . pull_request ;
231251 const author = pr . user . login ;
232- const status = process . env . VOUCH_STATUS ;
233- if ( ! status ) {
234- core . warning ( `PR #${ pr . number } : no vouch status, leaving it open.` ) ;
235- return ;
236- }
237- if ( TRUSTED_VOUCH_STATUSES . has ( status ) ) return ;
252+ // Who is trusted is decided here rather than by the vouch action, which reports its own failed
253+ // lookups as "not vouched". Every read below throws on failure, and a throw closes nothing.
254+ if ( pr . user . type === "Bot" ) return ;
238255 if ( parseExemptions ( fs . readFileSync ( EXEMPTIONS_PATH , "utf8" ) ) . has ( author . toLowerCase ( ) ) ) return ;
256+ if ( vouchedLogins ( fs . readFileSync ( VOUCHED_PATH , "utf8" ) ) . has ( author . toLowerCase ( ) ) ) return ;
257+ const { data : access } = await github . rest . repos . getCollaboratorPermissionLevel ( {
258+ ...context . repo ,
259+ username : author ,
260+ } ) ;
261+ if ( WRITE_PERMISSIONS . has ( access . permission ) ) return ;
239262 if ( pr . labels . some ( ( label ) => label . name === KEEP_OPEN_LABEL ) ) return ;
240263 // Someone else reopening a PR is a maintainer overriding the limit.
241264 const reopened = context . payload . action === "reopened" ;
0 commit comments