-
Notifications
You must be signed in to change notification settings - Fork 0
45 lines (38 loc) · 1.36 KB
/
PR_Label_Assign.yml
File metadata and controls
45 lines (38 loc) · 1.36 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
name: PR Title Labeler
on:
pull_request_target:
types: [opened, edited, reopened]
jobs:
label-pr:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Label PR based on title
uses: actions/github-script@v6
with:
script: |
const prTitle = context.payload.pull_request.title;
const labelMap = [
{ pattern: /^feat:/i, label: '✨ feat' },
{ pattern: /^fix:/i, label: '🐞 fix' },
{ pattern: /^chore:/i, label: '⚙️ chore' },
{ pattern: /^docs:/i, label: '📃 docs' },
{ pattern: /^refactor:/i, label: '🔨 refactor' },
{ pattern: /^test:/i, label: '✅ test' }
];
const labelsToAdd = labelMap
.filter(entry => entry.pattern.test(prTitle))
.map(entry => entry.label);
if (labelsToAdd.length > 0) {
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: labelsToAdd
});
core.info(`Added labels: ${labelsToAdd.join(', ')}`);
} else {
core.info('No matching labels found for PR title.');
}