-
Notifications
You must be signed in to change notification settings - Fork 34
54 lines (44 loc) · 1.75 KB
/
pr_size_labeler.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: "PR Size Labeler"
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
label:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get PR Size
id: get_pr_size
run: |
CHANGED_FILES=$(jq '.pull_request.changed_files' $GITHUB_EVENT_PATH)
ADDITIONS=$(jq '.pull_request.additions' $GITHUB_EVENT_PATH)
DELETIONS=$(jq '.pull_request.deletions' $GITHUB_EVENT_PATH)
echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV
echo "ADDITIONS=$ADDITIONS" >> $GITHUB_ENV
echo "DELETIONS=$DELETIONS" >> $GITHUB_ENV
# OBS that we are cuurently not on a stable version, thus major is disabled for now
- name: Apply Labels Based on Size
if: ${{ github.event.pull_request.changed_files != '' }}
run: |
PATCH_THRESHOLD=10
MINOR_THRESHOLD=500
MAJOR_THRESHOLD=1000
TOTAL_CHANGES=$(($ADDITIONS + $DELETIONS))
echo "Total changes: $TOTAL_CHANGES"
if [ "$TOTAL_CHANGES" -le "$PATCH_THRESHOLD" ]; then
LABEL="patch"
elif [ "$TOTAL_CHANGES" -le "$MINOR_THRESHOLD" ]; then
LABEL="minor"
else
LABEL="minor"
fi
echo "Applying label: $LABEL"
curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \
-d "{\"labels\":[\"$LABEL\"]}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ADDITIONS: ${{ env.ADDITIONS }}
DELETIONS: ${{ env.DELETIONS }}