Repository navigation
feat(discord): add live CI check status and PR state tracking to embed - #614
Conversation
Enhance the Discord PR notification workflow to update a single embed message throughout the PR lifecycle instead of posting once on open. Tracks PR state (open/draft/closed/merged), labels, assignees, reviewers, and live CI check results by reacting to pull_request and check_run events. Uses a hidden PR comment to store the Discord message ID for subsequent PATCH updates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/discord-pr.yml:
- Around line 91-105: The current finalization logic overwrites a skipped-only
summary with "✅ All 0 passed" because the if block only checks FAILING and
PENDING; update the condition in the CHECKS_FIELD finalization so it only sets
"✅ All $PASSING passed" when PASSING is greater than zero (e.g., require PASSING
-gt 0 in the if), or alternatively preserve/emit a skipped-only message when
PASSING is zero and SKIPPED is greater than zero; adjust the conditional that
sets CHECKS_FIELD (the block referencing CHECKS_FIELD and variables PASSING,
FAILING, PENDING, SKIPPED) accordingly.
- Around line 143-167: The upsert has a TOCTOU race: multiple runners can miss
the marker and each create a Discord message and comment; fix by making the
write idempotent—after you create a Discord message and post the gh api POST
comment (the block that sets RESPONSE, DISCORD_MSG_ID and calls gh api POST -f
body="<!-- discord-msg-id:${DISCORD_MSG_ID} -->"), immediately re-query COMMENTS
(same query that builds COMMENTS and DISCORD_MSG_ID) to check if another runner
already wrote a marker; if you detect an existing marker with a different id,
delete the newly created Discord message (use the same webhook/message DELETE or
PATCH to remove it) and adopt the existing marker's id instead; update the logic
around DISCORD_MSG_ID, RESPONSE and the gh api POST to perform this
re-check-and-resolve step so only one persistent discord-msg-id remains.
- Around line 28-35: The workflow step "Resolve PR, build embed, post or patch
Discord" should bail out early when DISCORD_WEBHOOK_URL
(secrets.DISCORD_PR_WEBHOOK_URL) is empty: before you parse
WEBHOOK_ID/WEBHOOK_TOKEN or call curl, check that the DISCORD_WEBHOOK_URL env
var is non-empty and if it is empty print a clear message and exit 0 (or skip
the step) to avoid parsing an empty string and failing the curl; update the
shell script in that step to perform this guard and return early rather than
continuing with WEBHOOK_ID/WEBHOOK_TOKEN extraction.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 2ba1f4ad-0da5-484b-8620-6619ab1c9aa4
📒 Files selected for processing (1)
.github/workflows/discord-pr.yml
…essages Strip HTML comments, convert GitHub checkboxes to unicode, and turn markdown headings into Discord bold. If the stored Discord message was deleted (PATCH returns 404), clean up the stale comment and re-post. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/discord-pr.yml:
- Around line 144-149: The current selector accepts any comment containing
"discord-msg-id:" and can pick up user comments; update the COMMENTS ->
DISCORD_MSG_ID extraction so it only considers bot-authored hidden marker
comments: when calling gh api capture id, body and user.login into COMMENTS,
then change the jq/filter that builds DISCORD_MSG_ID to select objects where
.user.login == "github-actions[bot]" and .body exactly matches the hidden
comment format (e.g. a regex like '^<!-- discord-msg-id:[0-9]+ -->$'), then
extract the numeric id; adjust the pipeline that assigns DISCORD_MSG_ID to use
that stricter jq selection instead of a plain contains() grep.
- Around line 18-19: The workflow currently uses the check_run trigger which
GitHub suppresses for Actions-created check suites; update the trigger to a
supported one such as workflow_run (or another appropriate event) so that this
workflow observes completed CI runs—replace the check_run: types: [completed]
stanza with a workflow_run: types: [completed] (or add workflow_run alongside
check_run) in the .github/workflows/discord-pr.yml so the workflow refreshes
when the CI workflow finishes.
- Around line 21-23: The workflow's permissions block currently grants contents:
read and pull-requests: write but omits checks, causing the GET
/repos/$REPO/commits/$HEAD_SHA/check-runs call (the check-runs API used later)
to fail for non-public repos; update the permissions block in
.github/workflows/discord-pr.yml to include checks: read so the job can call the
check-runs endpoint successfully (modify the existing permissions mapping where
contents and pull-requests are set).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: e66844fa-0329-461e-b5c3-3929450a9b60
📒 Files selected for processing (1)
.github/workflows/discord-pr.yml
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/discord-pr.yml:
- Line 122: The sed invocation that rewrites BODY uses the ERE quantifier
`{1,6}` but calls sed in BRE mode; update the sed command that processes BODY
(the line assigning BODY=$(echo "$BODY" | sed 's/^#{1,6} \(.*\)$/\n**\1**/g'))
to run sed in ERE mode (add the -E flag) so the `{1,6}` quantifier is
interpreted correctly on GNU sed/Ubuntu runners.
- Around line 171-176: When deleting the stale GitHub comment (the gh api -X
DELETE call that uses STALE_COMMENT_ID when PATCH_STATUS == "404"), capture and
check the command's exit status and handle failures: if the DELETE fails, emit
an error log (e.g., echo with context including STALE_COMMENT_ID and the gh exit
code or output) and avoid blindly setting DISCORD_MSG_ID="" so you don't mask
the stale comment; optionally implement a simple retry (N attempts) before
giving up or set a flag to skip creating a new Discord message. Update the block
that references PATCH_STATUS, STALE_COMMENT_ID, gh api -X DELETE, and
DISCORD_MSG_ID to perform the check, log the failure, and only clear
DISCORD_MSG_ID when the DELETE succeeded.
- Line 116: The current sed command that assigns BODY (BODY=$(echo "$BODY" | sed
's/<!--[^>]*-->//g')) fails on multi-line comments and comments containing '>';
replace that pipeline so BODY is sanitized with a multiline-capable regex engine
(e.g., use Perl with the single-string flag and a non-greedy pattern like
/<!--.*?-->/s) to remove HTML comments robustly; update the assignment that sets
BODY to invoke Perl (or another multiline-aware tool) and ensure the command
operates on the full BODY variable and strips all <!-- ... --> spans safely.
- Around line 179-184: The current curl invocation using curl -f can abort the
step and leave the PR without a marker comment if the POST fails; modify the
block that sets RESPONSE and DISCORD_MSG_ID so you stop using -f and instead
capture both response body and HTTP status (e.g., curl -sS -w '%{http_code}' -o
/tmp/discord_body --header ... -d "$PAYLOAD"
"${DISCORD_WEBHOOK_URL}?wait=true"), then read STATUS from the curl output and
BODY from the file, set RESPONSE to BODY, and only fail after handling transient
statuses by implementing a small retry/backoff loop for 429 and 5xx codes;
ensure DISCORD_MSG_ID is extracted from the successful RESPONSE (jq -r '.id')
and that the step only gives up after retries so you don't leave the PR without
a marker comment.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: c7372ad4-2d5b-4579-9eee-9c8f4537a23f
📒 Files selected for processing (1)
.github/workflows/discord-pr.yml
The discord-msg-id comment was never stored/found because the issues API endpoint requires explicit `issues: write` permission. Also adds a concurrency group keyed on PR number to prevent duplicate messages from racing workflow runs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe GitHub Actions workflow now triggers on expanded pull_request events and check_run.completed, fetches live PR and check-run data, formats a rich Discord embed (status, labels, assignees, reviewers, checks), transforms the PR body, and updates or creates an idempotent Discord message recorded via a PR comment marker. Changes
Sequence DiagramsequenceDiagram
participant GH as GitHub Actions
participant API as GitHub API
participant Discord as Discord API
GH->>GH: Event received (pull_request or check_run.completed)
GH->>GH: Resolve PR number (payload or check_run.head_sha -> API lookup)
alt no PR found
GH->>GH: Exit early
end
GH->>API: GET PR details (title, body, author, refs, state, labels, assignees, reviewers)
GH->>API: GET check-runs for head SHA (paginated)
GH->>GH: Aggregate/deduplicate checks, compute status & embed color
GH->>GH: Transform PR body (truncate, repair fences, strip comments, format)
GH->>API: Search PR comments for discord-msg-id marker
alt marker found
GH->>Discord: PATCH /messages/{id} with embed
Discord-->>GH: 200 OK or 404 Not Found
alt 404
GH->>Discord: POST new message with embed
Discord-->>GH: Message created (ID)
GH->>API: POST PR comment with discord-msg-id
end
else marker not found
GH->>Discord: POST new message with embed
Discord-->>GH: Message created (ID)
GH->>API: POST PR comment with discord-msg-id
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
♻️ Duplicate comments (7)
.github/workflows/discord-pr.yml (7)
18-19:⚠️ Potential issue | 🟠 Major
check_runwill not refresh GitHub Actions-based CI.If the checks you want to surface are created by GitHub Actions, this event never fires, so the new Checks field only updates on later PR activity and goes stale between CI completions. Use
workflow_runor another supported trigger for Actions-based checks.According to the official GitHub Actions documentation, does `on: check_run` trigger when the completed check run was created by GitHub Actions?🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/discord-pr.yml around lines 18 - 19, The workflow uses the check_run event (check_run: types: [completed]) which does not fire for check runs created by GitHub Actions; replace or add a trigger that does fire for Actions-based CI such as workflow_run (e.g., workflow_run: types: [completed]) or another supported event so PR checks refresh immediately after Action runs complete; update the triggers block to include workflow_run and remove or supplement check_run accordingly.
159-164:⚠️ Potential issue | 🟠 MajorOnly trust exact bot-authored marker comments.
This selector accepts any issue comment containing
discord-msg-id:. A user-authored hidden comment can redirect which Discord message gets patched, and the same loose match is reused when deleting stale markers. Filter ongithub-actions[bot]and the exact<!-- discord-msg-id:<id> -->format before extracting the id.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/discord-pr.yml around lines 159 - 164, Only trust exact bot-authored HTML marker comments: when querying COMMENTS and computing DISCORD_MSG_ID, filter the gh api results to require the comment author login equals "github-actions[bot]" and match the body against the exact HTML marker format "<!-- discord-msg-id:<id> -->" before extracting the numeric id; update the jq/select expression that builds COMMENTS (and any equivalent deletion logic) to use select(.user.login=="github-actions[bot]" and (.body | test("^<!-- discord-msg-id:[0-9]+ -->$"))) and then extract the id from that exact marker into DISCORD_MSG_ID.
33-40:⚠️ Potential issue | 🟠 MajorGuard missing webhook secrets at the top of the step.
Fork-originated
pull_requestruns do not receive repository secrets, soDISCORD_WEBHOOK_URLcan be empty here. Bail out before parsingWEBHOOK_ID/WEBHOOK_TOKENor callingcurl.Do GitHub Actions `pull_request` workflows receive repository secrets when the PR comes from a fork?🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/discord-pr.yml around lines 33 - 40, The workflow step "Resolve PR, build embed, post or patch Discord" must guard against missing webhook secrets by checking DISCORD_WEBHOOK_URL (env GH_TOKEN/ DISCORD_WEBHOOK_URL) before attempting to parse WEBHOOK_ID/WEBHOOK_TOKEN or invoking curl; update the step script to exit early if DISCORD_WEBHOOK_URL is empty or undefined (log a clear message and skip posting) so forked pull_request runs without secrets won’t attempt to parse tokens or call Discord.
21-24:⚠️ Potential issue | 🟠 MajorAdd
checks: readto the explicit permissions block.Once a workflow declares
permissions, every unspecified scope becomesnone. This job later calls the check-runs REST API, so omittingchecks: readcan prevent the Checks field from populating.When a GitHub Actions workflow sets explicit `permissions`, what happens to unspecified scopes, and what permission does `GET /repos/{owner}/{repo}/commits/{ref}/check-runs` require?🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/discord-pr.yml around lines 21 - 24, The permissions block currently lists contents/read, pull-requests/write, and issues/write but omits checks/read; update the permissions mapping in the workflow's permissions section to include checks: read so the job can call the check-runs API (add the line "checks: read" alongside the existing scopes in the permissions block).
107-109:⚠️ Potential issue | 🟠 MajorSkipped-only runs still render as green success.
Line 108 only checks
FAILINGandPENDING, so a commit with zero passes and only skipped checks is rewritten to✅ All 0 passed. Gate this branch on all checks actually passing, e.g.PASSING == TOTAL.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/discord-pr.yml around lines 107 - 109, The branch that sets CHECKS_FIELD to "✅ All $PASSING passed" should only run when every check actually passed; change the condition that currently tests only FAILING and PENDING to also require PASSING == TOTAL (or equivalently PASSING -eq TOTAL) and update the message to use TOTAL (e.g., "✅ All $TOTAL passed") so skipped-only runs no longer show as full success; modify the conditional around CHECKS_FIELD and the CHECKS_FIELD assignment to use the PASSING and TOTAL variables accordingly.
26-28:⚠️ Potential issue | 🔴 Critical
cancel-in-progress: truereopens the duplicate-message race.A newer run can cancel this job after the Discord POST succeeds but before the hidden
discord-msg-idcomment is written. The replacement run then sees no marker and creates a second message. This mutex needscancel-in-progress: false.In GitHub Actions, when `concurrency.cancel-in-progress` is true, can a currently running job be cancelled while a `run` step is still executing?🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/discord-pr.yml around lines 26 - 28, The concurrency block uses cancel-in-progress: true which allows a newer run to cancel an in-flight job and re-run, reopening the duplicate-message race; update the concurrency setting to set cancel-in-progress: false in the concurrency: group: discord-pr-${{ github.event.pull_request.number || github.event.check_run.pull_requests[0].number }} block so running jobs cannot be cancelled by newer runs and the hidden discord-msg-id comment remains reliable.
170-189:⚠️ Potential issue | 🟠 MajorHandle Discord update failures transactionally.
Any non-404 PATCH response is ignored, and the 404 branch deletes the stored marker before a replacement message exists. A 429/5xx here either leaves the embed stale with a green job or removes the marker and makes the next retry create a duplicate message. Fail or retry on non-2xx responses, and only clear/delete the marker after a successful replacement POST.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/discord-pr.yml around lines 170 - 189, The current PATCH handling treats only 404 specially and deletes the stored DISCORD_MSG_ID before ensuring a replacement exists; change the logic around PATCH_STATUS (from the curl PATCH block that sets PATCH_STATUS) so you treat any 2xx as success and continue, treat 404 as “message gone” but do NOT delete/clear DISCORD_MSG_ID or remove the GitHub marker yet, and treat any non-2xx/ non-404 (e.g., 429/5xx) as a retry/failure (exit non-zero or retry loop) instead of proceeding; then only after a successful POST (the block that sets RESPONSE and DISCORD_MSG_ID) perform the gh api -X DELETE using STALE_COMMENT_ID and clear DISCORD_MSG_ID/marker, ensuring deletion/clearing happens after a confirmed replacement POST succeeded.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In @.github/workflows/discord-pr.yml:
- Around line 18-19: The workflow uses the check_run event (check_run: types:
[completed]) which does not fire for check runs created by GitHub Actions;
replace or add a trigger that does fire for Actions-based CI such as
workflow_run (e.g., workflow_run: types: [completed]) or another supported event
so PR checks refresh immediately after Action runs complete; update the triggers
block to include workflow_run and remove or supplement check_run accordingly.
- Around line 159-164: Only trust exact bot-authored HTML marker comments: when
querying COMMENTS and computing DISCORD_MSG_ID, filter the gh api results to
require the comment author login equals "github-actions[bot]" and match the body
against the exact HTML marker format "<!-- discord-msg-id:<id> -->" before
extracting the numeric id; update the jq/select expression that builds COMMENTS
(and any equivalent deletion logic) to use
select(.user.login=="github-actions[bot]" and (.body | test("^<!--
discord-msg-id:[0-9]+ -->$"))) and then extract the id from that exact marker
into DISCORD_MSG_ID.
- Around line 33-40: The workflow step "Resolve PR, build embed, post or patch
Discord" must guard against missing webhook secrets by checking
DISCORD_WEBHOOK_URL (env GH_TOKEN/ DISCORD_WEBHOOK_URL) before attempting to
parse WEBHOOK_ID/WEBHOOK_TOKEN or invoking curl; update the step script to exit
early if DISCORD_WEBHOOK_URL is empty or undefined (log a clear message and skip
posting) so forked pull_request runs without secrets won’t attempt to parse
tokens or call Discord.
- Around line 21-24: The permissions block currently lists contents/read,
pull-requests/write, and issues/write but omits checks/read; update the
permissions mapping in the workflow's permissions section to include checks:
read so the job can call the check-runs API (add the line "checks: read"
alongside the existing scopes in the permissions block).
- Around line 107-109: The branch that sets CHECKS_FIELD to "✅ All $PASSING
passed" should only run when every check actually passed; change the condition
that currently tests only FAILING and PENDING to also require PASSING == TOTAL
(or equivalently PASSING -eq TOTAL) and update the message to use TOTAL (e.g.,
"✅ All $TOTAL passed") so skipped-only runs no longer show as full success;
modify the conditional around CHECKS_FIELD and the CHECKS_FIELD assignment to
use the PASSING and TOTAL variables accordingly.
- Around line 26-28: The concurrency block uses cancel-in-progress: true which
allows a newer run to cancel an in-flight job and re-run, reopening the
duplicate-message race; update the concurrency setting to set
cancel-in-progress: false in the concurrency: group: discord-pr-${{
github.event.pull_request.number ||
github.event.check_run.pull_requests[0].number }} block so running jobs cannot
be cancelled by newer runs and the hidden discord-msg-id comment remains
reliable.
- Around line 170-189: The current PATCH handling treats only 404 specially and
deletes the stored DISCORD_MSG_ID before ensuring a replacement exists; change
the logic around PATCH_STATUS (from the curl PATCH block that sets PATCH_STATUS)
so you treat any 2xx as success and continue, treat 404 as “message gone” but do
NOT delete/clear DISCORD_MSG_ID or remove the GitHub marker yet, and treat any
non-2xx/ non-404 (e.g., 429/5xx) as a retry/failure (exit non-zero or retry
loop) instead of proceeding; then only after a successful POST (the block that
sets RESPONSE and DISCORD_MSG_ID) perform the gh api -X DELETE using
STALE_COMMENT_ID and clear DISCORD_MSG_ID/marker, ensuring deletion/clearing
happens after a confirmed replacement POST succeeded.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1dc794dc-a826-40d3-bc99-deafee25576c
📒 Files selected for processing (1)
.github/workflows/discord-pr.yml
The Check Runs API returns every historical run and unexpanded matrix
placeholders, inflating counts. Deduplicate by name (keep latest),
filter out ${{ }} placeholders, and move cancelled to skipped bucket
so concurrency-cancelled runs don't show as failures.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add early exit when DISCORD_PR_WEBHOOK_URL is not configured to avoid malformed curl calls. Fix the "All N passed" finalization to require PASSING > 0, preventing a skipped-only result from being overwritten with "All 0 passed". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/discord-pr.yml:
- Around line 59-60: The gh api call that populates the PR variable can fail and
leave PR empty, causing downstream jq parsing to produce nulls and malformed
Discord embeds; after the gh api "/repos/$REPO/pulls/$PR_NUMBER" invocation (the
PR variable), check its exit status and/or whether PR is empty or missing
expected fields (used later by jq), and on failure log a clear error and exit
non‑zero (or set safe defaults) so the workflow stops instead of crafting a
broken embed; update the script around the gh api call and any code that reads
PR with jq to validate PR before building the Discord payload.
- Around line 26-28: The concurrency group expression can be empty for forked
check_run events because github.event.check_run.pull_requests may be empty;
update the concurrency group expression used in the workflow (the
concurrency.group setting) to add a fallback to the head SHA (e.g., use
github.event.pull_request.number ||
github.event.check_run.pull_requests[0].number ||
github.event.check_suite.head_sha or github.event.head_commit.id) so each run
for a forked PR resolves to a unique identifier; locate the concurrency block
that declares group: discord-pr-${{ github.event.pull_request.number ||
github.event.check_run.pull_requests[0].number }} and add the head-sha fallback
to that expression.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 3be86211-7ff2-4e9f-ae28-97ac8c6b727c
📒 Files selected for processing (1)
.github/workflows/discord-pr.yml
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The notify job is always in-progress when it queries the check-runs API, skewing passed/running counts. Filter it out and add it back as success since it will have completed its work by that point. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
resetting the checks |
|
resetting checks |
The pull_request event fires before CI checks are created, causing inaccurate counts. Show a placeholder on PR events and only query the check APIs when workflow_run fires after CI completes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The workflow_run trigger only fires when the workflow exists on the default branch. Revert to always querying checks and append a "CI starting..." hint on pull_request events since CI checks may not exist yet. Once merged, workflow_run will PATCH with final counts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update the embed after each individual check completes instead of waiting for the entire CI workflow to finish. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use /pulls endpoint with SHA filter instead of /commits/{sha}/pulls
for more reliable PR lookup on check_run and workflow_run events.
Add debug logging and fail on non-200 PATCH responses.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add workflow_call trigger so CI and PR checks can directly invoke the discord notification after completion, bypassing the default-branch limitation of check_run and workflow_run triggers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The discord-notify job (called via workflow_call from CI) is always in-progress at query time, inflating the running count. Exclude it and count it as passed, same as the notify job. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove check_run and workflow_run triggers that were redundant with workflow_call and causing double-fires. Simplify PR resolution to use inherited event context. Stop synthesizing fake success entries for self-checks. Add idempotency guard for the comment-as-state-store pattern to prevent duplicate Discord messages on concurrent runs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
a84282c to
9c35a4a
Compare
kwit75
left a comment
There was a problem hiding this comment.
LGTM 🚀 — thanks for the quick turnaround on the cleanup.
Verified against my prior comments:
- ✅ Lockfile churn gone — 3 files now, no pnpm-lock.yaml
- ✅
on: check_runremoved (the dead trigger for GH Actions checks) - ✅ Trigger model is exactly right —
pull_request + workflow_call.workflow_runandcheck_runboth gone, no more overlapping fire paths - ✅ Synthetic "success" injection removed — self-checks are now filtered out via
test("^(notify|discord-notify|Discord PR Notification)")rather than added back as fake passes - ✅ PR-by-SHA pagination concern is N/A now — PR number comes from event payload directly since the lookup paths are gone
- ✅ CHECKS_FIELD edge case is properly guarded by
PASSING -gt 0 - ✅
gh apifailure handling isif ! PR=$(...) || [ -z "$PR" ]which bails cleanly
One thing I'd still flag (not blocking): the comment-as-state-store still has a theoretical race condition between two near-simultaneous runs (both see no comment → both POST → both write a comment → future PATCHes only target one). The strict selector + bot author filter mitigates picking up the wrong comment, but doesn't prevent the dual-create. For our PR volume this is fine; if Discord starts showing duplicate embeds in the wild, the fix is to switch to GitHub Actions cache as the message-ID store. Worth a follow-up issue if you want to track it, but no need to block on it now.
Approving so you can land this before the Discord flood. Nice cleanup.
#614) * feat(discord): add live CI check status and PR state tracking to embed Enhance the Discord PR notification workflow to update a single embed message throughout the PR lifecycle instead of posting once on open. Tracks PR state (open/draft/closed/merged), labels, assignees, reviewers, and live CI check results by reacting to pull_request and check_run events. Uses a hidden PR comment to store the Discord message ID for subsequent PATCH updates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): use correct green embed color for open PR status Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: retrigger discord notification * chore: retrigger discord notification * fix(discord): sanitize PR body for Discord and recover from deleted messages Strip HTML comments, convert GitHub checkboxes to unicode, and turn markdown headings into Discord bold. If the stored Discord message was deleted (PATCH returns 404), clean up the stale comment and re-post. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): add issues permission and concurrency group The discord-msg-id comment was never stored/found because the issues API endpoint requires explicit `issues: write` permission. Also adds a concurrency group keyed on PR number to prevent duplicate messages from racing workflow runs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): deduplicate check runs to match GitHub UI counts The Check Runs API returns every historical run and unexpanded matrix placeholders, inflating counts. Deduplicate by name (keep latest), filter out ${{ }} placeholders, and move cancelled to skipped bucket so concurrency-cancelled runs don't show as failures. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): guard empty webhook and fix skipped-only check summary Add early exit when DISCORD_PR_WEBHOOK_URL is not configured to avoid malformed curl calls. Fix the "All N passed" finalization to require PASSING > 0, preventing a skipped-only result from being overwritten with "All 0 passed". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): use workflow_run trigger, add checks permission, tighten comment lookup Replace check_run with workflow_run since GitHub suppresses check_run events for Actions-created check suites, meaning CI completion never triggered an embed update. Add checks: read permission so the check-runs API works on non-public repos. Restrict the discord-msg-id comment lookup to bot-authored markers with exact format matching to prevent spoofing from user comments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): fix heading regex and multi-line HTML comment stripping Add -E flag to sed for heading conversion so {1,6} is treated as ERE quantifier instead of literal text. Replace sed with perl -0pe for HTML comment removal to handle multi-line spans from PR templates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): prevent cancel-in-progress orphaning and fix skipped check summary Set cancel-in-progress to false so a run cancelled mid-execution can't orphan a Discord message without saving its marker comment. Also require SKIPPED=0 in the "All passed" condition so mixed pass/skip results keep the detailed breakdown instead of being overwritten. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): add concurrency group fallback and validate PR fetch Add github.run_id fallback to the concurrency group so forked PRs with empty pull_requests arrays get a unique group instead of serializing all runs. Guard the PR API fetch to exit gracefully on failure instead of building a broken embed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): switch embed fields to 2-column layout for readability Insert zero-width space row breaks between field pairs so Discord renders them in 2 columns instead of 3, giving branch names and reviewer lists more room. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: retrigger discord notification * chore: retrigger discord notification * fix(discord): escape matrix placeholder filter to fix workflow parse error GitHub Actions interprets ${{ inside run: blocks (including comments and strings) as expression syntax. Move the literal into a shell variable and pass it to jq via --arg to avoid the parse error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: retrigger discord notification * fix(discord): use printf octal escapes to avoid GHA expression parse error GitHub Actions parses all ${{ sequences in run: blocks before shell execution, even inside single-quoted strings. Use printf with octal escapes to construct the marker at runtime. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * revert(discord): restore 3-column embed field layout Remove zero-width spacer fields and revert to the original 3-column inline layout for embed fields. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): remove extra spacing in embed body Drop the \n prefix from heading conversion that added blank lines before every bold heading. Improve blank-line collapsing after HTML comment stripping to prevent runs of empty lines. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): collapse blank line after bold headings in embed body Markdown headings have a blank line after them by convention. After converting to Discord bold, collapse the double newline to single so headings sit closer to their content. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): collapse all double newlines in embed body Discord renders single newlines as line breaks, so double newlines create excessive vertical spacing. Collapse all runs of 2+ newlines to a single newline and trim leading/trailing whitespace. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): fix leading whitespace trim in embed body Replace unreliable sed trim with perl s/^\s+// and s/\s+$// to reliably strip leading/trailing whitespace that was causing a gap between the embed title and description content. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): simplify body cleaning to only strip HTML comments Remove checkbox, heading, and newline transformations that were causing spacing issues. Keep only HTML comment stripping since Discord renders markdown natively. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): strip empty lines from embed description Remove all blank lines from the PR body to eliminate vertical spacing gaps in the Discord embed description. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): add gap between description and embed fields Append a trailing newline to the body so there is visual separation between the PR description and the status fields below it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): use zero-width space to preserve description-fields gap Discord trims trailing whitespace/newlines from embed descriptions. Append a zero-width space on a new line so the gap is preserved. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: retrigger discord notification * chore(discord): convert markdown checkboxes to unicode in embed body Discord doesn't render markdown checkboxes, so convert - [ ] and - [x] to ☐ and ☑ unicode characters. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): include commit statuses in check counts GitHub's PR checks page merges check runs and commit statuses (two separate APIs). The workflow was only querying check runs, missing external statuses like CodeRabbit. Fetch both APIs, normalize to a common format, and deduplicate by name to match GitHub's UI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): always show passed and failed check counts Display passed and failed counts even when zero so the checks field is never empty. Running and skipped are still conditional. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): use circular arrow emoji for running checks Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): exclude own check run from counts and assume success The notify job is always in-progress when it queries the check-runs API, skewing passed/running counts. Filter it out and add it back as success since it will have completed its work by that point. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): defer check counts to workflow_run trigger The pull_request event fires before CI checks are created, causing inaccurate counts. Show a placeholder on PR events and only query the check APIs when workflow_run fires after CI completes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): always query checks, append CI hint on PR events The workflow_run trigger only fires when the workflow exists on the default branch. Revert to always querying checks and append a "CI starting..." hint on pull_request events since CI checks may not exist yet. Once merged, workflow_run will PATCH with final counts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): remove PR description from embed Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(discord): add check_run trigger for per-check embed updates Update the embed after each individual check completes instead of waiting for the entire CI workflow to finish. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): remove CI starting hint from checks field Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): improve PR resolution fallback and error handling Use /pulls endpoint with SHA filter instead of /commits/{sha}/pulls for more reliable PR lookup on check_run and workflow_run events. Add debug logging and fail on non-200 PATCH responses. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): hide zero-count check categories in embed Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(discord): call PR notification from CI and PR checks workflows Add workflow_call trigger so CI and PR checks can directly invoke the discord notification after completion, bypassing the default-branch limitation of check_run and workflow_run triggers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): exclude discord-notify from check counts The discord-notify job (called via workflow_call from CI) is always in-progress at query time, inflating the running count. Exclude it and count it as passed, same as the notify job. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): remove dead triggers, fake checks, and add race guard Remove check_run and workflow_run triggers that were redundant with workflow_call and causing double-fires. Simplify PR resolution to use inherited event context. Stop synthesizing fake success entries for self-checks. Add idempotency guard for the comment-as-state-store pattern to prevent duplicate Discord messages on concurrent runs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
rocketride-org#614) * feat(discord): add live CI check status and PR state tracking to embed Enhance the Discord PR notification workflow to update a single embed message throughout the PR lifecycle instead of posting once on open. Tracks PR state (open/draft/closed/merged), labels, assignees, reviewers, and live CI check results by reacting to pull_request and check_run events. Uses a hidden PR comment to store the Discord message ID for subsequent PATCH updates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): use correct green embed color for open PR status Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: retrigger discord notification * chore: retrigger discord notification * fix(discord): sanitize PR body for Discord and recover from deleted messages Strip HTML comments, convert GitHub checkboxes to unicode, and turn markdown headings into Discord bold. If the stored Discord message was deleted (PATCH returns 404), clean up the stale comment and re-post. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): add issues permission and concurrency group The discord-msg-id comment was never stored/found because the issues API endpoint requires explicit `issues: write` permission. Also adds a concurrency group keyed on PR number to prevent duplicate messages from racing workflow runs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): deduplicate check runs to match GitHub UI counts The Check Runs API returns every historical run and unexpanded matrix placeholders, inflating counts. Deduplicate by name (keep latest), filter out ${{ }} placeholders, and move cancelled to skipped bucket so concurrency-cancelled runs don't show as failures. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): guard empty webhook and fix skipped-only check summary Add early exit when DISCORD_PR_WEBHOOK_URL is not configured to avoid malformed curl calls. Fix the "All N passed" finalization to require PASSING > 0, preventing a skipped-only result from being overwritten with "All 0 passed". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): use workflow_run trigger, add checks permission, tighten comment lookup Replace check_run with workflow_run since GitHub suppresses check_run events for Actions-created check suites, meaning CI completion never triggered an embed update. Add checks: read permission so the check-runs API works on non-public repos. Restrict the discord-msg-id comment lookup to bot-authored markers with exact format matching to prevent spoofing from user comments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): fix heading regex and multi-line HTML comment stripping Add -E flag to sed for heading conversion so {1,6} is treated as ERE quantifier instead of literal text. Replace sed with perl -0pe for HTML comment removal to handle multi-line spans from PR templates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): prevent cancel-in-progress orphaning and fix skipped check summary Set cancel-in-progress to false so a run cancelled mid-execution can't orphan a Discord message without saving its marker comment. Also require SKIPPED=0 in the "All passed" condition so mixed pass/skip results keep the detailed breakdown instead of being overwritten. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): add concurrency group fallback and validate PR fetch Add github.run_id fallback to the concurrency group so forked PRs with empty pull_requests arrays get a unique group instead of serializing all runs. Guard the PR API fetch to exit gracefully on failure instead of building a broken embed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): switch embed fields to 2-column layout for readability Insert zero-width space row breaks between field pairs so Discord renders them in 2 columns instead of 3, giving branch names and reviewer lists more room. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: retrigger discord notification * chore: retrigger discord notification * fix(discord): escape matrix placeholder filter to fix workflow parse error GitHub Actions interprets ${{ inside run: blocks (including comments and strings) as expression syntax. Move the literal into a shell variable and pass it to jq via --arg to avoid the parse error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: retrigger discord notification * fix(discord): use printf octal escapes to avoid GHA expression parse error GitHub Actions parses all ${{ sequences in run: blocks before shell execution, even inside single-quoted strings. Use printf with octal escapes to construct the marker at runtime. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * revert(discord): restore 3-column embed field layout Remove zero-width spacer fields and revert to the original 3-column inline layout for embed fields. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): remove extra spacing in embed body Drop the \n prefix from heading conversion that added blank lines before every bold heading. Improve blank-line collapsing after HTML comment stripping to prevent runs of empty lines. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): collapse blank line after bold headings in embed body Markdown headings have a blank line after them by convention. After converting to Discord bold, collapse the double newline to single so headings sit closer to their content. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): collapse all double newlines in embed body Discord renders single newlines as line breaks, so double newlines create excessive vertical spacing. Collapse all runs of 2+ newlines to a single newline and trim leading/trailing whitespace. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): fix leading whitespace trim in embed body Replace unreliable sed trim with perl s/^\s+// and s/\s+$// to reliably strip leading/trailing whitespace that was causing a gap between the embed title and description content. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): simplify body cleaning to only strip HTML comments Remove checkbox, heading, and newline transformations that were causing spacing issues. Keep only HTML comment stripping since Discord renders markdown natively. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): strip empty lines from embed description Remove all blank lines from the PR body to eliminate vertical spacing gaps in the Discord embed description. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): add gap between description and embed fields Append a trailing newline to the body so there is visual separation between the PR description and the status fields below it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): use zero-width space to preserve description-fields gap Discord trims trailing whitespace/newlines from embed descriptions. Append a zero-width space on a new line so the gap is preserved. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: retrigger discord notification * chore(discord): convert markdown checkboxes to unicode in embed body Discord doesn't render markdown checkboxes, so convert - [ ] and - [x] to ☐ and ☑ unicode characters. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): include commit statuses in check counts GitHub's PR checks page merges check runs and commit statuses (two separate APIs). The workflow was only querying check runs, missing external statuses like CodeRabbit. Fetch both APIs, normalize to a common format, and deduplicate by name to match GitHub's UI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): always show passed and failed check counts Display passed and failed counts even when zero so the checks field is never empty. Running and skipped are still conditional. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): use circular arrow emoji for running checks Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): exclude own check run from counts and assume success The notify job is always in-progress when it queries the check-runs API, skewing passed/running counts. Filter it out and add it back as success since it will have completed its work by that point. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): defer check counts to workflow_run trigger The pull_request event fires before CI checks are created, causing inaccurate counts. Show a placeholder on PR events and only query the check APIs when workflow_run fires after CI completes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): always query checks, append CI hint on PR events The workflow_run trigger only fires when the workflow exists on the default branch. Revert to always querying checks and append a "CI starting..." hint on pull_request events since CI checks may not exist yet. Once merged, workflow_run will PATCH with final counts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): remove PR description from embed Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(discord): add check_run trigger for per-check embed updates Update the embed after each individual check completes instead of waiting for the entire CI workflow to finish. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): remove CI starting hint from checks field Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): improve PR resolution fallback and error handling Use /pulls endpoint with SHA filter instead of /commits/{sha}/pulls for more reliable PR lookup on check_run and workflow_run events. Add debug logging and fail on non-200 PATCH responses. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(discord): hide zero-count check categories in embed Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(discord): call PR notification from CI and PR checks workflows Add workflow_call trigger so CI and PR checks can directly invoke the discord notification after completion, bypassing the default-branch limitation of check_run and workflow_run triggers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): exclude discord-notify from check counts The discord-notify job (called via workflow_call from CI) is always in-progress at query time, inflating the running count. Exclude it and count it as passed, same as the notify job. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(discord): remove dead triggers, fake checks, and add race guard Remove check_run and workflow_run triggers that were redundant with workflow_call and causing double-fires. Simplify PR resolution to use inherited event context. Stop synthesizing fake success entries for self-checks. Add idempotency guard for the comment-as-state-store pattern to prevent duplicate Discord messages on concurrent runs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Summary
Enhance the Discord PR notification workflow to update a single embed message throughout the PR lifecycle instead of posting once on open. Tracks PR state (open/draft/closed/merged), labels, assignees, reviewers, and live CI check results by reacting to pull_request and check_run events. Uses a hidden PR comment to store the Discord message ID for subsequent PATCH updates.
Type
Chore
Testing
./builder testpassesChecklist
Linked Issue
#613