Sign inSign up

pepakriz/gitlab-merger-bot

By pepakriz

•Updated almost 2 years ago

GitLab merger bot

Image
1

10K+

pepakriz/gitlab-merger-bot repository overview

⁠GitLab merger bot

Build Status

⁠What does it do?

The goal is to have green master after every merge. To achieve this you have to rebase every single merge request just before the merge and wait for the pipeline status. It takes a lot of time of manual maintenance, especially when you have to process a big chunk of merge requests (common situation for large projects, monorepos etc.). So let's automate it with GitLab MergerBot.

  1. When your merge request is ready to merge, assign it to the bot.
  2. The bot will add your request to its own serial (FIFO) queue. (single queue for every repository)
  3. When your request is on the turn, the bot will rebase the MR and start waiting for the pipeline.
  4. When the bot detects some problems with the merge request it'll reassign the merge request back to the author.
    Reasons can be for example:
    • Failing pipeline or pipeline awaiting for a manual action
    • The merge request has unresolved discussions
    • The merge request can't be rebased due to conflict

Assign Merged

⁠Advanced features
  • Autogenerated commit message based on MR title (Suffixed with link to the original MR).
  • The blocking jobs are triggered automatically. Very useful for E2E testing etc.
  • Bot skips squashing when bot:skip-squash label is present on the MR.
  • Bot assigns MR to the beginning of the queue when bot:high-priority is present. Useful for hotfixes etc.

⁠Pre-Installation requirements

⁠Get the auth token
  1. Create a new account for your bot-user
  2. Sign-in to GitLab as bot-user and go to https://gitlab.com/profile/personal_access_tokens⁠
  3. Add new personal access token with api scope

We strongly recommend using a separate account for bot-user. Don't reuse existing account which can leave the project in the future.

⁠Setup GitLab repository
  1. Make sure that your bot-user has privileges to accept merge requests
  2. In General Settings - Merge Request section:
    • set Merge method to Fast-forward merge
    • check Only allow merge requests to be merged if the pipeline succeeds
    • check (optionally) All discussions must be resolved

⁠Usage

⁠Running in kubernetes (with HELM)

To add the Helm Chart for your local client, run helm repo add:

helm repo add gitlab-merger-bot https://pepakriz.github.io/gitlab-merger-bot

And install it:

helm install --name gitlab-merger-bot gitlab-merger-bot \
#	--set settings.gitlabUrl="https://gitlab.mycompany.com" \
	--set settings.authToken="<token>"
⁠Running in docker
docker run -d --name gitlab-merger-bot --restart on-failure \
#	-e GITLAB_URL="https://gitlab.mycompany.com" \
	-e GITLAB_AUTH_TOKEN="<token>" \
	-v "$(pwd)/data":/data \
	pepakriz/gitlab-merger-bot:latest
⁠Running as a plain JS app
yarn install
yarn run build
GITLAB_AUTH_TOKEN="<token>" yarn run start
⁠Configuration options
Env variableDefault value
GITLAB_URLhttps://gitlab.comGitLab instance URL
GITLAB_AUTH_TOKENrequired Your GitLab token
CI_CHECK_INTERVAL10Time between CI checks (in seconds)
MR_CHECK_INTERVAL20Time between merge-requests checks (in seconds)
REMOVE_BRANCH_AFTER_MERGEtrueIt'll remove branch after merge
SQUASH_MERGE_REQUESTtrueIt'll squash commits on merge
AUTORUN_MANUAL_BLOCKING_JOBStrueIt'll autorun manual blocking jobs before merge
SKIP_SQUASHING_LABELbot:skip-squashIt'll skip squash when MR contains this label
HI_PRIORITY_LABELbot:high-priorityIt'll put MR with this label to the beginning of the queue
SENTRY_DSN``It'll enable Sentry monitoring
HTTP_SERVER_ENABLEfalseIt'll enable experimental API and dashboard support
HTTP_SERVER_PORT4000It'll use different http server port
WEB_HOOK_TOKEN``It'll enable experimental web hook support

⁠Development

For web hook development use this:

NGROK_AUTH=<authCode>
docker run -it --rm --net=host -p 4040:4040 -e NGROK_AUTH="$NGROK_AUTH" wernight/ngrok ngrok http 4000

Tag summary

Content type

Image

Digest

sha256:e211c5acc…

Size

28.4 MB

Last updated

almost 2 years ago

docker pull pepakriz/gitlab-merger-bot