Gitlab Merge Request
Description
The gitlab/mergerequest action opens (or updates) a GitLab merge request once a target linked to the same scm has changed something and the change has been pushed.
It is the second half of the GitLab workflow: the gitlab scm commits to a working branch and pushes it, this action turns that branch into a merge request. Without it, the branch is pushed and nothing else happens.
The scm may be either gitlab or gitlabsearch; with the latter, one merge request is opened per discovered project.
Requirements
An action never runs on its own: it needs an scmid pointing at an scm declared in the same manifest, and that scm must be of the matching kind. Both are checked when the manifest loads:
missing value for parameter(s) ["scmid"]
scm of kind "git" is not compatible with action of kind "github/pullrequest"The action then reuses that scm rather than being configured twice. From it, it inherits:
| Field | Inherited value |
|---|---|
| The working branch the scm created and pushed - the branch carrying the changes. |
| The scm’s |
| The repository the scm points at. |
credentials, URL | Whatever the scm was given, when the action does not set its own. |
Every one of these can be overridden in the action spec, but there is rarely a good reason to: a mismatch between the branch the scm pushed and the branch the action opens the request from produces a request with no changes in it.
Where the title comes from
The title is resolved from the first of these that is set:
spec.titleon the actiontitleon the action itself, one level abovespecthe name of the associated target, when there is exactly one
the pipeline name
The second form is the usual one:
actions:
default:
kind: <the action kind>
scmid: default
title: 'deps: bump axios version'Create or update
Updatecli looks for a request already open between the same two branches before creating one, so running the same pipeline repeatedly gives you one long-lived request per pipeline and repository rather than one per run. Whether that existing request is then refreshed with the latest title and description differs by plugin (each page says which).
Creation is also skipped, without failing the pipeline, when either branch is missing from the remote. Updatecli attempts it on every run regardless, so that a request closed by hand or lost to an earlier failure gets reopened on the next one.
Pipeline URL
When Updatecli detects that it runs inside a CI job, it appends a link to that job in the request description. Set disablepipelineurl: true on the action (next to kind and scmid, not inside spec) to leave it out.
Detection is limited to three engines, each recognised by one environment variable: Jenkins (JENKINS_URL), GitLab CI (GITLAB_CI), and GitHub Actions (GITHUB_ACTION), checked in that order. Anywhere else no link is added, whatever this setting says.
Parameters
| Name | Type | Description | Required |
|---|---|---|---|
| allowcollaboration | boolean | “allowcollaboration” defines if members who can merge to the target branch may push commits to the source branch. default: false remark:
| |
| assignees | array | “assignees” defines the list of assignees to add to the merge request. default: empty remark:
example:
| |
| automerge | boolean | “automerge” defines if the auto merge feature is enabled on a new merge request. default: false remark:
| |
| body | string | “body” defines a custom merge request body. default: a body generated from the pipeline execution. remark:
| |
| labels | array | “labels” defines the labels of the merge request. default: empty remark:
| |
| mergecommitmessage | string | “mergecommitmessage” defines the commit message used when the merge request is merged. default: empty remark:
| |
| owner | string | “owner” defines the owner of the GitLab repository. default: the owner of the associated scm of kind “gitlab”. remark:
| |
| removesourcebranch | boolean | “removesourcebranch” defines if the source branch is removed when the merge request is merged. default: false | |
| repository | string | “repository” defines the name of the GitLab repository, for a specific owner. default: the repository of the associated scm of kind “gitlab”. remark:
| |
| reviewers | array | “reviewers” defines the list of reviewers to add to the merge request. default: empty remark:
example:
| |
| sourcebranch | string | “sourcebranch” defines the branch the merge request takes its changes from. default: the working branch of the associated scm of kind “gitlab”. remark:
| |
| squash | boolean | “squash” defines if all commits are squashed into a single commit on merge. default: false remark:
| |
| squashcommitmessage | string | “squashcommitmessage” defines the commit message used when the merge request is squashed and merged. default: empty remark:
| |
| targetbranch | string | “targetbranch” defines the branch the merge request is merged into. default: the branch of the associated scm of kind “gitlab”. remark:
| |
| title | string | “title” defines the title of the GitLab merge request. default: the title is taken from the first match of:
remark:
example: | |
| token | string | “token” defines the credential used to authenticate with GitLab. remark:
example:
| |
| url | string | “url” defines the GitLab url to interact with. default: gitlab.com remark:
example:
| |
| username | string | “username” defines the username used to authenticate with GitLab. |
Assignees and reviewers
assignees and reviewers take numeric GitLab user IDs, not usernames - a list of integers. To find one, open the user’s profile page, then Actions (or ⋮) in the upper-right corner, and Copy user ID.
spec:
assignees:
- 1234567
reviewers:
- 7654321Labels
labels are applied to the merge request, and GitLab creates any label that does not exist yet as a new project label. This is the opposite of the GitHub plugin, where a missing label is an error.
Merge behavior
automerge: true turns on GitLab’s auto-merge, so the merge request merges by itself once its conditions are met - pipeline succeeded, required approvals given. It is a single boolean: there is no equivalent of the GitHub plugin’s merge.strategy, and Updatecli never merges client-side here.
The following options shape what merging produces, and the project’s own settings may override them:
squashSquashes the commits of the source branch into one on merge.
removesourcebranchDeletes the working branch once merged.
mergecommitmessage,squashcommitmessageOverride the commit messages GitLab generates. Left empty, the project’s message templates apply.
allowcollaborationLets members who can merge the target branch push to the merge request’s source branch.
Cleanup
Cleanup is not implemented for this plugin. updatecli apply --clean-git-branches removes working branches that ended up with no changes, but a merge request already opened for one of them is not closed automatically (that stays a manual step).
The same goes for the options this plugin does not expose. If closing stale merge requests, or anything else missing here, is something you would use, say so on the Updatecli issue tracker (these gaps are unimplemented rather than deliberate, and interest is what gets them prioritised).
Example
# updatecli.yaml
# updatecli diff --config updatecli.yaml
#
name: Show Gitlab pipeline example
# Sources are responsible to fetch information from third location such as npm registry.
sources:
updatecli:
name: Get latest axios version
kind: npm
spec:
name: axios
# Targets are responsible to update targeted files such as a yaml file.
targets:
npm:
name: Update e2e test file
kind: yaml
sourceid: updatecli
scmid: gitlab
spec:
file: e2e/updatecli.d/success.d/npm.yaml
key: conditions.axios.spec.version
###
# Actions such as gitlab/mergerequest is triggered if a target is updated.
actions:
default:
title: Bump axios version
kind: gitlab/mergerequest
scmid: gitlab
scms:
gitlab:
kind: gitlab
spec:
owner: "olblak"
repository: "updatecli"
branch: main
# For the change to be apply, we need to specify gitlab credentials
#username: gitlab_username
#token: gitlab_token