-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (72 loc) · 2.51 KB
/
labeler.yml
File metadata and controls
83 lines (72 loc) · 2.51 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
name: Auto Label PRs
on:
pull_request_target:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
jobs:
label:
name: Label PR
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Auto-label based on changed files
uses: actions/labeler@v5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
configuration-path: .github/labeler.yml
sync-labels: false
- name: Add size label
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = context.payload.pull_request;
const additions = pr.additions;
const deletions = pr.deletions;
const totalChanges = additions + deletions;
// Calculate size category
let sizeLabel = '';
if (totalChanges < 10) {
sizeLabel = 'size: XS';
} else if (totalChanges < 50) {
sizeLabel = 'size: S';
} else if (totalChanges < 200) {
sizeLabel = 'size: M';
} else if (totalChanges < 500) {
sizeLabel = 'size: L';
} else if (totalChanges < 1000) {
sizeLabel = 'size: XL';
} else {
sizeLabel = 'size: XXL';
}
// Remove old size labels
const currentLabels = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number
});
const sizeLabels = currentLabels.data
.map(label => label.name)
.filter(name => name.startsWith('size: '));
for (const label of sizeLabels) {
if (label !== sizeLabel) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
name: label
});
}
}
// Add new size label
if (!sizeLabels.includes(sizeLabel)) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: [sizeLabel]
});
}
console.log(`PR #${pr.number}: +${additions} -${deletions} = ${totalChanges} changes → ${sizeLabel}`);