-
Notifications
You must be signed in to change notification settings - Fork 194
66 lines (55 loc) · 2.14 KB
/
pullreq_size.yml
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
name: 'Label PR Based on Size'
on:
pull_request:
types: [opened, reopened, synchronize]
jobs:
label-pr-size:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up jq (for processing JSON)
run: sudo apt-get install jq
- name: Label PR based on size
run: |
XS_LIMIT=10
SM_LIMIT=50
MD_LIMIT=200
LG_LIMIT=500
LABEL_XS="size-xs"
LABEL_SM="size-sm"
LABEL_MD="size-md"
LABEL_LG="size-lg"
LABEL_XL="size-xl"
GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}"
GITHUB_REPOSITORY="${{ github.repository }}"
PR_NUMBER="${{ github.event.pull_request.number }}"
API_URI="https://api.github.com"
API_HEADER="Accept: application/vnd.github.v3+json"
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
# Function to calculate total lines added and deleted
additions=$(curl -sSL -H "$API_HEADER" -H "$AUTH_HEADER" \
"${API_URI}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" | jq '.additions')
deletions=$(curl -sSL -H "$API_HEADER" -H "$AUTH_HEADER" \
"${API_URI}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" | jq '.deletions')
total_modifications=$((additions + deletions))
# Determine the label based on total changes
if [ "$total_modifications" -lt "$XS_LIMIT" ]; then
label="$LABEL_XS"
elif [ "$total_modifications" -lt "$SM_LIMIT" ]; then
label="$LABEL_SM"
elif [ "$total_modifications" -lt "$MD_LIMIT" ]; then
label="$LABEL_MD"
elif [ "$total_modifications" -lt "$LG_LIMIT" ]; then
label="$LABEL_LG"
else
label="$LABEL_XL"
fi
# Apply the label
curl -sSL -H "$API_HEADER" -H "$AUTH_HEADER" -X POST -d "{\"labels\":[\"$label\"]}" \
"${API_URI}/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/labels"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}