-
Notifications
You must be signed in to change notification settings - Fork 440
88 lines (75 loc) · 2.81 KB
/
set_pr_label.yml
File metadata and controls
88 lines (75 loc) · 2.81 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Set release label to PR based on title and description
on:
pull_request_target:
types:
- opened
- edited
permissions:
contents: read
issues: write
pull-requests: write
jobs:
set_label:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Assign label based on PR title
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr_title = context.payload.pull_request.title;
// Define regex patterns for labels based on conventional commit keywords
const label_patterns_map = {
"release::bug_fixes": /^(fix)\b/i,
"release::enhancements": /^(feat|refactor|perf)\b/i,
"release::ci_docs": /^(ci|docs)\b/i,
"release::maintenance": /^(chore|style|test|build|revert)\b/i,
};
let assigned_label = null;
// Check each pattern
for (const [release_label, pattern] of Object.entries(label_patterns_map)) {
if (pattern.test(pr_title)) {
assigned_label = release_label;
break; // Assign first matching label
}
}
// If a label was matched, add it to PR
if (assigned_label) {
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [assigned_label]
});
}
- name: Assign label based on PR description
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr_body = context.payload.pull_request.body;
const label_map = {
"Bugfix": "release::bug_fixes",
"Feature / enhancement": "release::enhancements",
"CI / Documentation": "release::ci_docs",
"Maintenance": "release::maintenance"
};
let assigned_label = null;
for (const [checkbox_label, release_label] of Object.entries(label_map)) {
const checkbox_regex = new RegExp(`- \\[x\\] ${checkbox_label}`, 'mi');
if (checkbox_regex.test(pr_body)) {
assigned_label = release_label;
break; // Assign first matching label
}
}
// If a label was matched, add it to PR
if (assigned_label) {
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [assigned_label]
});
}