-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
55 lines (48 loc) · 1.93 KB
/
pr-labels.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
55
name: Manage labels based on PR body
on:
pull_request:
types: [opened, edited, reopened, synchronize]
jobs:
manage-labels:
runs-on: ubuntu-latest
steps:
- name: Analyze PR Body and manage labels
run: |
body="${{ github.event.pull_request.body }}"
labels_to_add=()
labels_to_remove=()
declare -A label_checks=(
["New feature"]="enhancement"
["Bug fix|Hotfix|Security patch"]="bug"
["Documentation update"]="documentation"
["Refactoring"]="refactor"
["UI/UX improvement"]="UI/UX"
)
for key in "${!label_checks[@]}"; do
if echo "$body" | grep -q "\- \[x\] $key"; then
labels_to_add+=("${label_checks[$key]}")
else
labels_to_remove+=("${label_checks[$key]}")
fi
done
echo "LABELS_TO_ADD=${labels_to_add[*]}" >> $GITHUB_ENV
echo "LABELS_TO_REMOVE=${labels_to_remove[*]}" >> $GITHUB_ENV
- name: Add labels if necessary
if: env.LABELS_TO_ADD != ''
run: |
for label in ${{ env.LABELS_TO_ADD }}; do
curl -s -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"labels\": [\"$label\"]}" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels
done
- name: Remove labels if necessary
if: env.LABELS_TO_REMOVE != ''
run: |
for label in ${{ env.LABELS_TO_REMOVE }}; do
curl -s -X DELETE \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/$label
done