-
Notifications
You must be signed in to change notification settings - Fork 3
84 lines (71 loc) · 3.04 KB
/
pr-labeler.yml
File metadata and controls
84 lines (71 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: PR Labeler
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
label:
name: Auto Label PR
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Label based on files
uses: actions/labeler@v5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
configuration-path: .github/labeler.yml
- name: Label based on PR title
uses: actions/github-script@v7
with:
script: |
const title = context.payload.pull_request.title.toLowerCase();
const labels = [];
// Check PR title prefix
if (title.startsWith('feat')) labels.push('feature');
if (title.startsWith('fix')) labels.push('bug');
if (title.startsWith('docs')) labels.push('documentation');
if (title.startsWith('refactor')) labels.push('refactor');
if (title.startsWith('test')) labels.push('testing');
if (title.startsWith('chore')) labels.push('chore');
if (title.startsWith('perf')) labels.push('performance');
// Add size labels based on changes
const { data: files } = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number
});
const changes = files.reduce((sum, file) => sum + file.changes, 0);
if (changes < 50) labels.push('size/small');
else if (changes < 200) labels.push('size/medium');
else labels.push('size/large');
// Add labels to PR
if (labels.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: labels
});
}
- name: Check PR description
uses: actions/github-script@v7
with:
script: |
const body = context.payload.pull_request.body || '';
if (body.length < 50) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: ['needs-description']
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: 'This PR needs a more detailed description. Please add:\n\n- What changes were made\n- Why these changes were necessary\n- How to test the changes\n\nRefer to our [Contributing Guidelines](../CONTRIBUTING.md) for more details.'
});
}