-
Notifications
You must be signed in to change notification settings - Fork 2
78 lines (64 loc) · 2.27 KB
/
Copy pathlabel-sync.yml
File metadata and controls
78 lines (64 loc) · 2.27 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Label PRs
on:
pull_request:
types: [opened, synchronize]
permissions:
contents: read
pull-requests: write
jobs:
label:
name: Auto-label by path
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Get changed files
id: changed
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# The files endpoint lists paths only. `gh pr diff --name-only` fetches the
# whole diff first and fails with HTTP 406 past 20,000 lines, which a
# full docs/gallery regeneration exceeds (#300).
run: |
FILES=$(gh api --paginate "repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" --jq '.[].filename')
echo "files<<EOF" >> "$GITHUB_OUTPUT"
echo "$FILES" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Apply labels
env:
FILES: ${{ steps.changed.outputs.files }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
LABELS=""
if echo "$FILES" | grep -q "^skills/"; then
LABELS="$LABELS skills"
fi
if echo "$FILES" | grep -q "^rules/"; then
LABELS="$LABELS rules"
fi
if echo "$FILES" | grep -q "^snippets/"; then
LABELS="$LABELS snippets"
fi
if echo "$FILES" | grep -q "^templates/"; then
LABELS="$LABELS templates"
fi
if echo "$FILES" | grep -q "^examples/"; then
LABELS="$LABELS examples"
fi
if echo "$FILES" | grep -q "^showcase/"; then
LABELS="$LABELS showcase"
fi
if echo "$FILES" | grep -qE "(README\.md|AGENTS\.md|CLAUDE\.md|ROADMAP\.md|CHANGELOG\.md|^docs/)"; then
LABELS="$LABELS documentation"
fi
if echo "$FILES" | grep -q "^\.github/"; then
LABELS="$LABELS ci"
fi
if [ -n "$LABELS" ]; then
for label in $LABELS; do
gh label create "$label" --force --color "ededed" 2>/dev/null || true
gh pr edit ${{ github.event.pull_request.number }} --add-label "$label"
done
echo "Applied labels:$LABELS"
else
echo "No labels to apply"
fi