-
Notifications
You must be signed in to change notification settings - Fork 241
61 lines (54 loc) · 1.68 KB
/
Copy pathlabels-verify.yml
File metadata and controls
61 lines (54 loc) · 1.68 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: "Verify PR labels"
on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
- labeled
- unlabeled
- edited
permissions:
contents: read
pull-requests: read
issues: read
jobs:
triage:
name: Require exactly one pr label
runs-on: ubuntu-latest
steps:
- name: Validate release notes label
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
shell: bash
run: |
labels="$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/labels" --jq '.[].name')"
pr_labels="$(printf '%s\n' "${labels}" | grep '^pr:' || true)"
if [ -z "${pr_labels}" ]; then
count=0
else
count="$(printf '%s\n' "${pr_labels}" | wc -l | tr -d ' ')"
fi
if [ "${count}" -eq 1 ]; then
echo "Found PR release-note label: ${pr_labels}"
exit 0
fi
{
echo "Pull requests must have exactly one label with the pr: prefix."
echo "Found ${count} pr: labels."
if [ "${count}" -gt 0 ]; then
printf 'Matching labels:\n'
printf '%s\n' "${pr_labels}" | sed 's/^/- /'
fi
echo
echo "Available labels on this PR:"
if [ -n "${labels}" ]; then
printf '%s\n' "${labels}" | sed 's/^/- /'
else
echo "- <none>"
fi
} >> "${GITHUB_STEP_SUMMARY}"
echo "::error title=Invalid pr: label count::Pull requests must have exactly one label with the pr: prefix. Found ${count}."
exit 1