Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pas256/09a645fe15ee42185555cf176720c396 to your computer and use it in GitHub Desktop.
Save pas256/09a645fe15ee42185555cf176720c396 to your computer and use it in GitHub Desktop.
Enable/disable branch protection on GitHub through their API
#!/bin/bash
OAUTH2_TOKEN=<fill in your own OAUTH2 token>
OWNER=tiesmaster
REPO=Coolkit.Converters # retrieve this with: basename $(git config --get remote.origin.url) .git
curl https://api.github.com/repos/${OWNER}/${REPO}/branches/master \
-H "Authorization: token $OAUTH2_TOKEN" \
-H "Accept: application/vnd.github.loki-preview+json" \
-X PATCH \
-d '{
"protection": {
"enabled": false
}
}' \
-s | json protection
#!/bin/bash
OAUTH2_TOKEN=<fill in your own OAUTH2 token>
OWNER=tiesmaster
REPO=Coolkit.Converters # retrieve this with: basename $(git config --get remote.origin.url) .git
curl https://api.github.com/repos/${OWNER}/${REPO}/branches/master \
-H "Authorization: token $OAUTH2_TOKEN" \
-H "Accept: application/vnd.github.loki-preview+json" \
-X PATCH \
-d '{
"protection": {
"enabled": true,
"required_status_checks": {
"enforcement_level": "everyone",
"contexts": [
"default"
]
}
}
}' \
-s | json protection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment