Skip to content

Commit 1107316

Browse files
committed
fix: apply org-level settings before loading repository configurations
1 parent b2a6c96 commit 1107316

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

lib/plugins/branches.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@ const Overrides = require('./overrides')
55
const ignorableFields = []
66
const previewHeaders = { accept: 'application/vnd.github.hellcat-preview+json,application/vnd.github.luke-cage-preview+json,application/vnd.github.zzzax-preview+json' }
77
const 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

1422
module.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)

lib/settings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class Settings {
4646
const settings = new Settings(nop, context, context.repo(), config, ref)
4747

4848
try {
49+
// Apply org-level settings (e.g., rulesets) first, matching syncAll behavior
50+
await settings.updateOrg()
51+
4952
for (const repo of repos) {
5053
settings.repo = repo
5154
await settings.loadConfigs(repo)

0 commit comments

Comments
 (0)