(To be improved)
- httpie (which provides the
http
command) —pip install httpie
- Save the
git-branch-protection.sh
asgit-branch-protection
somewhere in your path (something like~/bin
or~/.local/bin
if you already use it) - Generate a GitHub token and save it as
~/.config/github_token
.
$ git branch-protection protect
Show branch protection of master branch
gh api repos/:owner/:repo/branches/master/protection
Deletes branch protection of master branch
gh api -X DELETE repos/:owner/:repo/branches/master/protection
Configuation for the branch protection to enable https://docs.github.com/en/rest/reference/repos#update-branch-protection
echo '{
"required_status_checks": {
"strict": true,
"contexts": ["contexts"]
},
"enforce_admins": true,
"required_pull_request_reviews": {
"dismissal_restrictions": {
"users": ["users"],
"teams": ["teams"]
},
"dismiss_stale_reviews": false,
"require_code_owner_reviews": false,
"required_approving_review_count": 1
},
"restrictions": {
"users": ["users"],
"teams": ["teams"],
"apps": ["apps"]
}
}' >/tmp/config-branch-rules
Applies the branch protection specified above to master branch
gh api --method PUT --preview luke-cage repos/:owner/:repo/branches/master/protection --input /tmp/config-branch-rules >/dev/null