Skip to content

Commit 903dfb3

Browse files
committed
add auto pr labeller workflow
1 parent 6838811 commit 903dfb3

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

.github/workflows/pr-labels.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Manage labels based on PR body
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, reopened, synchronize]
6+
7+
jobs:
8+
manage-labels:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Analyze PR Body and manage labels
12+
run: |
13+
body="${{ github.event.pull_request.body }}"
14+
labels_to_add=()
15+
labels_to_remove=()
16+
declare -A label_checks=(
17+
["New feature"]="enhancement"
18+
["Bug fix|Hotfix|Security patch"]="bug"
19+
["Documentation update"]="documentation"
20+
["Refactoring"]="refactor"
21+
["UI/UX improvement"]="UI/UX"
22+
)
23+
for key in "${!label_checks[@]}"; do
24+
if echo "$body" | grep -q "\- \[x\] $key"; then
25+
labels_to_add+=("${label_checks[$key]}")
26+
else
27+
labels_to_remove+=("${label_checks[$key]}")
28+
fi
29+
done
30+
echo "LABELS_TO_ADD=${labels_to_add[*]}" >> $GITHUB_ENV
31+
echo "LABELS_TO_REMOVE=${labels_to_remove[*]}" >> $GITHUB_ENV
32+
- name: Add labels if necessary
33+
if: env.LABELS_TO_ADD != ''
34+
run: |
35+
for label in ${{ env.LABELS_TO_ADD }}; do
36+
curl -s -X POST \
37+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
38+
-H "Accept: application/vnd.github.v3+json" \
39+
-d "{\"labels\": [\"$label\"]}" \
40+
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels
41+
done
42+
- name: Remove labels if necessary
43+
if: env.LABELS_TO_REMOVE != ''
44+
run: |
45+
for label in ${{ env.LABELS_TO_REMOVE }}; do
46+
curl -s -X DELETE \
47+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
48+
-H "Accept: application/vnd.github.v3+json" \
49+
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/$label
50+
done

0 commit comments

Comments
 (0)