Skip to content

Commit 83a80b9

Browse files
committed
set labels on PRs
1 parent bb608a2 commit 83a80b9

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

.github/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ changelog:
6161
- chore
6262
- maintenance
6363

64-
- title: Other Changes
64+
- title: ⏪ Reverts
6565
labels:
66-
- "*"
66+
- revert

.github/workflows/label-pr.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Label PRs from Conventional Commits
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, reopened]
6+
7+
permissions:
8+
pull-requests: write
9+
10+
jobs:
11+
label:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Label PR based on title
15+
uses: actions/github-script@v7
16+
with:
17+
script: |
18+
const title = context.payload.pull_request.title.toLowerCase();
19+
const labels = [];
20+
21+
// Check for breaking change indicator (!)
22+
if (title.includes('!:') || title.match(/!\([^)]+\):/)) {
23+
labels.push('breaking');
24+
}
25+
26+
// Match conventional commit types
27+
if (title.startsWith('feat') || title.includes('feature')) {
28+
labels.push('feat');
29+
} else if (title.startsWith('fix')) {
30+
labels.push('fix');
31+
} else if (title.startsWith('docs')) {
32+
labels.push('docs');
33+
} else if (title.startsWith('refactor')) {
34+
labels.push('refactor');
35+
} else if (title.startsWith('perf')) {
36+
labels.push('perf');
37+
} else if (title.startsWith('test')) {
38+
labels.push('test');
39+
} else if (title.startsWith('build')) {
40+
labels.push('build');
41+
} else if (title.startsWith('ci')) {
42+
labels.push('ci');
43+
} else if (title.startsWith('chore')) {
44+
labels.push('chore');
45+
} else if (title.startsWith('style')) {
46+
labels.push('style');
47+
} else if (title.startsWith('revert')) {
48+
labels.push('revert');
49+
}
50+
51+
// Add labels if any were identified
52+
if (labels.length > 0) {
53+
await github.rest.issues.addLabels({
54+
owner: context.repo.owner,
55+
repo: context.repo.repo,
56+
issue_number: context.payload.pull_request.number,
57+
labels: labels
58+
});
59+
60+
console.log(`Added labels: ${labels.join(', ')}`);
61+
}

0 commit comments

Comments
 (0)