Examples¶
Note
A quick demo of what SCM Engine can do.
The script field is a expr-lang expression, a safe, fast, and intuitive expression evaluator.
Close Merge Requests without recent activity¶
This example will close a Merge Request if no activity has happened for 28 days.
The script will warn at 21 days mark that the Merge Request will be closed, with instructions on how to prevent it.
-
Add the label
staleto MRs without activity in the last 21 days.The
stalelabel will automatically be removed if any activity happens on the MR. -
Syntax highlighted
script -
Syntax highlighted
if -
Syntax highlighted
if -
Send "warning" about the MR being inactive
- Add the
stalelabel to the MR (if it doesn't exists) - Add a comment to the MR
- Close the MR
- Add a comment to the MR
-
Close the MR if no activity has happened after 7 days.
Why 7 days?
The
merge_request.updated_atupdated when we commented and added thestalelabel at the 21 day mark.So instead we count 7 days from that point in time for the
closestep. -
You can use Twitter Bootstrap color variables instead of HEX values.
Add label if a file extension is modified¶
# yaml-language-server: $schema=https://jippi.github.io/scm-engine/scm-engine.schema.json
label:
- name: lang/go
color: $indigo
script: merge_request.modified_files("*.go")
- name: lang/markdown
color: $indigo
script: merge_request.modified_files("*.md")
- name: type/documentation
color: $green
script: merge_request.modified_files("docs/")
- name: go::tests::missing
color: $red
priority: 999
script: |1
merge_request.modified_files("*.go")
&& NOT merge_request.modified_files("*_test.go")
- name: go::tests::ok
color: $green
priority: 999
script: |1
merge_request.modified_files("*.go")
&& merge_request.modified_files("*_test.go")
Generate labels via script¶
# yaml-language-server: $schema=https://jippi.github.io/scm-engine/scm-engine.schema.json
label:
# Generate list of labels via script
- strategy: generate
# With a description (optional)
description: "Modified this service directory"
# With the color $pink
color: "$pink"
# From this script, returning a list of labels
script: >
/* Generate a list of files changed in the MR inside pkg/service/ */
merge_request.modified_files_list("pkg/service/")
/* Remove the filename from the path
pkg/service/example/file.go => pkg/service/example */
| map({ filepath_dir(#) })
/* Remove the prefix "pkg/" from the path
pkg/service/example => service/example */
| map({ trimPrefix(#, "pkg/") })
/* Remove duplicate values from the output */
| uniq()
/* Generate a list of files changed in the MR inside pkg/service/ */
merge_request.modified_files_list("pkg/service/")
/* Remove the filename from the path
*
* pkg/service/example/file.go => pkg/service/example
*/
| map({ filepath_dir(#) })
/* Remove the prefix "pkg/" from the path
*
* pkg/service/example => service/example
*/
| map({ trimPrefix(#, "pkg/") })
/* Remove duplicate values from the output */
| uniq()
Assign reviewers from CODEOWNERS¶
The codeowners source relies on the GitLab CODE OWNERS feature.
For a reviewer to be assigned to a Merge Request, the project must have a CODEOWNERS file and the groups/users mentioned in the file must have direct membership to the project.
# yaml-language-server: $schema=https://jippi.github.io/scm-engine/scm-engine.schema.json
actions:
- name: "assign"
if: |1
merge_request.state_is("opened")
&& not merge_request.approved
then:
- action: assign_reviewers
source: codeowners
limit: 1
mode: random
Assign reviewers from Backstage¶
The backstage source relies on the Backstage Catalog to derive ownership information.
This assumes System and User in Backstage can be mapped directly to a GitLab project and user.
For a Backstage System entity to be mapped to a GitLab project, the system must have same name as the GitLab project or the gitlab.com/project annotation is set to the GitLab project name.
For a Backstage User entity to be mapped to a GitLab user, the user must have the gitlab.com/user_id annotation set to the numeric ID of the user. A plugin that can be used to automatically set this annotation is @seatgeek/backstage-plugin-gitlab-catalog-backend.
# yaml-language-server: $schema=https://jippi.github.io/scm-engine/scm-engine.schema.json
actions:
- name: "assign"
if: |1
merge_request.state_is("opened")
&& not merge_request.approved
then:
- action: assign_reviewers
source: backstage
limit: 1
mode: random
Assign reviewers from static user IDs¶
The static source allows you to specify a fixed list of GitLab user IDs to assign as reviewers. This is useful when you want to assign specific users regardless of CODEOWNERS or Backstage configuration.
You can find a user's numeric ID by visiting their GitLab profile page - the ID is shown in the URL or on the profile.