webhook-labeler

Serverless function to automatically add labels to Pull Requests based on the changed files

Stars
2

🏷️⚙️ Webhook Labeler

Serverless function to automatically add labels to Pull Requests based on the changed files

How to install

  1. Clone this repo and deploy the code to Vercel
$ git clone https://github.com/rafaelalmeidatk/webhook-labeler
$ cd webhook-labeler
$ vercel
  1. Create a GitHub personal token (instructions here) with the repo scope. The user that generated the token should have permissions to see the target repo and add labels to the PRs.

  2. Inside the Vercel dashboard, access the settings of the deployed project and add the following env variables:

  • GITHUB_TOKEN: the token that you created on step 2
  • GITHUB_SECRET: a strong random string, this should not be public available

A server restart is required, you can do this deploying the code again

  1. Add the labeler.json file to the target repo, inside the .github folder (.github/labeler.json). Config example:
{
  "labels": {
    "core": ["src/**", "api/**"],
    "docs": "docs/**"
  }
}
  1. Go to the Webhooks page inside the repo settings and click the "Add webhook" button
  • Payload URL
    The URL of the deployment you made on step 1
  • Content type
    application/json
  • Secret
    The random string you created on step 3
  • Which events would you like to trigger this webhook?
    Pull requests
  1. After submiting the form, a ping event will be sent to confirm if everything is correct.

You can use the same Payload URL for multiple repos, as long as the user that generated the GitHub token has permissions to read and change labels for all these repos

Development

Run yarn install to install the deps and yarn dev to start the local server (the Vercel CLI should be globally available).