Skip to content

Commit f90096a

Browse files
committed
chore: add labeler bot
Signed-off-by: Min Zhang <minzhang@redhat.com>
1 parent 5106d72 commit f90096a

File tree

3 files changed

+217
-0
lines changed

3 files changed

+217
-0
lines changed

.github/labeler.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Controller related changes
2+
area/controller:
3+
- changed-files:
4+
- any-glob-to-any-file:
5+
- 'controllers/**/*'
6+
- 'main.go'
7+
8+
# Daemon related changes
9+
area/daemon:
10+
- changed-files:
11+
- any-glob-to-any-file: 'daemon/**/*'
12+
13+
# CNI plugin related changes
14+
area/cni:
15+
- changed-files:
16+
- any-glob-to-any-file: 'cni/**/*'
17+
18+
# Plugin related changes
19+
area/plugin:
20+
- changed-files:
21+
- any-glob-to-any-file: 'internal/**/*'
22+
23+
# API/CRD changes
24+
area/api:
25+
- changed-files:
26+
- any-glob-to-any-file:
27+
- 'api/**/*'
28+
- 'config/crd/**/*'
29+
30+
# Configuration changes
31+
area/config:
32+
- changed-files:
33+
- any-glob-to-any-file: 'config/**/*'
34+
35+
# Documentation changes
36+
area/docs:
37+
- changed-files:
38+
- any-glob-to-any-file:
39+
- 'document/**/*'
40+
- 'README.md'
41+
- '**/*.md'
42+
- 'CONTRIBUTING.md'
43+
- 'MAINTAINERS.md'
44+
45+
# Test related changes
46+
area/testing:
47+
- changed-files:
48+
- any-glob-to-any-file:
49+
- '**/*_test.go'
50+
- '**/test/**/*'
51+
- 'testing/**/*'
52+
- 'e2e-test/**/*'
53+
54+
# CI/CD and workflow changes
55+
area/ci:
56+
- changed-files:
57+
- any-glob-to-any-file:
58+
- '.github/**/*'
59+
- 'Makefile'
60+
- '**/Makefile'
61+
- '**/*.yaml'
62+
- '**/*.yml'
63+
- 'Dockerfile*'
64+
- '**/Dockerfile*'
65+
66+
# Dependencies
67+
area/dependencies:
68+
- changed-files:
69+
- any-glob-to-any-file:
70+
- 'go.mod'
71+
- 'go.sum'
72+
- '**/go.mod'
73+
- '**/go.sum'
74+
75+
# Language specific labels
76+
language/go:
77+
- changed-files:
78+
- any-glob-to-any-file: '**/*.go'
79+
80+
language/yaml:
81+
- changed-files:
82+
- any-glob-to-any-file:
83+
- '**/*.yaml'
84+
- '**/*.yml'
85+
86+
language/shell:
87+
- changed-files:
88+
- any-glob-to-any-file: '**/*.sh'
89+
90+
# Commit type labels based on branch names (conventional commits style)
91+
kind/feat:
92+
- head-branch: ['^feat/', '^feature/', 'feat-', 'feature-']
93+
94+
kind/fix:
95+
- head-branch: ['^fix/', '^bugfix/', 'fix-', 'bugfix-', 'hotfix/']
96+
97+
kind/chore:
98+
- head-branch: ['^chore/', 'chore-']
99+
100+
kind/docs:
101+
- head-branch: ['^docs/', '^doc/', 'docs-', 'doc-']
102+
103+
kind/ci:
104+
- head-branch: ['^ci/', 'ci-']
105+
106+
kind/refactor:
107+
- head-branch: ['^refactor/', 'refactor-']
108+
109+
enhancement:
110+
- head-branch: ['^enhancement/', '^enhance/', 'enhancement-', 'enhance-']
111+
112+
# Target branch labels
113+
release:
114+
- base-branch: 'main'
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: "Commit Message Labeler"
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, edited]
6+
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
11+
jobs:
12+
commit-labeler:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Assign Labels from Conventional Commits
21+
uses: actions/github-script@v7
22+
with:
23+
github-token: ${{ secrets.GITHUB_TOKEN }}
24+
script: |
25+
const { owner, repo, number } = context.issue;
26+
27+
// Get all commits in the PR
28+
const commits = await github.rest.pulls.listCommits({
29+
owner,
30+
repo,
31+
pull_number: number
32+
});
33+
34+
const commitTypes = new Set();
35+
36+
// Parse commit messages to extract types
37+
commits.data.forEach(commit => {
38+
const message = commit.commit.message;
39+
const match = message.match(/^(feat|feature|fix|bugfix|hotfix|chore|docs?|refactor|revert|enhancement|enhance)(?:\(.+\))?:/);
40+
if (match) {
41+
commitTypes.add(match[1]);
42+
}
43+
});
44+
45+
// Map commit types to labels
46+
const labelMap = {
47+
'feat': 'kind/feat',
48+
'feature': 'kind/feat',
49+
'fix': 'kind/fix',
50+
'bugfix': 'kind/fix',
51+
'hotfix': 'kind/fix',
52+
'chore': 'kind/chore',
53+
'docs': 'kind/docs',
54+
'doc': 'kind/docs',
55+
'refactor': 'kind/refactor',
56+
'revert': 'kind/revert',
57+
'enhancement': 'enhancement',
58+
'enhance': 'enhancement'
59+
};
60+
61+
// Apply labels based on commit types found
62+
for (const commitType of commitTypes) {
63+
const label = labelMap[commitType];
64+
if (label) {
65+
try {
66+
await github.rest.issues.addLabels({
67+
owner,
68+
repo,
69+
issue_number: number,
70+
labels: [label]
71+
});
72+
console.log(`Applied label: ${label} (from commit type: ${commitType})`);
73+
} catch (error) {
74+
console.error(`Failed to apply label ${label}:`, error.message);
75+
}
76+
}
77+
}
78+
79+
console.log(`Processed ${commits.data.length} commits, found types: ${Array.from(commitTypes).join(', ')}`);
80+
console.log(`Applied labels: ${Array.from(commitTypes).map(t => labelMap[t]).filter(Boolean).join(', ')}`);
81+
82+
return {
83+
commitTypes: Array.from(commitTypes),
84+
labelsApplied: Array.from(commitTypes).map(t => labelMap[t]).filter(Boolean)
85+
};

.github/workflows/labeler.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "Pull Request Labeler"
2+
3+
on:
4+
- pull_request_target
5+
6+
permissions:
7+
contents: read
8+
pull-requests: write
9+
10+
jobs:
11+
labeler:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Apply labels
15+
uses: actions/labeler@v5
16+
with:
17+
configuration-path: .github/labeler.yml
18+
repo-token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)