Auto branch protect is a simple web service that listens for organization events to know when a repository has been created. When the repository is created this web service automates the protection of the main branch. It also notifies you with an @mention in an issue within the repository that outlines the protections that were added.
- Install the following:
- Set GH_TOKEN as an environment variable with a value that corresponds to a GitHub Token (ie.
export GH_TOKEN=208923487234780287128091
) - Set the user value in app.py
- Start the local web service via
flask run --host=0.0.0.0 &
- Start the forwarding service via
./ngrok http 5000 &
- Note the forwarding address (ie.
https://cfe6d829.ngrok.io
in the output of the ngrok application)
- Set up a WebHook in the desired GitHub organization example
- Note that the Payload URL should match the forwarding address from ngrok
- Select the individual events radio button and check repositories
- Content type should be application/json
- Save the Webhook
- Create a repository
- See that branch protection and an issue was created for the repo!
- Python
- Flask
- ngrok
- Payloads are capped at 25 MB. If your event generates a larger payload, a webhook will not be fired. This may happen, for example, on a create event if many branches or tags are pushed at once. We suggest monitoring your payload size to ensure delivery. See webhooks docs
- There is a 1 second Delay built in to the code which is NOT ideal. It seems the code is checking for the main branch before it is finished creating.
- This could be done with AWS Lambda and an API Gateway.