Skip to content

Commit 64d2146

Browse files
committed
ci: Add auto-label GH action
1 parent b528f32 commit 64d2146

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

.github/workflows/pr-labeler.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Changelog Labeler
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited]
6+
7+
permissions:
8+
pull-requests: write
9+
10+
jobs:
11+
label:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Add changelog label
15+
uses: actions/github-script@v7
16+
with:
17+
script: |
18+
const title = context.payload.pull_request.title.toLowerCase();
19+
const prNumber = context.payload.pull_request.number;
20+
21+
// Get current labels
22+
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
23+
owner: context.repo.owner,
24+
repo: context.repo.repo,
25+
issue_number: prNumber,
26+
});
27+
28+
// Check if a Changelog label already exists
29+
const hasChangelogLabel = currentLabels.some(label =>
30+
label.name.startsWith('Changelog') || label.name === 'skip-changelog'
31+
);
32+
33+
if (hasChangelogLabel) {
34+
console.log('PR already has a Changelog label, skipping');
35+
return;
36+
}
37+
38+
// Determine which label to apply
39+
let newLabel = null;
40+
41+
if (title.startsWith('feat')) {
42+
newLabel = 'Changelog: Feature';
43+
} else if (title.startsWith('fix') || title.startsWith('bugfix')) {
44+
newLabel = 'Changelog: Bugfix';
45+
} else if (title.includes('deprecate')) {
46+
newLabel = 'Changelog: Deprecation';
47+
} else if (title.startsWith('docs')) {
48+
newLabel = 'Changelog: Docs';
49+
} else if (title.startswith('ref') || title.startsWith('test')) {
50+
newLabel = 'Changelog: Internal';
51+
} else if (title.startsWith('ci') || title.startsWith('build')) {
52+
newLabel = 'skip-changelog';
53+
}
54+
55+
// Apply the new label if one was determined
56+
if (newLabel) {
57+
await github.rest.issues.addLabels({
58+
owner: context.repo.owner,
59+
repo: context.repo.repo,
60+
issue_number: prNumber,
61+
labels: [newLabel],
62+
});
63+
64+
console.log(`Applied label: ${newLabel}`);
65+
} else {
66+
console.log('No matching label pattern found in PR title, please add manually');
67+
}
68+

0 commit comments

Comments
 (0)