Skip to content

Commit eec02a6

Browse files
authored
Simplify changelog assist to reminder-only
Remove slash commands and recheck plumbing. GITHUB_TOKEN cannot apply labels in a way that re-triggers required pull_request checks; UI label changes fire labeled events and changelog-label-check reruns reliably. Keep sticky reminder posting and removal on pull_request_target only.
1 parent 2514851 commit eec02a6

3 files changed

Lines changed: 12 additions & 122 deletions

File tree

.github/pull_request_template.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030

3131
## Does this code need a note in the changelog?
32-
<!-- Comment `/needs-changelog` or `/no-changelog` on this PR (author or collaborator). Maintainers may also set those labels in the GitHub UI. -->
33-
<!-- If `/needs-changelog`, add a release-note entry under `## Changelog` below. If `/no-changelog`, add a brief explanation there of why no release note is needed. Merge requires exactly one label — not changelog text in the description. -->
32+
<!-- Set the `needs-changelog` or `no-changelog` label on this PR in the GitHub labels panel. -->
33+
<!-- If `needs-changelog`, add a release-note entry under `## Changelog` below. If `no-changelog`, add a brief explanation there of why no release note is needed. Merge requires exactly one label — not changelog text in the description. -->
3434

3535

3636
## Changelog
Lines changed: 8 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Remind PR authors to set a changelog label and apply labels from slash commands.
1+
# Post a sticky reminder when a PR is missing a changelog label.
22
#
33
# Labels: needs-changelog (user-facing change; add release note in PR description)
44
# no-changelog (no release note needed)
55
#
6-
# PR authors and collaborators may comment /needs-changelog or /no-changelog on the PR.
7-
# changelog-label-check.yml enforces exactly one of these labels before merge.
6+
# Authors set one of those labels in the GitHub UI (or maintainers do). That fires
7+
# pull_request labeled events and changelog-label-check.yml re-runs automatically.
88
name: Changelog label assist
99

1010
on:
@@ -13,21 +13,12 @@ on:
1313
branches:
1414
- master
1515
- stable/v**
16-
issue_comment:
17-
types: [created]
1816

1917
permissions:
20-
actions: write
2118
pull-requests: write
22-
issues: write
2319

2420
concurrency:
25-
group: >-
26-
${{
27-
github.event_name == 'pull_request_target'
28-
&& format('changelog-label-pr-{0}', github.event.pull_request.number)
29-
|| format('changelog-label-comment-{0}', github.event.issue.number)
30-
}}
21+
group: changelog-label-pr-${{ github.event.pull_request.number }}
3122
cancel-in-progress: true
3223

3324
jobs:
@@ -40,9 +31,8 @@ jobs:
4031
with:
4132
egress-policy: audit
4233

