Skip to content

Architecture

GitLab Auto Merge is a Kotlin/Ktor backend service. It connects to one GitLab project via the GitLab API and manages merge requests autonomously.

+-----------------+ GitLab API +-------------------+
| | ----------------------> | |
| Auto Merge | | GitLab Instance |
| (port 8711) | <---------------------- | |
| | Webhooks +-------------------+
+-----------------+
Layer Technology
Backend Kotlin/JVM, Ktor Server
GitLab Integration gitlab4j-api
CLI Clikt
Serialization Kotlinx Serialization + Jackson
Containerization Jib (Google)
  • Polls every 15 seconds (configurable)
  • Also triggered by GitLab webhooks (MR and pipeline events)
  • Webhook triggers are debounced to avoid redundant runs
  • A mutex prevents concurrent executions

Each auto-merge run executes in strict sequence:

  1. Data Collection — Fetches MRs, pipelines, runners from GitLab API
  2. Calculation — Builds command objects from MR state. No side effects.
  3. Execution — Executes all collected commands against GitLab
  4. Result — Records audit protocol, updates dashboard state

All actions are modeled as command objects:

Command Action
ApplyLabels Apply the computed label set to the MR
Merge Merge the MR
Rebase Rebase onto target branch
CancelPipeline Cancel a running pipeline
RetryJob Retry a failed job
ApplyDesiredLabels Apply desired-state labels
CancelAutoMerge Cancel GitLab’s built-in “merge when pipeline succeeds”
AddNoteToMergeRequest Add comment to MR

Benefits:

  • DryRun shows all planned commands without executing
  • Calculation logic is testable independently of execution
  • Commands can be analyzed, filtered, or reordered before execution

Labels are managed declaratively. The system computes the desired label set for each MR and applies the diff — preventing toggling issues where labels are added and removed in rapid succession.

Every run is recorded with:

  • Start/finish timestamps
  • MRs retrieved and categorized
  • Commands executed (with dry-run flag)
  • All events stored for audit trail and UI display

The official Docker image is available on Docker Hub:

neckarit/gitlab-auto-merge