-
Notifications
You must be signed in to change notification settings - Fork 41
38 lines (34 loc) · 1.34 KB
/
size.yaml
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
name: Pull request size
on: pull_request_target
jobs:
size-label:
name: Size label
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Calculate size
run: |
#!/usr/bin/bash
set -euo pipefail
additions=$(curl -s "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" | jq '.additions')
deletions=$(curl -s "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" | jq '.deletions')
size=$((additions + deletions))
sizelabel=XS
if [ ${size} -gt 600 ]; then
sizelabel="XXL"
elif [ ${size} -gt 240 ]; then
sizelabel="XL"
elif [ ${size} -gt 120 ]; then
sizelabel="L"
elif [ ${size} -gt 60 ]; then
sizelabel="M"
elif [ ${size} -gt 35 ]; then
sizelabel="S"
fi
echo "Adding size: ${sizelabel}"
curl -s --fail-with-body -X POST -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \
-d "[\"size: ${sizelabel}\"]"