We recently decided, for safety reasons and ensuring solid reviews, protecting our master branches in GitHub was something we should be doing. Having looked into it, a few quick clicks later our core repositories were done. The challenge came down the line when we needed to easily turn them all on. With >100 repositories that would be somewhat of an arduous point and click task so I knocked up a crude and basic script to do it for me.
For reference a few pages on GitHub’s site are useful:
It should be noted that in the API documentation it states that protected branch API calls are in Developer Preview so you’ll notice the extra part from the docs to enable this:
Update: Nov. 2017
Since writing this post, the API for protected branches is no longer in Developer Preview. Additionally some of the options have moved around in the JSON you need to send.
Most of the original script is fine, but, the API section at the end needs to be updated. We’ve also added the dismiss_stale_reviews option which ensures if any commits are pushed after an approval they are also checked.
About the Author
Ian is Head of Technology for Venntro and heads up
the Product Development and Operations team in Windsor (and remote).