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 +-------------------+
+-----------------+
LayerTechnology
BackendKotlin/JVM, Ktor Server
GitLab Integrationgitlab4j-api
CLIClikt
SerializationKotlinx Serialization + Jackson
ContainerizationJib (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:

CommandAction
SetStatusLabelUpdate MR status label
SetQueueLabelSet queue position label
MergeMerge the MR
RebaseRebase onto target branch
CancelPipelineCancel a running pipeline
RetryJobRetry a failed job
ApplyDesiredLabelsApply desired-state labels
CancelAutoMergeCancel GitLab’s built-in “merge when pipeline succeeds”
AddNoteToMergeRequestAdd 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