-
Notifications
You must be signed in to change notification settings - Fork 3
74 lines (62 loc) · 2.6 KB
/
pr-size-labeler.yml
File metadata and controls
74 lines (62 loc) · 2.6 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
name: PR Size Labeler - Calculate
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
jobs:
calculate-pr-size:
name: Calculate PR Size
runs-on: ubuntu-latest
steps:
- name: Get PR details
id: pr
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const additions = pr.data.additions;
const deletions = pr.data.deletions;
const totalChanges = additions + deletions;
console.log(`PR #${context.issue.number}: +${additions} -${deletions} (${totalChanges} total)`);
return {
additions: additions,
deletions: deletions,
total: totalChanges
};
- name: Determine size label
id: size
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
script: |
const changes = ${{ steps.pr.outputs.result }};
const total = changes.total;
let sizeLabel = '';
if (total < 100) {
sizeLabel = 'size/XS';
} else if (total < 300) {
sizeLabel = 'size/S';
} else if (total < 600) {
sizeLabel = 'size/M';
} else if (total < 1000) {
sizeLabel = 'size/L';
} else {
sizeLabel = 'size/XL';
}
console.log(`PR size: ${total} lines -> ${sizeLabel}`);
return sizeLabel;
- name: Save size label to artifact
run: |
mkdir -p pr-size
echo "${{ steps.size.outputs.result }}" > pr-size/label.txt
echo "${{ github.event.pull_request.number }}" > pr-size/pr-number.txt
- name: Upload artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: pr-size-label
path: pr-size/
retention-days: 1