Skip to content

Commit 14370df

Browse files
committed
Merge #190: Add GitHub Action for Automatic Labeling Based on File Changes.
d410c4a added labeler (0xZaddyy) Pull request description: This pull request introduces a GitHub Action workflow that automatically applies labels to pull requests based on the files modified. **What This Does** 1. Automatically applies labels like **c-node**, **c-client**, **c-integration**, etc. 2. Labeling is based on file path patterns using the labeler GitHub Action 3. Runs on PR events: **opened**, **synchronize**, and **reopened** i made a PR to test this in my fork: [https://github.com/0xZaddyy/corepc/pulls](url) ACKs for top commit: tcharding: ACK d410c4a Tree-SHA512: 59acaa756b6c7cde5ddf2b5884ed7e95c655420795f7377df9b73d4c179237edf7a03f03b4f2cfbd641528cacb81ae60f83d74a6efe15a18beaf34adcd79602f
2 parents 16daef8 + d410c4a commit 14370df

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

.github/workflows/pr-labeler.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: PR Labeler
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened]
5+
6+
jobs:
7+
label-pr:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: read
11+
pull-requests: write
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Label PR based on changed files
16+
uses: actions/github-script@v6
17+
with:
18+
github-token: ${{ secrets.GITHUB_TOKEN }}
19+
script: |
20+
const changedFiles = await github.paginate(
21+
github.rest.pulls.listFiles,
22+
{
23+
owner: context.repo.owner,
24+
repo: context.repo.repo,
25+
pull_number: context.issue.number,
26+
}
27+
);
28+
29+
const filePathsToLabels = {
30+
'node/': 'c-node',
31+
'client/': 'c-client',
32+
'integration_test/': 'c-integration_test',
33+
'jsonrpc/': 'c-jsonrpc',
34+
'types/': 'c-types',
35+
'verify/': 'c-verify'
36+
};
37+
38+
const labelsToAdd = new Set();
39+
40+
changedFiles.forEach(file => {
41+
const filePath = file.filename;
42+
for (const [path, label] of Object.entries(filePathsToLabels)) {
43+
if (filePath.startsWith(path)) {
44+
labelsToAdd.add(label);
45+
break;
46+
}
47+
}
48+
});
49+
50+
if (labelsToAdd.size > 0) {
51+
await github.rest.issues.addLabels({
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
issue_number: context.issue.number,
55+
labels: Array.from(labelsToAdd)
56+
});
57+
}

0 commit comments

Comments
 (0)