|
1 | | -name: "Verify type labels" |
| 1 | +name: "Verify PR labels" |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request_target: |
5 | | - types: [opened, labeled, unlabeled, synchronize] |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - reopened |
| 8 | + - synchronize |
| 9 | + - ready_for_review |
| 10 | + - labeled |
| 11 | + - unlabeled |
| 12 | + - edited |
6 | 13 |
|
7 | 14 | permissions: |
8 | | - contents: none |
| 15 | + contents: read |
| 16 | + pull-requests: read |
| 17 | + issues: read |
9 | 18 |
|
10 | 19 | jobs: |
11 | 20 | triage: |
| 21 | + name: Require exactly one pr label |
12 | 22 | runs-on: ubuntu-latest |
13 | | - permissions: |
14 | | - pull-requests: read |
15 | 23 | steps: |
16 | | - - uses: baev/action-label-verify@main |
17 | | - with: |
18 | | - repo-token: ${{ secrets.GITHUB_TOKEN }} |
19 | | - allowed: | |
20 | | - type:bug |
21 | | - type:dependencies |
22 | | - type:improvement |
23 | | - type:internal |
24 | | - type:invalid |
25 | | - type:new feature |
26 | | - type:security |
27 | | - type:documentation |
| 24 | + - name: Validate release notes label |
| 25 | + env: |
| 26 | + GH_TOKEN: ${{ github.token }} |
| 27 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 28 | + shell: bash |
| 29 | + run: | |
| 30 | + labels="$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/labels" --jq '.[].name')" |
| 31 | + pr_labels="$(printf '%s\n' "${labels}" | grep '^pr:' || true)" |
| 32 | +
|
| 33 | + if [ -z "${pr_labels}" ]; then |
| 34 | + count=0 |
| 35 | + else |
| 36 | + count="$(printf '%s\n' "${pr_labels}" | wc -l | tr -d ' ')" |
| 37 | + fi |
| 38 | +
|
| 39 | + if [ "${count}" -eq 1 ]; then |
| 40 | + echo "Found PR release-note label: ${pr_labels}" |
| 41 | + exit 0 |
| 42 | + fi |
| 43 | +
|
| 44 | + { |
| 45 | + echo "Pull requests must have exactly one label with the pr: prefix." |
| 46 | + echo "Found ${count} pr: labels." |
| 47 | + if [ "${count}" -gt 0 ]; then |
| 48 | + printf 'Matching labels:\n' |
| 49 | + printf '%s\n' "${pr_labels}" | sed 's/^/- /' |
| 50 | + fi |
| 51 | + echo |
| 52 | + echo "Available labels on this PR:" |
| 53 | + if [ -n "${labels}" ]; then |
| 54 | + printf '%s\n' "${labels}" | sed 's/^/- /' |
| 55 | + else |
| 56 | + echo "- <none>" |
| 57 | + fi |
| 58 | + } >> "${GITHUB_STEP_SUMMARY}" |
| 59 | +
|
| 60 | + echo "::error title=Invalid pr: label count::Pull requests must have exactly one label with the pr: prefix. Found ${count}." |
| 61 | + exit 1 |
0 commit comments