Repository navigation
61 lines (51 loc) · 1.74 KB
/
Copy pathlabel-sync.yml
File metadata and controls
61 lines (51 loc) · 1.74 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
name: Label PRs
on:
pull_request:
types: [opened, synchronize]
permissions: {}
jobs:
label:
name: Auto-label by path
runs-on: ubuntu-latest
# Fork PRs get a read-only token, so labeling cannot succeed there.
if: github.event.pull_request.head.repo.full_name == github.repository
permissions:
contents: read
pull-requests: write
steps:
- name: Apply labels by changed path
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
FILES="$(gh pr diff "$PR_NUMBER" --name-only)"
LABELS=""
if echo "$FILES" | grep -q "^standards/"; then
LABELS="$LABELS standards"
fi
if echo "$FILES" | grep -q "^scaffold/"; then
LABELS="$LABELS scaffold"
fi
if echo "$FILES" | grep -q "^docs/"; then
LABELS="$LABELS documentation"
fi
if echo "$FILES" | grep -q "^registry.json"; then
LABELS="$LABELS registry"
fi
if echo "$FILES" | grep -q "^\.github/"; then
LABELS="$LABELS ci"
fi
if [ -z "$LABELS" ]; then
echo "No labels to apply"
exit 0
fi
EXISTING="$(gh label list --limit 200 --json name --jq '.[].name')"
for label in $LABELS; do
# Create only when missing, so existing label colors are kept.
if ! printf '%s\n' "$EXISTING" | grep -qx "$label"; then
gh label create "$label" --color "ededed" || true
fi
gh pr edit "$PR_NUMBER" --add-label "$label"
done
echo "Applied labels:$LABELS"