-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (48 loc) · 1.77 KB
/
label.yml
File metadata and controls
60 lines (48 loc) · 1.77 KB
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
name: Label
on:
pull_request:
types: [opened, reopened, synchronize]
jobs:
label:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Label PR
run: |
PR=${{ github.event.pull_request.number }}
changed_files=$(gh api "repos/${{ github.repository }}/pulls/$PR/files" --paginate -q '.[].filename')
current_labels=$(gh pr view $PR --json labels -q '.labels[].name')
add_label() {
gh label create "$1" --color "0075ca" 2>/dev/null || true
gh pr edit $PR --add-label "$1"
}
remove_label_if_exists() {
if echo "$current_labels" | grep -qF "$1"; then
gh pr edit $PR --remove-label "$1"
fi
}
remove_label_if_exists "🥐 Crew"
remove_label_if_exists "⚡️ Playground"
remove_label_if_exists "🔗 Root"
remove_label_if_exists "🔗 Workflows"
echo "$current_labels" | grep "^🔗 Packages:" | while read -r label; do
gh pr edit $PR --remove-label "$label"
done
if echo "$changed_files" | grep -q "^apps/crew/"; then
add_label "🥐 Crew"
fi
if echo "$changed_files" | grep -q "^apps/playground/"; then
add_label "⚡️ Playground"
fi
if echo "$changed_files" | grep -qE "^[^/]+$|^\.github/"; then
add_label "🔗 Root"
fi
changed_packages=$(echo "$changed_files" | grep "^packages/" | awk -F'/' '{print $2}' | sort -u)
for pkg in $changed_packages; do
add_label "🔗 Packages:$pkg"
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}