Solves the problem of missing automation of labeling merge requests in GitLab. Based on merge request pipelines, labels are automatically assigned using various configuration options.
- Dedicated JSON configuration file to configure all your labels
- Supports regular expressions (RegExp with JS Flavor) to match the suitable labels
- Label assignment method can be either
APPEND
orOVERRIDE
- Only uses the official GitLab API
- Works efficiently and saves resources (fast & lightweight)
- Supports any GitLab instance (On-Premise & Cloud)
The following configuration variants are currently supported.
Assigns labels based on the paths of the changed files. Compares the git diff between the source and target branch of the specific merge request.
Assigns labels based on the commit messages of the made changes. Compares the git log between the source and target branch of the specific merge request.
In order to use gitlab-mr-labeler you must follow these steps:
- Create a Project Access Token in GitLab
- Add a dedicated JSON configuration file
- Configure a CI job that runs on every merge request
You need ~ 7 minutes to get your initial setup up and running 🚀.
This tool needs a PAT in order to be able to assign labels on merge requests. Just follow the steps as described in the GitLab documentation. See Create a project access token.
Make sure to set the following variables:
- Select a role:
Developer
- Select scopes:
api
Add your newly created token as an CI/CD variable. See Define a CI/CD variable in the UI.
In order to configure which labels should be applied you need to provide a json configuration file. You can place the configuration file anywhere in your project repository. This file will be referenced when the gitlab-mr-labeler CLI is called.
You must define the following properties. If you want to disable any label matcher just set the equivalent property to an empty object ({}
).
- assignMethod: Can be either
APPEND
orOVERRIDE
- gitLogMessages: Object of label keys and an array value of matchable regex strings
- gitDiffPaths: Object of label keys and an array value of matchable regex strings
Regular expressions must be defined using the JavaScript flavor.
The format must therefore correspond to the following pattern: /PATTERN/OPTIONAL_FLAGS
(regular expression literal).
For most use cases you should always supply the m
flag to enable multi-line matching.
// .gitlab/gitlab-mr-labeler.config.json
{
"assignMethod": "APPEND",
"gitLogMessages": {
"feature": ["/^feat/mi"]
},
"gitDiffPaths": {
"dependencies": ["/package\.json$/m"]
}
}
Check out the predefined examples to find a good starting point to label your merge requests 🔥.
To automatically determine and assign the appropriate labels you need to define a merge request pipeline job that executes the gitlab-mr-labeler CLI with your created project access token and the relative path to your json configuration file.
# .gitlab-ci.yml
stages:
- prepare
gitlab_mr_labeler:
stage: prepare
image: docker.io/marhali/gitlab-mr-labeler:latest
script: gitlab-mr-labeler $MY_PROCESS_ACCESS_TOKEN .gitlab/gitlab-mr-labeler.config.json
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
Distributed under the MIT License. See LICENSE for more information.
Marcel Haßlinger - @marhali_de - Portfolio Website
Project Link: https://github.com/marhali/gitlab-mr-labeler
If this tool helps you to reduce development time, you can give me a cup of coffee :)