dimagi / required-labels

🏷 Automated label checking for GitHub pull requests
BSD 3-Clause "New" or "Revised" License
47 stars 16 forks source link
flask github github-labels python3

GitHub Required Labels

Build Status

:label: Automated label checking for GitHub pull requests.

Label requirements satisfied Label requirements not satisfied

required-labels enforces label rules on your pull requests. We use this at Dimagi to alert our product and design teams of external-facing changes we are making to our code.

Check it out in action here.

There is also a longer write-up on this project here.

You can set customized label requirements for your PRs to enforce particular team workflows with lists of "required", "banned" or "at least one" labels. For example:


Easy Installation

Deploy to Heroku

Click the following button to deploy this app to heroku (you'll need a heroku account):

Deploy

You'll be presented with a set-up screen.

Enter the name for your app. Something like your-required-labels.

Set up the required labels (comma separated):

Enter the credentials:

OR

Note: The application will use GITHUB_TOKEN first if defined and will fall back to GITHUB_USER and GITHUB_PW if not.

Click "deploy app". The app will deploy.

When completed, you can click "Launch App" and it will take you to an information screen which lists all of the label settings.

Next, you should set up your repo.

Updating label settings

In the heroku dashboard for your app, click Settings then Reveal Config Vars. Here you will be able to update the label settings and github credentials at any time.

Deploy to your own machine

Dependencies

Installation

$ git clone git@github.com:dimagi/required-labels.git
$ pip install -r requirements.txt
$ cp custom.conf.template custom.conf

Then modify custom.conf with your own settings. Default behavior is to source this file from project cloned directory.

You can source a custom file path using CONFIG_FILE environment variable.

$ export CONFIG_FILE=/some/path/to/config.conf

You can also set REQUIRED_LABELS_ALL, REQUIRED_LABELS_ANY, or BANNED_LABELS along with GITHUB_USER and GITHUB_PW directly as environment variables:

$ export REQUIRED_LABELS_ALL=required-label-name,other-required-label-name
$ export GITHUB_USER={username}
$ export GITHUB_PW={password}
$ gunicorn main:app

Set up your repo

Enable the Webhook

In the GitHub repository you want to enable this service, click Settings -> Webhooks -> Add Webhook. Then enter the following settings:

Now, a new "checker" should show up when creating a new pull request. Label requirements satisfied

Ensure the user has write permissions

In the Collaborators & teams settings page, make sure the user who you set up earlier has at least Write permissions on the repo.

Running Tests

$ python -m unittest -v