-
-
Notifications
You must be signed in to change notification settings - Fork 7
106 lines (96 loc) · 3.63 KB
/
Copy pathlabeler.yml
File metadata and controls
106 lines (96 loc) · 3.63 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: PR Labeler
# Auto-labels pull requests based on changed file paths.
# Type labels (bug, enhancement, etc.) are applied by the separate
# "Label by PR title" job below, derived from the Conventional Commit title.
# "status: waiting triage" is applied to newly opened PRs from contributors —
# maintainer-authored PRs (OWNER / MEMBER) are skipped.
#
# Uses pull_request_target so labeling works for fork PRs.
# The base repo token is used; PR code is never checked out.
on:
pull_request_target:
types: [opened, synchronize, reopened, edited]
permissions:
contents: read
pull-requests: write
issues: write
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
paths:
name: Label by changed files
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v6
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
configuration-path: .github/labeler.yml
# Additive only — never strip labels. With sync-labels: true the path
# job removed any label not in labeler.yml, which raced the title job
# below and silently deleted its type labels (Bug/enhancement/chore) on
# synchronize/edit. Labels are only ever added now; removing them is a
# maintainer's call, not the bot's.
sync-labels: false
type:
name: Label by PR title
runs-on: ubuntu-latest
# The type label comes from the title, which only changes on open/edit —
# skip synchronize (new commits) so we don't re-run for nothing.
if: github.event.action != 'synchronize'
steps:
- name: Map Conventional Commit type to label
uses: actions/github-script@v9
with:
script: |
const title = context.payload.pull_request.title || '';
const match = title.match(/^(\w+)(?:\([^)]*\))?!?:/);
if (!match) return;
const map = {
feat: 'enhancement',
fix: 'Bug',
docs: 'documentation',
perf: 'performance',
refactor: 'refactor',
test: 'tests',
build: 'dependencies',
ci: 'area: ci',
chore: 'chore',
style: 'chore',
revert: 'Bug',
};
const label = map[match[1].toLowerCase()];
if (label) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: [label],
});
}
if (/^(\w+)(?:\([^)]*\))?!:/.test(title)) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: ['scope: breaking'],
});
}
triage:
name: Mark new PRs for triage
runs-on: ubuntu-latest
# Skip PRs opened by a repo owner or org member — already triaged.
if: >-
github.event.action == 'opened' &&
github.event.pull_request.author_association != 'OWNER' &&
github.event.pull_request.author_association != 'MEMBER'
steps:
- uses: actions/github-script@v9
with:
script: |
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: ['status: waiting triage'],
});