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
stale
to MRs without activity in the last 21 days.The
stale
label 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
stale
label 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_at
updated when we commented and added thestale
label at the 21 day mark.So instead we count 7 days from that point in time for the
close
step. -
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()