-
Notifications
You must be signed in to change notification settings - Fork 197
Bug/issue 842 #928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main-enterprise
Are you sure you want to change the base?
Bug/issue 842 #928
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,18 @@ const Overrides = require('./overrides') | |
| const ignorableFields = [] | ||
| const previewHeaders = { accept: 'application/vnd.github.hellcat-preview+json,application/vnd.github.luke-cage-preview+json,application/vnd.github.zzzax-preview+json' } | ||
| const overrides = { | ||
| 'contexts': { | ||
| 'action': 'reset', | ||
| 'type': 'array' | ||
| }, | ||
| contexts: { | ||
| action: 'reset', | ||
| type: 'array' | ||
| } | ||
| } | ||
|
|
||
| // GitHub API requires these fields to be present in updateBranchProtection calls | ||
| // See: https://docs.github.com/rest/branches/branch-protection#update-branch-protection | ||
| const requiredBranchProtectionDefaults = { | ||
| required_status_checks: null, | ||
| enforce_admins: null, | ||
| restrictions: null | ||
| } | ||
|
|
||
| module.exports = class Branches extends ErrorStash { | ||
|
|
@@ -73,7 +81,7 @@ module.exports = class Branches extends ErrorStash { | |
| resArray.push(new NopCommand(this.constructor.name, this.repo, null, results)) | ||
| } | ||
|
|
||
| Object.assign(params, branch.protection, { headers: previewHeaders }) | ||
| Object.assign(params, requiredBranchProtectionDefaults, branch.protection, { headers: previewHeaders }) | ||
|
|
||
|
Comment on lines
+84
to
85
|
||
| if (this.nop) { | ||
| 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 { | |
| 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 [] }) | ||
| }).catch((e) => { | ||
| if (e.status === 404) { | ||
| Object.assign(params, Overrides.removeOverrides(overrides, branch.protection, {}), { headers: previewHeaders }) | ||
| Object.assign(params, requiredBranchProtectionDefaults, Overrides.removeOverrides(overrides, branch.protection, {}), { headers: previewHeaders }) | ||
| if (this.nop) { | ||
| resArray.push(new NopCommand(this.constructor.name, this.repo, this.github.repos.updateBranchProtection.endpoint(params), 'Add Branch Protection')) | ||
| return Promise.resolve(resArray) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requiredBranchProtectionDefaultssetsrequired_status_checks,enforce_admins, andrestrictionstonullfor all update calls. BecauseMergeDeep.compareDeepexplicitly ignores deletions for object properties not present in the config, this change can unintentionally clear existing branch protection fields that the config omitted (e.g., existingrestrictionswould be sent asnull). Instead, when branch protection already exists, populate these required keys from the current protection response (converted to the shape expected byupdateBranchProtection) and only fall back tonulldefaults in the 404/no-existing-protection path.