1
1
name : Manage labels based on PR body
2
2
3
3
on :
4
- pull_request :
4
+ pull_request_target :
5
5
types : [opened, edited, reopened, synchronize]
6
6
7
7
jobs :
8
8
manage-labels :
9
9
runs-on : ubuntu-latest
10
10
steps :
11
11
- name : Analyze PR Body and manage labels
12
+ shell : bash
12
13
run : |
13
- body="${{ github.event. pull_request.body }}"
14
+ body=$(jq -r '. pull_request.body' "$GITHUB_EVENT_PATH")
14
15
labels_to_add=()
15
16
labels_to_remove=()
16
17
declare -A label_checks=(
@@ -20,19 +21,23 @@ jobs:
20
21
["Refactoring"]="refactor"
21
22
["UI/UX improvement"]="UI/UX"
22
23
)
23
- for key in "${!label_checks[@]}"; do
24
- if echo "$body" | grep -q "\- \[x\] $key"; then
25
- labels_to_add+=("${label_checks[$key]}")
24
+ for pattern in "${!label_checks[@]}"; do
25
+ label="${label_checks[$pattern]}"
26
+ if echo "$body" | grep -Eq "\- \[x\] ($pattern)"; then
27
+ labels_to_add+=("$label")
26
28
else
27
- labels_to_remove+=("${label_checks[$key]} ")
29
+ labels_to_remove+=("$label ")
28
30
fi
29
31
done
30
- echo "LABELS_TO_ADD=${labels_to_add[*]}" >> $GITHUB_ENV
31
- echo "LABELS_TO_REMOVE=${labels_to_remove[*]}" >> $GITHUB_ENV
32
+
33
+ echo "LABELS_TO_ADD=$(IFS=,; echo "${labels_to_add[*]}")" >> $GITHUB_ENV
34
+ echo "LABELS_TO_REMOVE=$(IFS=,; echo "${labels_to_remove[*]}")" >> $GITHUB_ENV
35
+
32
36
- name : Add labels if necessary
33
37
if : env.LABELS_TO_ADD != ''
34
38
run : |
35
- for label in ${{ env.LABELS_TO_ADD }}; do
39
+ IFS=',' read -ra labels <<< "${LABELS_TO_ADD}"
40
+ for label in "${labels[@]}"; do
36
41
curl -s -X POST \
37
42
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
38
43
-H "Accept: application/vnd.github.v3+json" \
42
47
- name : Remove labels if necessary
43
48
if : env.LABELS_TO_REMOVE != ''
44
49
run : |
45
- for label in ${{ env.LABELS_TO_REMOVE }}; do
50
+ IFS=',' read -ra labels <<< "${LABELS_TO_REMOVE}"
51
+ for label in "${labels[@]}"; do
46
52
curl -s -X DELETE \
47
53
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
48
54
-H "Accept: application/vnd.github.v3+json" \
49
55
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/$label
50
- done
56
+ done
0 commit comments