@@ -5,10 +5,18 @@ const Overrides = require('./overrides')
55const ignorableFields = [ ]
66const previewHeaders = { accept : 'application/vnd.github.hellcat-preview+json,application/vnd.github.luke-cage-preview+json,application/vnd.github.zzzax-preview+json' }
77const overrides = {
8- 'contexts' : {
9- 'action' : 'reset' ,
10- 'type' : 'array'
11- } ,
8+ contexts : {
9+ action : 'reset' ,
10+ type : 'array'
11+ }
12+ }
13+
14+ // GitHub API requires these fields to be present in updateBranchProtection calls
15+ // See: https://docs.github.com/rest/branches/branch-protection#update-branch-protection
16+ const requiredBranchProtectionDefaults = {
17+ required_status_checks : null ,
18+ enforce_admins : null ,
19+ restrictions : null
1220}
1321
1422module . exports = class Branches extends ErrorStash {
@@ -73,7 +81,7 @@ module.exports = class Branches extends ErrorStash {
7381 resArray . push ( new NopCommand ( this . constructor . name , this . repo , null , results ) )
7482 }
7583
76- Object . assign ( params , branch . protection , { headers : previewHeaders } )
84+ Object . assign ( params , requiredBranchProtectionDefaults , branch . protection , { headers : previewHeaders } )
7785
7886 if ( this . nop ) {
7987 resArray . push ( new NopCommand ( this . constructor . name , this . repo , this . github . repos . updateBranchProtection . endpoint ( params ) , 'Add Branch Protection' ) )
@@ -83,7 +91,7 @@ module.exports = class Branches extends ErrorStash {
8391 return this . github . repos . updateBranchProtection ( params ) . then ( res => this . log . debug ( `Branch protection applied successfully ${ JSON . stringify ( res . url ) } ` ) ) . catch ( e => { this . logError ( `Error applying branch protection ${ JSON . stringify ( e ) } ` ) ; return [ ] } )
8492 } ) . catch ( ( e ) => {
8593 if ( e . status === 404 ) {
86- Object . assign ( params , Overrides . removeOverrides ( overrides , branch . protection , { } ) , { headers : previewHeaders } )
94+ Object . assign ( params , requiredBranchProtectionDefaults , Overrides . removeOverrides ( overrides , branch . protection , { } ) , { headers : previewHeaders } )
8795 if ( this . nop ) {
8896 resArray . push ( new NopCommand ( this . constructor . name , this . repo , this . github . repos . updateBranchProtection . endpoint ( params ) , 'Add Branch Protection' ) )
8997 return Promise . resolve ( resArray )
0 commit comments