43-
- name: Resolve changelog label state (PR events)
34+
- name: Resolve changelog label state
4435
id: pr_labels
45-
if: github.event_name == 'pull_request_target'
4636
env:
4737
GH_TOKEN: ${{ github.token }}
4838
PR_NUMBER: ${{ github.event.pull_request.number }}
@@ -70,7 +60,7 @@ jobs:
7060
fi
7161
7262
- name: Post sticky changelog reminder
73-
if: github.event_name == 'pull_request_target' && steps.pr_labels.outputs.show_reminder == 'true'
63+
if: steps.pr_labels.outputs.show_reminder == 'true'
7464
uses: marocchino/sticky-pull-request-comment@0ea0beb66eb9baf113663a64ec522f60e49231c0 # v3.0.4
7565
with:
7666
header: changelog-label
@@ -83,113 +73,14 @@ jobs:
8373
- **`needs-changelog`** — user-facing change; add a release-note entry in the PR description (e.g. under a `## Changelog` section)
8474
- **`no-changelog`** — no release note needed; please add a brief rationale in the PR description (e.g. under the changelog question in the PR template)
8575
86-
**PR author or collaborator:** comment on this PR with one of:
87-
88-
- `/needs-changelog`
89-
- `/no-changelog`
90-
91-
Maintainers may also set `needs-changelog` or `no-changelog` in the GitHub UI.
76+
Set **`needs-changelog`** or **`no-changelog`** on this PR in the GitHub labels panel (right sidebar). That re-runs the required **Changelog label validation** check automatically.
9277
9378
Merge is blocked only until one of these labels is set — release note or rationale text in the PR description is encouraged but not required to merge.
9479
9580
- name: Remove sticky changelog reminder
96-
if: github.event_name == 'pull_request_target' && steps.pr_labels.outputs.show_reminder == 'false'
81+
if: steps.pr_labels.outputs.show_reminder == 'false'
9782
uses: marocchino/sticky-pull-request-comment@0ea0beb66eb9baf113663a64ec522f60e49231c0 # v3.0.4
9883
with:
9984
header: changelog-label
10085
number: ${{ github.event.pull_request.number }}
10186
delete: true
102-
103-
- name: Apply changelog label from slash command
104-
id: slash_command
105-
if: github.event_name == 'issue_comment' && github.event.issue.pull_request
106-
env:
107-
GH_TOKEN: ${{ github.token }}
108-
COMMENT_BODY: ${{ github.event.comment.body }}
109-
COMMENT_USER: ${{ github.event.comment.user.login }}
110-
AUTHOR_ASSOCIATION: ${{ github.event.comment.author_association }}
111-
ISSUE_NUMBER: ${{ github.event.issue.number }}
112-
run: |
113-
set -euo pipefail
114-
115-
repo="${{ github.repository }}"
116-
pr="${ISSUE_NUMBER}"
117-
118-
base_ref="$(gh api "repos/${repo}/pulls/${pr}" --jq '.base.ref')"
119-
if [[ "$base_ref" != "master" && ! "$base_ref" =~ ^stable/v ]]; then
120-
echo "PR base '${base_ref}' is not master or stable/v*; skipping."
121-
exit 0
122-
fi
123-
124-
chosen=""
125-
while IFS= read -r line || [[ -n "$line" ]]; do
126-
line="${line%%$'\r'}"
127-
if [[ "$line" =~ ^/needs-changelog([[:space:]]|$) ]]; then
128-
chosen=needs-changelog
129-
break
130-
elif [[ "$line" =~ ^/no-changelog([[:space:]]|$) ]]; then
131-
chosen=no-changelog
132-
break
133-
fi
134-
done <<< "${COMMENT_BODY:-}"
135-
136-
if [[ -z "$chosen" ]]; then
137-
echo "No changelog slash command in comment; skipping."
138-
exit 0
139-
fi
140-
141-
pr_author="$(gh api "repos/${repo}/pulls/${pr}" --jq '.user.login')"
142-
allowed=false
143-
if [[ "$COMMENT_USER" == "$pr_author" ]]; then
144-
allowed=true
145-
fi
146-
case "${AUTHOR_ASSOCIATION:-NONE}" in
147-
OWNER|MEMBER|COLLABORATOR|MAINTAINER) allowed=true ;;
148-
esac
149-
150-
if [[ "$allowed" != true ]]; then
151-
gh api "repos/${repo}/issues/${pr}/comments" \
152-
-f body="Only the PR author or a collaborator can use \`/${chosen}\` to set the changelog label."
153-
exit 0
154-
fi
155-
156-
if [[ "$chosen" == "needs-changelog" ]]; then
157-
other=no-changelog
158-
else
159-
other=needs-changelog
160-
fi
161-
162-
gh api -X POST "repos/${repo}/issues/${pr}/labels" -f "labels[]=${chosen}"
163-
gh api -X DELETE "repos/${repo}/issues/${pr}/labels/${other}" --silent 2>/dev/null || true
164-
165-
if [[ "$chosen" == "needs-changelog" ]]; then
166-
ack="Applied label \`needs-changelog\`. Please add a release-note entry in the PR description (e.g. under a \`## Changelog\` section). Merge is not blocked on this — only the label is required."
167-
else
168-
ack="Applied label \`no-changelog\`. Please add a brief note in the PR description explaining why a release note is not needed (e.g. under the changelog question in the PR template). Merge is not blocked on this — only the label is required."
169-
fi
170-
gh api "repos/${repo}/issues/${pr}/comments" -f "body=${ack}"
171-
172-
# Sticky removal must proceed even if the recheck below fails.
173-
echo "applied=true" >> "$GITHUB_OUTPUT"
174-
175-
# GITHUB_TOKEN label changes do not re-trigger pull_request workflows; rerun the PR check (best-effort).
176-
run_id=""
177-
page=1
178-
while [[ -z "${run_id}" && "${page}" -le 10 ]]; do
179-
run_id="$(gh api "repos/${repo}/actions/workflows/changelog-label-check.yml/runs?per_page=100&page=${page}&event=pull_request" \
180-
--jq ".workflow_runs[] | select(any(.pull_requests[]?; .number == ${pr})) | .id" 2>/dev/null | head -1)" || true
181-
page=$((page + 1))
182-
done
183-
if [[ -n "${run_id}" ]]; then
184-
gh run rerun "${run_id}" || echo "::warning::Failed to rerun changelog-label-check run ${run_id} for PR ${pr}"
185-
else
186-
echo "::warning::No pull_request changelog-label-check run found for PR ${pr}; merge gate may need a manual re-run."
187-
fi
188-
189-
- name: Remove sticky changelog reminder after slash command
190-
if: github.event_name == 'issue_comment' && steps.slash_command.outputs.applied == 'true'
191-
uses: marocchino/sticky-pull-request-comment@0ea0beb66eb9baf113663a64ec522f60e49231c0 # v3.0.4
192-
with:
193-
header: changelog-label
194-
number: ${{ github.event.issue.number }}
195-
delete: true

.github/workflows/changelog-label-check.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@ jobs:
4848
4949
if [[ "$has_needs" == true && "$has_no" == true ]]; then
5050
echo "::error::PR has both \`needs-changelog\` and \`no-changelog\` labels. Remove one so exactly one remains."
51-
echo "::error::Comment on this PR with \`/needs-changelog\` or \`/no-changelog\` (PR author or collaborator), or edit labels in the GitHub UI."
51+
echo "::error::Edit labels on this PR in the GitHub UI so only one changelog label remains."
5252
exit 1
5353
fi
5454
5555
if [[ "$has_needs" == false && "$has_no" == false ]]; then
5656
echo "::error::PR is missing a changelog label. Add exactly one: \`needs-changelog\` or \`no-changelog\`."
57-
echo "::error::Comment on this PR with \`/needs-changelog\` (user-facing change; add a release note in the PR description) or \`/no-changelog\` (no release note needed; add a brief rationale in the PR description)."
58-
echo "::error::PR author and collaborators can use those slash commands; maintainers may also set labels in the GitHub UI."
57+
echo "::error::Set \`needs-changelog\` (user-facing change; add a release note in the PR description) or \`no-changelog\` (no release note needed; add a brief rationale in the PR description) in the GitHub labels panel."
5958
exit 1
6059
fi
6160

0 commit comments

Comments
 (0)