Skip to content

Commit 4299026

Browse files
Merge pull request #107 from sanzzzz-g/feature/auto-labeling-workflow
[PR]: Set up automatic issue and PR labeling workflow
2 parents 478f9ad + ef9bc64 commit 4299026

2 files changed

Lines changed: 108 additions & 0 deletions

File tree

.github/labeler.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
3+
documentation:
4+
- changed-files:
5+
- any-glob-to-any-file:
6+
- '**/*.md'
7+
- 'docs/**'
8+
9+
python:
10+
- changed-files:
11+
- any-glob-to-any-file:
12+
- '**/*.py'
13+
14+
github-actions:
15+
- changed-files:
16+
- any-glob-to-any-file:
17+
- '.github/**'
18+
19+
enhancement:
20+
- changed-files:
21+
- any-glob-to-any-file:
22+
- 'src/**'
23+
- '*/**.py'
24+
25+
level1:
26+
- changed-files:
27+
- any-glob-to-any-file:
28+
- '**/*.md'
29+
30+
level2:
31+
- changed-files:
32+
- any-glob-to-any-file:
33+
- '**/*.py'
34+
35+
level3:
36+
- changed-files:
37+
- any-glob-to-any-file:
38+
- '.github/**'
39+
- 'tests/**'

.github/workflows/labeler.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Auto Label Issues and PRs
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
issues:
7+
types: [opened, reopened]
8+
9+
permissions:
10+
contents: read
11+
issues: write
12+
pull-requests: write
13+
14+
jobs:
15+
label-pr:
16+
name: Label Pull Requests
17+
runs-on: ubuntu-latest
18+
if: github.event_name == 'pull_request'
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Apply labels based on changed files
24+
uses: actions/labeler@v5
25+
with:
26+
repo-token: "${{ secrets.GITHUB_TOKEN }}"
27+
configuration-path: .github/labeler.yml
28+
29+
label-issue:
30+
name: Label Issues
31+
runs-on: ubuntu-latest
32+
if: github.event_name == 'issues'
33+
steps:
34+
- name: Label new issues with gssoc26
35+
uses: actions/github-script@v7
36+
with:
37+
github-token: ${{ secrets.GITHUB_TOKEN }}
38+
script: |
39+
const issue = context.payload.issue;
40+
const body = (issue.body || '').toLowerCase();
41+
const title = (issue.title || '').toLowerCase();
42+
43+
const labelsToAdd = ['gssoc26'];
44+
45+
if (title.includes('bug') || body.includes('bug')) {
46+
labelsToAdd.push('bug');
47+
}
48+
if (title.includes('feature') || body.includes('enhancement')) {
49+
labelsToAdd.push('enhancement');
50+
}
51+
if (title.includes('docs') || body.includes('documentation')) {
52+
labelsToAdd.push('documentation');
53+
}
54+
if (title.includes('level 1') || body.includes('level 1')) {
55+
labelsToAdd.push('level1');
56+
}
57+
if (title.includes('level 2') || body.includes('level 2')) {
58+
labelsToAdd.push('level2');
59+
}
60+
if (title.includes('level 3') || body.includes('level 3')) {
61+
labelsToAdd.push('level3');
62+
}
63+
64+
await github.rest.issues.addLabels({
65+
owner: context.repo.owner,
66+
repo: context.repo.repo,
67+
issue_number: issue.number,
68+
labels: labelsToAdd
69+
});

0 commit comments

Comments
 (0)