-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (42 loc) · 1.3 KB
/
triage.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# https://docs.github.com/en/actions
name: "Triage"
on: # yamllint disable-line rule:truthy
pull_request_target:
types:
- "opened"
jobs:
label:
name: "Label"
runs-on: "ubuntu-latest"
steps:
- name: "Add labels based on branch name"
uses: "actions/github-script@v6"
with:
github-token: "${{ secrets.LCTRS_BOT_TOKEN }}"
script: |
const branchPrefixLabels = {
feature: "enhancement",
fix: "bug",
};
const pullRequest = context.payload.pull_request;
const branchName = pullRequest.head.ref;
const matches = branchName.match(new RegExp('^([^/]+)\/'));
if (!matches instanceof Array) {
return;
}
if (!branchPrefixLabels.hasOwnProperty(matches[1])) {
return;
}
const label = branchPrefixLabels[matches[1]];
try {
await github.rest.issues.addLabels({
issue_number: pullRequest.number,
labels: [
label,
],
owner: context.repo.owner,
repo: context.repo.repo,
});
} catch (error) {
core.setFailed(error.message);
}