update-branch-bot

A tool to help developers to ensure that their PRs are up-to-date with master branch 🤖

MIT License

Stars
2

update-branch-bot

Setup

Step 1: Create a Github personal access token

To enable the bot to create pull request comments and access repositories, we need to create a Github personal access token. If the bot will operate on public repositories, the token should have the scope public_repo. If the bot will also operate on private repositories, the token should have the scope repo.

Step 2: Deploy the bot

Option 1: Google Cloud Functions

First, install the dependencies. Follow the instructions under the "before you begin" section here:

Next, create the GCP resources and deploy the bot:

yarn install --prod
gcloud functions deploy GcpGithubWebhook --runtime nodejs10 --trigger-http --set-env-vars GITHUB_WEBHOOK_SECRET=<secret>,GITHUB_TOKEN=<token>,TOPIC_NAME=webhookqueue
gcloud functions deploy GcpWebhookWorker --trigger-topic webhookqueue --runtime nodejs10 --set-env-vars GITHUB_TOKEN=<token>,SLACK_TOKEN=<token>,SLACK_WEBHOOK_URL=<url>

The bot will be available at the URL https://<region>-<name>.cloudfunctions.net/GcpGithubWebhook

Option 2: Azure Functions

First, install the dependencies:

Next, create the Azure resources:

az group create --location <location> --name <name>
az group deployment create --resource-group <name> --template-file azuredeploy.json --parameters appName=<name> GITHUB_TOKEN=<token> GITHUB_WEBHOOK_SECRET=<secret> SLACK_TOKEN=<token> SLACK_WEBHOOK_URL=<url>
func azure functionapp fetch-app-settings <name>

Then, deploy the bot:

yarn install --prod
func azure functionapp publish <name>

The bot will be available at the URL https://<name>.azurewebsites.net/api/AzGithubWebhook

Step 3: Configure the Github webhook

curl 'https://api.github.com/repos/<organization>/<repository>/hooks' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <token>' \
  -d '
  {
    "name": "web",
    "active": true,
    "events": [
      "push",
      "pull_request"
    ],
    "config": {
      "url": "<url>",
      "secret": "<secret>",
      "content_type": "json",
      "insecure_ssl": "0"
    }
  }
  '

Development

This project uses the following static analysis tools: