-
Notifications
You must be signed in to change notification settings - Fork 605
72 lines (60 loc) · 2.46 KB
/
pr-labeler.yml
File metadata and controls
72 lines (60 loc) · 2.46 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
# This action adds changelog labels to PRs that are then used by the release
# notes generator in Craft. The configuration for which labels map to what
# changelog categories can be found in .github/release.yml.
name: Label PR for Changelog
on:
pull_request:
types: [opened, edited]
permissions:
pull-requests: write
jobs:
label:
runs-on: ubuntu-latest
steps:
- name: Add changelog label
uses: actions/github-script@v7
with:
script: |
const title = context.payload.pull_request.title.toLowerCase();
const prNumber = context.payload.pull_request.number;
// Get current labels
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
// Check if a Changelog label already exists
const hasChangelogLabel = currentLabels.some(label =>
label.name.startsWith('Changelog:') || label.name === 'skip-changelog'
);
if (hasChangelogLabel) {
console.log('PR already has a Changelog label, skipping');
return;
}
// Determine which label to apply
let newLabel = null;
if (title.includes('deprecate')) {
newLabel = 'Changelog: Deprecation';
} else if (title.startsWith('feat')) {
newLabel = 'Changelog: Feature';
} else if (title.startsWith('fix') || title.startsWith('bugfix')) {
newLabel = 'Changelog: Bugfix';
} else if (title.startsWith('docs')) {
newLabel = 'Changelog: Docs';
} else if (title.startsWith('ref') || title.startsWith('test')) {
newLabel = 'Changelog: Internal';
} else if (title.startsWith('ci') || title.startsWith('build')) {
newLabel = 'skip-changelog';
}
// Apply the new label if one was determined
if (newLabel) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: [newLabel],
});
console.log(`Applied label: ${newLabel}`);
} else {
console.log('No matching label pattern found in PR title, please add manually');
}