When you use issues and labels to manage day to day work and define a specific process, often there are situations and times where it's hard to keep labels in the right status. For example:
However it's likely that people will forget to assign both labels, and over time there will be a mixture of issues missing one of the two labels.
There are other key situations where automation can help. (see below for these practical examples)
Automation can address all of these situations and streamline work.
Define a set of rules that will automatically
The Triage Bot is an Open GitLab project that makes it possible to automate many issue and merge request hygiene tasks to ensure that your projects are more consistently following a given process.
Here are two examples of how Triage Polices/Rules can automate updates and issue hygiene:
- name: My policy
conditions:
date:
attribute: updated_at
condition: older_than
interval_type: days
interval: 5
state: opened
labels:
- No Label
limits:
most_recent: 50
actions:
labels:
- needs attention
mention:
- markglenfletcher
comment: |
{{author}} This issue is unlabelled after 5 days. It needs attention. Please take care of this before the end of #{2.days.from_now.strftime('%Y-%m-%d')}
- name: sm_request (MISSING a scoped label and assign it as a New Reqeust)
conditions:
labels:
- sm_request
state: opened
forbidden_labels:
- sm_req::triage
- sm_req::transfered
- sm_req::new_request
- sm_req::declined
- sm_req::completed
- sm_req::backlog
- sm_req::assigned
actions:
labels:
- sm_req::new_request
comment: |
SM TriageBot helping out here: This SM Request issue was not in the workflow, automatically adding it as a new request.
There are only two simple steps to set up the TriageBot.
gitlab-ci.yml
file. The gitlab-ci.yml
file is stored in the root directory of your project.Here is an example of the Product and Solution Marketing pipeline, where there are three Jobs defined. There are two Manual jobs, and one Scheduled Job. The two Manual jobs either test(dry-run
) the rules/policies, or actually apply the rules/policies (policy:run
). The one Scheduled job (schedule:policyrun
), when runs will actually apply the rules/policies.
>image: ruby:2.7
stages:
- triage
- run
dry-run:triage:
stage: triage
script:
- gem install gitlab-triage
- gitlab-triage --help
- gitlab-triage --dry-run --token $API_TOKEN --source projects --source-id $CI_PROJECT_PATH
when: manual
except:
- schedules
policy:run:
stage: run
script:
- gem install gitlab-triage
- gitlab-triage --token $API_TOKEN --source projects --source-id $CI_PROJECT_PATH
when: manual
except:
- schedules
schedule:policyrun:
stage: run
script:
- gem install gitlab-triage
- gitlab-triage --token $API_TOKEN --source projects --source-id $CI_PROJECT_PATH
only:
- schedules
$API_TOKEN
that you see in the above example pipeline.You will need to configure a GitLab CI/CD Environment Variable$API_TOKEN
for these jobs to run.
Here's how:
2. Setting Up CI-CD API Token Variable | Image |
---|---|
1. In your project select the left menu option Settings-->CI/CD |
![]() |
2. Then expand the Variables section |
![]() |
3. Add a new line where - Type= "Variable" - Key = "API_TOKEN" - Value = Your API Key. - You have an API Key don't you? (See short instructions below) - Set Masked to True. |
![]() |
4. Save Variables |
3. Getting your API Key | Image |
---|---|
1. The API Key is linked to your account and basically gives the Bot permission to act on your behalf. First click on the dropdown on your personal settings in GitLab. | ![]() |
2. Select Access Tokens and - Give the access token a Name - Leave the Expiration Date blank (unless you want it to expire) - Select "API" for the Scopes - Click Create personal access token |
![]() |
3. The Personal Access Token will appear at the top of the page. | ![]() |
4. Copy the Token and then Add it to the API_TOKEN Value in the CI/CD Variables settings. |
The Triage Policies/Rules are defined in a YML
file called .triage-policies.yml
which is stored in the root directory of your project. For DETAILED instructions about rules and policy options read the Defining a Policy section in the README.md file in the Triage Bot project.
.triage-policies.yml
resource_rules:
issues:
rules:
- name: find all open issues - any label (simple - should be lots)
conditions:
state: opened
This will trigger a pipeline, where the Jobs should all be skipped. You should see this at the bottom of your screen.
4. Dry-Run TriageBot | Image |
---|---|
1. Click on the Pipeline link and go to the pipeline screen | ![]() |
2. Run the "Dry Run" pipeline job. | ![]() |
3. Click on the job and watch it run. | ![]() |
4. Fist it starts by creating a container and getting a runner growing (That means your CI job is defined OK so far) | ![]() |
5. Then it prompts the Triage bot to show it's help output (that means it's working, and your API key is good) | ![]() |
6. Then the job runs the "Dry-Run" and you see the output from the bot as it runs. Just one job - find all the open issues, so it runs fast, finds over 1,000 issues. Since the policy/rule had no filters or actions, the job finishes. | ![]() |
Now, you need to define any specific policies/rules that you need for your project.
Scheduling Jobs | Image |
---|---|
1. Go to CI/CD–>Pipelines on the left menu | ![]() |
2. Click on Create New Schedule | ![]() |
3. Create the schedule - Write a Name/description - Select an Interval pattern (how frequently do you want it to run. Probably daily.) - Leave the Target Branch , and Variables options with the default - Click on Save Pipeline Schedule. |
![]() |
Create a label in your project that is the flag that tells the automation bot to move the issue.
move--> project2Test
.triage-policies.yml
resource_rules:
issues:
rules:
- name: 1. Mooving an issue to another project based on the label - move to Test Project 2
conditions:
labels:
- move--> project2Test
state: opened
actions:
comment: |
/move gitlab-com/marketing/strategic-marketing/testgroup-pmm-isights/testproject2
This rule will look for the label move--> project2Test
in all open issues and then apply the quick action
/move ....
where it specifies the destination for the issue.In the future if you want to move a bunch of issues to that project, all you have to do is add the move--> project2Test
label.
Create a label in your project that is the flag that tells the automation bot to promote the issue to be an epic.
promote-me
.triage-policies.yml
resource_rules:
issues:
rules:
- name: 1.2 Promote Issues to epics
conditions:
labels:
- promote-me
state: opened
actions:
comment: |
/promote
This rule will look for the label promote-me
in all open issues and then apply the quick action
/promte
which promotes the issue into an epic.In the future if you want to promote a bunch of issues, all you have to do is add the promote-me
label.
If you want to effectively delete an issue (strip it of labels, remove it from epics and milestones,and remove estimates, and close it)
Create a label in your project that is the flag that tells the automation bot to promote the issue to be an epic.
deprecate-me
.triage-policies.yml
resource_rules:
issues:
rules:
- name: 1.1 - Deprecate Issues Close and strip labels of deprecated issues
conditions:
labels:
- deprecate-me
state: opened
actions:
comment: |
/remove_milestone
/remove_epic
/remove_estimate
/unlabel
/title Deprecated Issue
/close
This rule will look for the label deprecate-me
in all open issues and then apply a bunch of quick actions that update and close the issue.
In the future if you want to delete and deprecate a bunch of issues, all you have to do is add the deprecate-me
label.
From here, you can build/draft your specific policies/rules for your project.