Skip to content

Commit 411dd70

Browse files
authored
ci: add PR auto-labeler (Universal-Commerce-Protocol#366)
1 parent c44fde5 commit 411dd70

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

.github/workflows/auto-label.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Auto Label Merged PRs
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- main
8+
- "release/**"
9+
10+
jobs:
11+
label_prs:
12+
runs-on: ubuntu-latest
13+
14+
if: github.event.pull_request.merged == true
15+
16+
permissions:
17+
pull-requests: write
18+
19+
steps:
20+
- name: Apply labels based on Conventional Commits
21+
uses: actions/github-script@v7
22+
with:
23+
script: |
24+
const title = context.payload.pull_request.title.toLowerCase();
25+
const prNumber = context.payload.pull_request.number;
26+
const owner = context.repo.owner;
27+
const repo = context.repo.repo;
28+
29+
let labelsToAdd = [];
30+
31+
// The Regex checks: Starts with type (^type), optional scope (\([^)]+\))?, optional bang (!?), and a colon (:)
32+
if (/^feat(\([^)]+\))?!?:/.test(title)) {
33+
labelsToAdd.push('enhancement');
34+
} else if (/^docs(\([^)]+\))?!?:/.test(title)) {
35+
labelsToAdd.push('documentation');
36+
}
37+
38+
if (labelsToAdd.length > 0) {
39+
console.log(`Adding labels: ${labelsToAdd} to merged PR #${prNumber}`);
40+
41+
await github.rest.issues.addLabels({
42+
owner: owner,
43+
repo: repo,
44+
issue_number: prNumber,
45+
labels: labelsToAdd
46+
});
47+
} else {
48+
console.log('No matching Conventional Commit prefix found. No labels added.');
49+
}

0 commit comments

Comments
 (0)