Skip to content

Instantly share code, notes, and snippets.

@josecolella
Created August 3, 2023 05:12
Show Gist options
  • Save josecolella/62e1fd34af601d49b49be26a9578f8a6 to your computer and use it in GitHub Desktop.
Save josecolella/62e1fd34af601d49b49be26a9578f8a6 to your computer and use it in GitHub Desktop.
Updating the allow_update_branch setting for a repository
# Updating the setting to update branches when there is a build incident
## Initial rollout
### Why?
A very common thing that happens at Gusto is a build incident due to some flakiness or intermittent database network issue.
A developers first instinct is to update to main to see if the issue has been resolved. Many times this results in merging to
main several times, costing the company money.
### What?
We can leverage two approaches: Github REST API and Octokit.rb (wrapper around the github API)
> Using REST API
```sh
curl --location --request PATCH 'https://api.github.com/repos/org/repo' \
--header 'Accept: application/vnd.github+json' \
--header 'X-Github-Api-Version: 2022-11-28' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ' \
--data '{
"allow_update_branch": false
}'
```
> Using Octokit
```ruby
client.edit_repository('org/repo', allow_update_branch: true)
```
One caveat is the API token that is used needs to have read and write access to Repository access permissions in order to be able to work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment