-
Notifications
You must be signed in to change notification settings - Fork 13
56 lines (47 loc) · 1.45 KB
/
labeler.yml
File metadata and controls
56 lines (47 loc) · 1.45 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
name: Label PRs
on:
pull_request:
types: [opened, synchronize]
permissions:
contents: read
pull-requests: write
jobs:
area-labels:
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v5
with:
sync-labels: false
type-label:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const title = context.payload.pull_request.title;
const prefixMap = {
'feat': 'type: feature',
'fix': 'type: fix',
'refactor': 'type: refactor',
'chore': 'type: chore',
'build': 'type: build',
'test': 'type: test',
'docs': 'type: docs',
};
const match = title.match(/^(\w+)(\(.+\))?[!]?:/);
if (!match) return;
const prefix = match[1];
const label = prefixMap[prefix];
if (!label) return;
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
if (labels.some(l => l.name === label)) return;
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: [label],
});