@@ -105,11 +105,16 @@ function barnacleIssueContext(
105105
106106function barnacleGithub (
107107 files : ReturnType < typeof file > [ ] ,
108- options : { maintainerLogins ?: string [ ] ; repositoryRoles ?: Record < string , string > } = { } ,
108+ options : {
109+ maintainerLogins ?: string [ ] ;
110+ removeLabelNotFound ?: string [ ] ;
111+ repositoryRoles ?: Record < string , string > ;
112+ } = { } ,
109113) {
110114 const maintainerLogins = new Set (
111115 ( options . maintainerLogins ?? [ ] ) . map ( ( login ) => login . toLowerCase ( ) ) ,
112116 ) ;
117+ const removeLabelNotFound = new Set ( options . removeLabelNotFound ?? [ ] ) ;
113118 const repositoryRoles = Object . fromEntries (
114119 Object . entries ( options . repositoryRoles ?? { } ) . map ( ( [ login , role ] ) => [
115120 login . toLowerCase ( ) ,
@@ -147,6 +152,11 @@ function barnacleGithub(
147152 } ,
148153 removeLabel : async ( params : { issue_number : number ; name : string } ) => {
149154 calls . removeLabel . push ( params ) ;
155+ if ( removeLabelNotFound . has ( params . name ) ) {
156+ const error = new Error ( "not found" ) as Error & { status : number } ;
157+ error . status = 404 ;
158+ throw error ;
159+ }
150160 } ,
151161 update : async ( params : { issue_number : number ; state ?: string } ) => {
152162 calls . update . push ( params ) ;
@@ -516,6 +526,32 @@ describe("barnacle-auto-response", () => {
516526 expect ( calls . update ) . toEqual ( [ ] ) ;
517527 } ) ;
518528
529+ it ( "does not close GitHub App-authored PRs when stale PR-limit label removal returns 404" , async ( ) => {
530+ const { calls, github } = barnacleGithub ( [ file ( "README.md" ) ] , {
531+ removeLabelNotFound : [ "r: too-many-prs" ] ,
532+ } ) ;
533+
534+ await runBarnacleAutoResponse ( {
535+ github,
536+ context : barnacleContext (
537+ {
538+ user : {
539+ login : "renovate[bot]" ,
540+ type : "Bot" ,
541+ } ,
542+ } ,
543+ [ "r: too-many-prs" ] ,
544+ ) ,
545+ core : {
546+ info : ( ) => undefined ,
547+ } ,
548+ } ) ;
549+
550+ expect ( calls . removeLabel ) . toContainEqual ( expect . objectContaining ( { name : "r: too-many-prs" } ) ) ;
551+ expect ( calls . createComment ) . toEqual ( [ ] ) ;
552+ expect ( calls . update ) . toEqual ( [ ] ) ;
553+ } ) ;
554+
519555 it ( "still adds candidate labels to broad contributor PRs" , async ( ) => {
520556 const { calls, github } = barnacleGithub ( [
521557 file ( "ui/src/app.ts" ) ,
0 commit comments