Skip to content

Commit 1c081a1

Browse files
committed
fix(build-schema): enhance schema dereferencing with GitHub API spec
1 parent 8a5f2ca commit 1c081a1

7 files changed

Lines changed: 2269 additions & 55 deletions

File tree

lib/plugins/branches.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

lib/plugins/rulesets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const overrides = {
77
'required_status_checks': {
88
'action': 'delete',
99
'parents': 3,
10-
'type': 'dict'
10+
'type': 'array'
1111
},
1212
}
1313

schema/dereferenced/repos.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@
145145
"TEAM",
146146
"ROLE"
147147
]
148+
},
149+
"mode": {
150+
"type": "string",
151+
"description": "The bypass mode for the reviewer",
152+
"enum": [
153+
"ALWAYS",
154+
"EXEMPT"
155+
],
156+
"default": "ALWAYS"
148157
}
149158
}
150159
}
@@ -957,6 +966,15 @@
957966
"TEAM",
958967
"ROLE"
959968
]
969+
},
970+
"mode": {
971+
"type": "string",
972+
"description": "The bypass mode for the reviewer",
973+
"enum": [
974+
"ALWAYS",
975+
"EXEMPT"
976+
],
977+
"default": "ALWAYS"
960978
}
961979
}
962980
}

0 commit comments

Comments
 (0)