GitLab
Ticket creation
Load @leitwerk-dev/ticket-creation and set:
extensions:
gitlab:
ticket_creation:
enabled: true
default_labels: [created-by-leitwerk]
gitlab_create_issue discovers projects from configured profiles, excluding archived
projects and projects with issues disabled. The token needs API access and permission
to create issues and configured default labels in the destination. Optional labels
must already exist. Set default_labels: [] to omit defaults; label names cannot
contain commas.
The normal draft process asks for approval before writing. Its snapshot pins the
installation, project ID and path. Renamed, transferred, disabled or repointed
destinations fail before writing. Retry reconciliation includes closed issues and
recovers lost create responses. Ticket creation defaults to disabled; enabling it
requires the ticket process to be loaded.
Profiles and delivery
@leitwerk-dev/gitlab supplies GitLab v4 API access and repository-scoped HTTPS Git authentication from one server-owned profile. Load this optional extension on the server and worker.
extensions:
gitlab:
profiles:
example:
base_url: https://forge.test
token: env:GITLAB_TOKEN
ignored_comment_users: [sonarqube]
# Optional, when /user cannot provide a usable commit identity:
# git_identity:
# name: Leitwerk Bot
# email: bot@example.net
base_url must be an HTTPS origin without credentials, a query or a fragment. Supply a personal, project or group token with api and write_repository scopes and permission to push the selected source branches. Tokens stay on the server except for the selected repository's authenticated worker.start delivery. No separate Git credential configuration is needed. Missing tokens, identity or permissions are configuration errors.
Public interface
GitLabClientLike defines project/group discovery, MR metadata and paginated changes, branches/commits, pipelines, failed jobs, bounded traces, bot identity and notes. GitLabClient implements it using HTTPS, pagination and bounded transient read retries. Errors omit response bodies and credentials. Writes are reconciled by their caller rather than blindly repeated.
gitlabIntegration exposes profiles() and client(profile) through the SDK capability registry. setupGitLabIntegration() registers an explicit adapter for tools and external observations.
- Server setup also supplies
repositoryCatalog for Settings. Opening Settings
or a repository editor does not scan GitLab. Searches of at least two characters
read one page of up to 100 matches per profile and cache repeated queries;
concurrent identical searches share one request. Refresh sources explicitly
loads a complete catalog, which subsequent searches filter locally. A failed
refresh retains the last successful data. Server restart or integration
reconfiguration starts a new cache. Saved selections use known metadata without
remote reads; unknown names display the stable repository ID until found.
Admission and delivery still read live project metadata and permissions through
client(profile).
listMergeRequests(projectId, labels) reads open MRs matching every comma-separated label. Pass null for projectId to query all accessible projects without enumerating repositories. Both forms use scope=all, not only MRs authored by the token owner.
listMergeRequestLabelEvents() reads paginated label transitions with stable event IDs. updateMergeRequestLabels() applies add_labels and remove_labels without replacing unrelated labels.
registerGitLabMaintainedProcess() registers a typed MR maintenance policy through
the capability registry. One server service observes all registered processes,
including running turns and operator waits. The process supplies its repair
destinations, state adapters and completion policy.
gitlabRepositoryCredentials(profile, projects) derives internal credential references. The core authorizes their HTTPS origin and exact repository path against the process projects.
selectGitLabProjects() expands exact includes and groups, including subgroups, then applies exclusions. Includes form a union; stable project IDs remove duplicates. An explicit include or all_accessible: true is required.
observeMergeRequest() selects the newest pipeline associated with the current MR source revision. Synthetic merge commits must contain that head as a parent. With no matching MR pipeline, it falls back to the current source branch's push pipeline. A newer pending result supersedes older terminal results. The observation includes GitLab's has_conflicts, merge_status and detailed_merge_status, plus targetHead read from the current target branch (not the historical diff base). Closed MRs do not require branch or pipeline reads.
gitLabMergeRepairReason(mr) identifies explicit conflict and need_rebase evidence. gitLabMergeabilityPending(mr) distinguishes asynchronous checks; approvals, discussions and generic merge blocking are not Git conflict evidence.
gitlabExternal.mergeRequest() reports MR closure/merge, source/target project and branch changes, current heads, mergeability and CI observations. Mergeability or target changes wake an idle process even when its source SHA and successful pipeline are unchanged. Its afterKey is the previous observationKey(). An optional wakeAt timestamp permits recovery timers without retaining a worker. Poll failures back off from 30 seconds to five minutes and surface diagnostics.
Commit-pinned repository inspection
gitlab_inspect_project, gitlab_repository_tree, gitlab_repository_file, and
gitlab_code_search require a GitLab process project binding. Tree, file, and
search calls require a full commit ID as ref; branches are rejected. Tokens
stay on the server unless the process explicitly declares repository credentials.
gitlab_code_search({ projectKey, ref, search, page?, perPage? }) uses
project-scoped basic blob search. It returns paths, snippets, starting lines, the
requested revision/page, and nextPage (null when complete). Defaults are page
1 and 20 results; at most 100 results are returned per page. Follow continuation
pages and read the files for complete evidence. Access errors, unavailable search,
invalid responses, and cancellation fail the call; they are never empty matches.
Project-bound tools
Project metadata binds tools to { gitlab: { profile, projectId, iid } }. Each call requires an authorized process project. Available tools are gitlab_observe_merge_request, gitlab_get_changes, gitlab_get_identity, gitlab_list_failed_jobs, gitlab_get_job_trace, gitlab_comment, and gitlab_reply. Job and pipeline reads verify membership in the bound MR's current pipeline. Traces cap individual reads at 256 KiB; truncation is explicit.
Comments require a stable business writeKey. ensureGitLabComment() combines it with the instance, project, MR and process IDs, appends a hidden marker, and uses ctx.externalWrites.ensure(). It searches remote notes before creating a comment and after an uncertain write. gitlab_reply additionally requires discussionId and reconciles within that discussion. Repeating a call after losing either the response or the local write-log record reuses the same remote comment.
The MR external source can also observe review feedback using feedback: { afterId, since, quietPeriodMs }. It reads paginated discussions, preserving inline file/line context, and excludes system/resolved notes, Leitwerk-generated comment markers and accounts flagged as bots. Human comments by the authenticated PAT owner remain actionable. Each new unseen note resets the trailing quiet period; a mature batch wakes the process even when the MR revision and CI status are unchanged. The process owns the durable cursor and decides when feedback is consumed. The provider recomputes timing from note timestamps after restart.
Each profile may configure ignored_comment_users, defaulting to []. Usernames
are case-insensitive and accept a leading @. The shared feedback reader excludes
those authors for every workflow using the profile, before feedback settling and
cursor selection. Their general comments, inline comments and replies do not trigger
work or acknowledgements. Other users' replies in the same discussion remain
actionable; mentioning an ignored account does not exclude a comment. Profile edits
apply after server restart; executing turns keep their captured inputs. CI and
conflict observations remain available.
ensureGitLabSeenReaction() lets a process acknowledge an authorized MR comment with an eyes reaction. It reconciles the authenticated bot's reaction and records it with ctx.externalWrites.ensure(). Other users' eyes reactions do not suppress the bot's acknowledgement; retries and restarts do not duplicate it. The calling process owns selection and lifecycle checks.
gitlab_approve_merge_request approves the bound MR when its current source SHA matches the supplied full SHA. The write key includes that SHA. A repeated call reconciles the bot's existing approval and does not approve again. A SHA that is no longer HEAD is left unapproved. gitlab_unapprove_merge_request removes that approval when the same SHA is still HEAD. A repeated call does not unapprove again. A moved HEAD is left unchanged so the next review can decide.
The extension contains no Renovate selection or repair policy. ./testing exports a persistent LocalGitLabAdapter with real local repository ancestry for integration tests.
Merge request templates
When creating a new merge request, Leitwerk reads
.gitlab/merge_request_templates/ from the target project's default branch.
Default.md wins; without it, Leitwerk uses the sole Markdown template. If
several exist with no default, delivery reports the ambiguity and uses the
normal description. Templates from other projects or GitLab settings are not
used. A repository read error is retryable, not interpreted as an absent template.
The initial description keeps the template's Markdown structure and appends the
workflow's links and recovery marker. Template quick actions are not executed.
Reconciliation and later updates leave existing descriptions unchanged.
Shared MR maintenance
Opt in during setupServer. Declare external edges using
gitlabMaintenanceSource() and register their identities:
registerGitLabMaintainedProcess(api, {
processId: process.id,
paramsCodec: process.paramsCodec,
stateCodec: process.stateCodec,
idleTurnId: "deliver_change",
observe: repairPolicy.observe,
stopped: repairPolicy.stopped,
terminal: repairPolicy.terminal,
completion: repairPolicy.completion,
complete: repairPolicy.complete,
});
Bindings default to each process project's gitlab metadata. bindings can
provide explicit MR targets. settings supplies the consumed feedback cursor,
activation receipt, polling interval and quiet period; the quiet period defaults
to two minutes. assess, eligible and canWrite retain process-specific admission
rules. observe returns state and an optional declared external action ID, such
as maintenance_feedback. It replaces the former destinations alias mapping.
The service fires that edge; ordinary observations allocate no worker or turn record.
currentBinding identifies a selected repair or operator decision so removing a
different MR's label preserves that business position. Interrupted repairs on
remaining MRs retain their staged work and repair budgets.
messages supplies retry-safe discussion replies or comments. settled advances
business acknowledgement state after those writes succeed. completion determines
the terminal lifecycle without remote writes. complete delivers process-specific
terminal writes and retries them after the process ends.
Eligible, owned bindings request server-managed recovery for failed unaccepted
worker starts. The server allows three starts per episode, with 30/60 second
retry delays for known transient failures. Configuration errors, OOMs and unknown
failures require manual recovery. Accepted failed turns are never retried by
maintenance. Recovery does not consume the process's business repair budget.
The deprecated retry.maxAttempts setting is ignored; maintenance cannot override
the server's startup budget.
Taking responsibility adds leitwerk-active. Green CI keeps maintenance active for
later feedback. Removing the label ends that MR's activation and leaves the MR open.
Other bindings continue; a single stopped, unmerged binding aborts its process.
Remove/re-add pairs between polls end the old activation. Ownership is rechecked
before publication, replies and reactions; late worker outcomes are fenced.
Label-read failures produce retry diagnostics and do not cancel maintenance.
Deleting a linked MR aborts the whole process, including running repairs and
operator waits. Deletion is confirmed by an MR 404 while its project remains
accessible; access failures and other read errors remain retryable diagnostics.
Deleted bindings are persisted and receive no further MR reads or writes after
restart.
Merged MRs lose leitwerk-active and gain leitwerk-done. Unmerged closure and
stopping remove active without adding done. Label writes preserve unrelated labels
and reconcile lost responses. Startup adopts live bindings and existing activation
receipts, retaining feedback cursors, budgets, selected turns and historical records.
Processes retain their own reactivation admission and partial-completion rules.
The shared publication adapter used by Jira and GitLab repository changes registers
this policy. Settled feedback and actionable conflicts invoke Address Feedback
directly; failed current-revision CI invokes Fix CI. Changed work returns to Deliver.
A no-change outcome returns through Deliver to check concurrent source updates and
retained local work before acknowledging its batch. An unchanged checkout creates
no commit or push. Label, target-head and mergeability updates do not replay a
handled pipeline failure. A new pipeline or an observed running-to-failed retry
remains actionable. Maintenance adds no business turns.
The current source branch is authoritative, including developer rebases and pushes.
Idle observations adopt its head while retaining the earlier work baseline and
publication receipt separately. Feedback stays actionable when the head changes;
the worker reconciles unpublished local work before adjusting the current revision.
Source/target project or branch changes are explicit binding errors, not permission
to publish elsewhere. Active workers keep their captured state; delivery rechecks
the branch after their work. Only pipelines associated with the current source
revision or a merge-result commit containing it can trigger repair.
An eyes reaction means the watcher saw an authorized comment. It does not mean a
worker started, completed an adjustment, or consumed the feedback. Comments remain
pending until publication or a verified no-change result is acknowledged. Conflict
resolution, validation retries and safe publication use the shared
Coding reconciliation contract.
Creating repository changes
Load gitlab-repo-change for UI and labeled-issue
change workflows. Repository-only metadata { gitlab: { profile, projectId } }
permits identity resolution and MR creation. gitlab_ensure_merge_request validates
the process branches, reconciles its remote marker through the durable write log,
and pins iid through server project persistence. Existing MR-bound metadata and
tool calls remain supported. MR-only tools reject missing bindings.
The GitLab repository change process uses SSH clone URLs and git-ssh profiles.
The Jira GitLab change process supports HTTPS with
the GitLab profile's token, or explicitly selected SSH profiles. HTTPS mappings need
no separate SSH credentials. Jira API tokens stay on the server. Supplying origin
in the GitLab binding pins the installation: tool calls fail if its profile is repointed.