@@ -64,7 +64,7 @@ module.exports = class Branches extends ErrorStash {
6464 const params = Object . assign ( { } , p )
6565 return this . github . rest . repos . getBranchProtection ( params ) . then ( ( result ) => {
6666 const mergeDeep = new MergeDeep ( this . log , this . github , ignorableFields )
67- const changes = mergeDeep . compareDeep ( { branch : { protection : this . reformatAndReturnBranchProtection ( result . data ) } } , { branch : { protection : Overrides . removeOverrides ( overrides , branch . protection , result . data ) } } )
67+ const changes = mergeDeep . compareDeep ( { branch : { protection : this . reformatAndReturnBranchProtection ( structuredClone ( result . data ) ) } } , { branch : { protection : Overrides . removeOverrides ( overrides , branch . protection , result . data ) } } )
6868 const results = { msg : `Followings changes will be applied to the branch protection for ${ params . branch . name } branch` , additions : changes . additions , modifications : changes . modifications , deletions : changes . deletions }
6969 this . log . debug ( `Result of compareDeep = ${ results } ` )
7070
@@ -81,7 +81,7 @@ module.exports = class Branches extends ErrorStash {
8181 resArray . push ( new NopCommand ( this . constructor . name , this . repo , null , results ) )
8282 }
8383
84- Object . assign ( params , requiredBranchProtectionDefaults , branch . protection , { headers : previewHeaders } )
84+ Object . assign ( params , requiredBranchProtectionDefaults , this . reformatAndReturnBranchProtection ( structuredClone ( result . data ) ) , Overrides . removeOverrides ( overrides , branch . protection , result . data ) , { headers : previewHeaders } )
8585
8686 if ( this . nop ) {
8787 resArray . push ( new NopCommand ( this . constructor . name , this . repo , this . github . rest . repos . updateBranchProtection . endpoint ( params ) , 'Add Branch Protection' ) )
@@ -131,6 +131,29 @@ module.exports = class Branches extends ErrorStash {
131131 protection . required_linear_history = protection . required_linear_history && protection . required_linear_history . enabled
132132 protection . enforce_admins = protection . enforce_admins && protection . enforce_admins . enabled
133133 protection . required_signatures = protection . required_signatures && protection . required_signatures . enabled
134+ protection . allow_force_pushes = protection . allow_force_pushes && protection . allow_force_pushes . enabled
135+ protection . block_creations = protection . block_creations && protection . block_creations . enabled
136+ protection . lock_branch = protection . lock_branch && protection . lock_branch . enabled
137+ protection . allow_fork_syncing = protection . allow_fork_syncing && protection . allow_fork_syncing . enabled
138+ if ( protection . restrictions ) {
139+ delete protection . restrictions . url
140+ protection . restrictions . users = Array . isArray ( protection . restrictions . users )
141+ ? protection . restrictions . users . map ( user => user . login || user )
142+ : [ ]
143+ protection . restrictions . teams = Array . isArray ( protection . restrictions . teams )
144+ ? protection . restrictions . teams . map ( team => team . slug || team )
145+ : [ ]
146+ protection . restrictions . apps = Array . isArray ( protection . restrictions . apps )
147+ ? protection . restrictions . apps . map ( app => app . slug || app )
148+ : [ ]
149+ }
150+ if ( protection . required_status_checks ) {
151+ delete protection . required_status_checks . url
152+ delete protection . required_status_checks . contexts_url
153+ if ( Array . isArray ( protection . required_status_checks . contexts ) && protection . required_status_checks . contexts . length === 0 ) {
154+ delete protection . required_status_checks . contexts
155+ }
156+ }
134157 if ( protection . required_pull_request_reviews && ! protection . required_pull_request_reviews . bypass_pull_request_allowances ) {
135158 protection . required_pull_request_reviews . bypass_pull_request_allowances = { apps : [ ] , teams : [ ] , users : [ ] }
136159 }
0 commit comments