@@ -31,6 +31,7 @@ import {
3131 writeRepairSquashMergeBody ,
3232} from "./repair-merge-message.js" ;
3333import { compactText as compactPlainText } from "./text-utils.js" ;
34+ import { rollUpStatusChecks } from "./status-check-rollup.js" ;
3435
3536const PASSING_CHECK_CONCLUSIONS = new Set ( [ "SUCCESS" , "SKIPPED" , "NEUTRAL" ] ) ;
3637const FIX_PR_MERGE_STATES = new Set ( [ "CLEAN" , "HAS_HOOKS" , "UNSTABLE" ] ) ;
@@ -512,12 +513,11 @@ function validateMergePreflight(preflight: LooseRecord) {
512513
513514function validateStatusChecks ( checks : LooseRecord [ ] ) {
514515 if ( ! Array . isArray ( checks ) || checks . length === 0 ) return "no PR checks found" ;
515- const ignored = ignoredCheckNames ( ) ;
516516 const blockers : LooseRecord [ ] = [ ] ;
517517 let considered = 0 ;
518- for ( const check of latestCheckRuns ( checks ) ) {
518+ for ( const { check, ignored } of postFlightStatusCheckRollup ( checks ) ) {
519519 const name = String ( check . name ?? check . context ?? "unknown check" ) ;
520- if ( isIgnoredStatusCheck ( check , ignored ) ) continue ;
520+ if ( ignored ) continue ;
521521 considered += 1 ;
522522 const status = String ( check . status ?? check . state ?? "" ) . toUpperCase ( ) ;
523523 const conclusion = String ( check . conclusion ?? "" ) . toUpperCase ( ) ;
@@ -552,49 +552,17 @@ function shouldWaitForIssueImplementationChecks(checkBlock: string, view: LooseR
552552}
553553
554554function hasPendingChecks ( checks : LooseRecord [ ] ) {
555- const ignored = ignoredCheckNames ( ) ;
556- return latestCheckRuns ( checks ?? [ ] ) . some ( ( check : JsonValue ) => {
557- if ( isIgnoredStatusCheck ( check , ignored ) ) return false ;
555+ return postFlightStatusCheckRollup ( checks ?? [ ] ) . some ( ( { check, ignored } ) => {
556+ if ( ignored ) return false ;
558557 return isPendingStatusCheck ( check ) ;
559558 } ) ;
560559}
561560
562- function isIgnoredStatusCheck ( check : LooseRecord , ignored : Set < string > ) {
563- const name = String ( check . name ?? check . context ?? "unknown check" ) . toLowerCase ( ) ;
564- const workflow = String ( check . workflowName ?? "" ) . toLowerCase ( ) ;
565- return ignored . has ( name ) || Boolean ( workflow && ignored . has ( workflow ) ) ;
566- }
567-
568- function latestCheckRuns ( checks : LooseRecord [ ] ) {
569- const byKey = new Map < string , LooseRecord > ( ) ;
570- for ( const check of checks ) {
571- const key = checkIdentity ( check ) ;
572- const previous = byKey . get ( key ) ;
573- if ( ! previous || checkTimestamp ( check ) >= checkTimestamp ( previous ) ) byKey . set ( key , check ) ;
574- }
575- return [ ...byKey . values ( ) ] ;
576- }
577-
578- function checkIdentity ( check : LooseRecord ) {
579- const name = String ( check . name ?? check . context ?? "unknown check" ) . toLowerCase ( ) ;
580- const workflow = String ( check . workflowName ?? "" ) . toLowerCase ( ) ;
581- return `${ workflow } \n${ name } ` ;
582- }
583-
584- function checkTimestamp ( check : LooseRecord ) {
585- for ( const field of [
586- "startedAt" ,
587- "started_at" ,
588- "createdAt" ,
589- "created_at" ,
590- "completedAt" ,
591- "completed_at" ,
592- ] ) {
593- const parsed = Date . parse ( String ( check [ field ] ?? "" ) ) ;
594- if ( Number . isFinite ( parsed ) ) return parsed ;
595- }
596- if ( isPendingStatusCheck ( check ) ) return Number . MAX_SAFE_INTEGER ;
597- return 0 ;
561+ function postFlightStatusCheckRollup ( checks : LooseRecord [ ] ) {
562+ return rollUpStatusChecks (
563+ checks ,
564+ process . env . CLAWSWEEPER_POST_FLIGHT_IGNORE_CHECKS ?? DEFAULT_IGNORED_CHECKS . join ( "," ) ,
565+ ) ;
598566}
599567
600568function isPendingStatusCheck ( check : LooseRecord ) {
@@ -603,19 +571,6 @@ function isPendingStatusCheck(check: LooseRecord) {
603571 return ! conclusion && Boolean ( status ) && ! [ "COMPLETED" , "SUCCESS" ] . includes ( status ) ;
604572}
605573
606- function ignoredCheckNames ( ) {
607- const configured = String (
608- process . env . CLAWSWEEPER_POST_FLIGHT_IGNORE_CHECKS ?? DEFAULT_IGNORED_CHECKS . join ( "," ) ,
609- ) ;
610- return new Set (
611- configured
612- . split ( "," )
613- . map ( ( item : JsonValue ) => item . trim ( ) )
614- . map ( ( item : string ) => item . toLowerCase ( ) )
615- . filter ( Boolean ) ,
616- ) ;
617- }
618-
619574function shouldRequirePrChecks ( ) {
620575 return process . env . CLAWSWEEPER_POST_FLIGHT_REQUIRE_PR_CHECKS === "1" ;
621576}
0 commit comments