Skip to content

Commit 4ec2521

Browse files
committed
ci: inline autolabel workflow
The reusable one is not accessible from this public repo
1 parent ca2c3d3 commit 4ec2521

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

.github/workflows/autolabel.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Label PR
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
BOT_TOKEN:
7+
required: true
8+
9+
permissions:
10+
contents: read
11+
pull-requests: write
12+
13+
jobs:
14+
autolabel:
15+
runs-on: ubuntu-latest
16+
name: Automatically Label PR
17+
if: ${{ !github.event.pull_request.draft && !contains(github.event.pull_request.labels.*.name , 'release') }}
18+
steps:
19+
- uses: actions/[email protected]
20+
with:
21+
github-token: ${{ secrets.BOT_TOKEN }}
22+
script: |
23+
const labelPatterns = {
24+
feature: ["feature/*", "feat/*"],
25+
fix: "fix/*",
26+
chore: "chore/*",
27+
docs: "docs/*",
28+
refactor: "refactor/*",
29+
ci: "ci/*"
30+
};
31+
32+
const branchName = context.payload.pull_request.head.ref
33+
const labelsToAdd = [];
34+
35+
for (const label in labelPatterns) {
36+
const patterns = Array.isArray(labelPatterns[label]) ? labelPatterns[label] : [labelPatterns[label]];
37+
for (const pattern of patterns) {
38+
if (branchName.match(new RegExp(`^${pattern.replace('*', '.*')}$`))) {
39+
labelsToAdd.push(label);
40+
break;
41+
}
42+
}
43+
}
44+
45+
if (labelsToAdd.length > 0) {
46+
core.info(`ℹ️ Matched the following labels: ${labelsToAdd.join(", ")}`)
47+
48+
github.rest.issues.addLabels({
49+
...context.repo,
50+
issue_number: context.payload.pull_request.number,
51+
labels: labelsToAdd
52+
})
53+
} else {
54+
core.info(`ℹ️ The HEAD ref of this PR does not match any of the specified patterns.`)
55+
}

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name: Label, Build & Lint PR
1010

1111
jobs:
1212
autolabel:
13-
uses: Navigraph/workflows/.github/workflows/autolabel.yml@main
13+
uses: ./.github/workflows/autolabel.yml
1414
secrets: inherit
1515

1616
filter:

0 commit comments

Comments
 (0)