-
Notifications
You must be signed in to change notification settings - Fork 2
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
chore: add script to reconcile branch protection #204
Conversation
b1106f6
to
d1eb732
Compare
tested on my experimental org. Only works with orgs and doesn't work with user repos Demonstrating usagesetting rules
empting rules 🐚 echo 'thisisnottheorganisationyourelookingfor/thecoolthing: []' | ./hack/set-checks.sh apply-and-agree-to-risk
thisisnottheorganisationyourelookingfor/thecoolthing : []
{
"url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection",
"required_status_checks": {
"url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/required_status_checks",
"strict": true,
"contexts": [
"hi"
],
"contexts_url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/required_status_checks/contexts",
"checks": [
{
"context": "hi",
"app_id": 15368
}
]
},
"restrictions": {
"url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/restrictions",
"users_url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/restrictions/users",
"teams_url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/restrictions/teams",
"apps_url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/restrictions/apps",
"users": [],
"teams": [],
"apps": []
},
"required_signatures": {
"url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/required_signatures",
"enabled": false
},
"enforce_admins": {
"url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/enforce_admins",
"enabled": false
},
"required_linear_history": {
"enabled": false
},
"allow_force_pushes": {
"enabled": false
},
"allow_deletions": {
"enabled": false
},
"block_creations": {
"enabled": false
},
"required_conversation_resolution": {
"enabled": false
},
"lock_branch": {
"enabled": false
},
"allow_fork_syncing": {
"enabled": false
}
}
Config difference:
{ {
"url": "https://api.github.com/repos/thisisnottheorganisati | "url": null,
"required_status_checks": { "required_status_checks": {
"url": "https://api.github.com/repos/thisisnottheorganisa <
"strict": true, "strict": true,
"contexts": [ | "checks": []
"hi" <
], <
"contexts_url": "https://api.github.com/repos/thisisnotth <
"checks": [ <
{ <
"context": "hi", <
"app_id": 15368 <
} <
] <
}, },
"restrictions": { "restrictions": {
"url": "https://api.github.com/repos/thisisnottheorganisa <
"users_url": "https://api.github.com/repos/thisisnottheor <
"teams_url": "https://api.github.com/repos/thisisnottheor <
"apps_url": "https://api.github.com/repos/thisisnottheorg <
"users": [], "users": [],
"teams": [], "teams": [],
"apps": [] "apps": []
}, },
"required_signatures": { | "required_signatures": null,
"url": "https://api.github.com/repos/thisisnottheorganisa | "enforce_admins": null,
"enabled": false | "required_linear_history": null,
}, | "allow_force_pushes": null,
"enforce_admins": { | "allow_deletions": null,
"url": "https://api.github.com/repos/thisisnottheorganisa | "block_creations": null,
"enabled": false | "required_conversation_resolution": null,
}, | "lock_branch": null,
"required_linear_history": { | "allow_fork_syncing": null,
"enabled": false | "required_pull_request_reviews": null
}, <
"allow_force_pushes": { <
"enabled": false <
}, <
"allow_deletions": { <
"enabled": false <
}, <
"block_creations": { <
"enabled": false <
}, <
"required_conversation_resolution": { <
"enabled": false <
}, <
"lock_branch": { <
"enabled": false <
}, <
"allow_fork_syncing": { <
"enabled": false <
} <
} }
Updating branch protection for thisisnottheorganisationyourelookingfor/thecoolthing on branch main
{
"url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection",
"required_status_checks": {
"url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/required_status_checks",
"strict": true,
"contexts": [
],
"contexts_url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/required_status_checks/contexts",
"checks": [
]
},
"restrictions": {
"url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/restrictions",
"users_url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/restrictions/users",
"teams_url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/restrictions/teams",
"apps_url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/restrictions/apps",
"users": [
],
"teams": [
],
"apps": [
]
},
"required_signatures": {
"url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/required_signatures",
"enabled": false
},
"enforce_admins": {
"url": "https://api.github.com/repos/thisisnottheorganisationyourelookingfor/thecoolthing/branches/main/protection/enforce_admins",
"enabled": false
},
"required_linear_history": {
"enabled": false
},
"allow_force_pushes": {
"enabled": false
},
"allow_deletions": {
"enabled": false
},
"block_creations": {
"enabled": false
},
"required_conversation_resolution": {
"enabled": false
},
"lock_branch": {
"enabled": false
},
"allow_fork_syncing": {
"enabled": false
}
} |
ff61e56
to
ea7eddf
Compare
pass through the output of ./hack/list-checks.sh to ./hack/set-checks.sh and create or update the branch protection rule for the main branch
ea7eddf
to
918fb8e
Compare
updates in 918fb8e include
|
for testing against the repos, with this PR still open to see passing checks I'd recommend selecting two or three repos to see if it reflects the protection rules as expected
to rollback, run to completely apply against all repos run
note that this will take at least 5mins to discovery all the checks from all the repos before applying them. complete rollback
|
set-checks likely won't be able to patch the diff. |
pass through the output of
./hack/list-checks.sh
to./hack/set-checks.sh
and create or update the branch protection rule for the main branch.Long term, tools like Prow's branchprotector
https://docs.prow.k8s.io/docs/components/optional/branchprotector/
would be better, since it's more robust and scaled to fit many communities.