Skip to content

Eun/merge-with-label

Repository files navigation

Actions Status Coverage Status PkgGoDev go-report

A github bot for merging & updating pull requests with a label.

Functionality

This bot can merge and keep your branches up to date with the latest changes from base (master/main).

Config file

Place merge-with-label.yml in .github repository:

version: 1
merge:
  # specify a list of labels that indicate whether a pull request is eligible
  # for merging (regex)
  # (or-list, only one label must be present on a pull request)
  # (leave empty to disable the merge feature)
  labels:
    - "merge"
  # strategy to merge (can be "commit", "squash" or "rebase")
  strategy: "squash"
  # amount of required approvals before merging
  #requiredApprovals: 1
  # specify a list of users that are required for review (regex)
  # (and-list, all users need to approve)
  #requireApprovalsFrom:
  #  -
  # names of the checks that are need to pass before merging (regex)
  # (and-list, all checks need to pass)
  requiredChecks:
    - ".*"
  # require a linear history
  requireLinearHistory: false
  # delete branch after merging
  deleteBranch: true
  # never merge pull requests that were created by these users (regex)
  #ignoreFromUsers:
  #  - "dependabot"
  # never merge pull requests that match one of these titles (regex)
  #ignoreWithTitles:
  #  - "chore:.+"
  # never update pull requests that match one of these labels (regex)
  #ignoreWithLabels:
  #  - "dont-merge"
update:
  # specify a list of labels that indicate whether a pull request is eligible
  # for updating (regex)
  # (or-list, only one label must be present on a pull request)
  # (leave empty to disable the update feature)
  labels: 
    - "update-branch"
  # never update pull requests that were created by these users (regex)
  ignoreFromUsers:
    - "dependabot"
  # never update pull requests that match one of these titles (regex)
  #ignoreWithTitles:
  #  - "chore:.+"
  # never update pull requests that match one of these titles (regex)
  #ignoreWithTitles:
  #  - "chore:.+"
  # never update pull requests that match one of these labels (regex)
  #ignoreWithLabels:
  #  - "dont-update"

Setup

  1. Create a new github app with following permissions & events

    Repository Permissions

    Permission Level
    Actions Read
    Checks Read and write
    Commit statuses Read-Only
    Contents Read and write
    Metadata Read-Only
    Pull requests Read and write
    Workflows Read and write

    Subscribe to events

    • Check run
    • Pull request
    • Pull request review
    • Push
    • Status
  2. Create a private key and save it

  3. Note down the app id

  4. Spin up the instance somewhere using docker compose

    docker-compose.yml

    version: '3.9'
    services:
      nats:
        image: nats:2.9.20
        restart: unless-stopped
        command: ["--js", "-user", "nats", "-pass", "425751fd-62e2-4b73-9e1b-5a9b0dafc5ad"]
    
      server:
        image: ghcr.io/eun/merge-with-label:latest
        restart: unless-stopped
        command: "server"
        ports:
          - "8000:8000"
        environment:
          PORT: 8000
          NATS_URL: nats://nats:425751fd-62e2-4b73-9e1b-5a9b0dafc5ad@nats:4222
        depends_on:
          - nats
    
      worker:
        image: ghcr.io/eun/merge-with-label:latest
        restart: unless-stopped
        command: "worker"
        volumes:
          - "./private-key.pem:/private-key.pem:ro"
        environment:
          NATS_URL: nats://nats:425751fd-62e2-4b73-9e1b-5a9b0dafc5ad@nats:4222
          APP_ID: <your app id>
          PRIVATE_KEY: /private-key.pem
        depends_on:
          - server

    Make sure you fill in your app id, provide the private-key.pem file and modify the nats username and password

  5. Point the webhook url to the deployment

Fine Tuning Settings

Following environment variables are available

Variable Default Value
AllowedRepositories .*
AllowOnlyPublicRepositories false
BotName merge-with-label
StreamName mwl_bot_events
PullRequestSubject pull_request
PushSubject push
MessageRetryAttempts 5
MessageRetryWait 15s
RateLimitBucketName mwl_rate_limit
RateLimitBucketTTL 24h
RateLimitInterval 30s
AccessTokensBucketName mwl_access_tokens
AccessTokensBucketTTL 24h
ConfigsBucketName mwl_configs
ConfigsBucketTTL 24h
CheckRunsBucketName mwl_check_runs
CheckRunsBucketTTL 10m
DurationBeforeMergeAfterCheck 10s
DurationToWaitAfterUpdateBranch 30s
MaxMessageAge 10m
MessageChannelSizePerSubject 64

Additionally, you can enable debug logging by setting the DEBUG environment variable to true.

Build History

Build history