Skip to content

feat(discord): add live CI check status and PR state tracking to embed - #614

Merged
joshuadarron merged 43 commits into
developfrom
chore/RR-613-featdiscord-add-live-ci-check-status-field-to-pr-embed
Apr 6, 2026
Merged

joshuadarron merged 43 commits into
developfrom
chore/RR-613-featdiscord-add-live-ci-check-status-field-to-pr-embed

Conversation

@joshuadarron

@joshuadarron joshuadarron commented Apr 3, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • Tests added or updated
  • Tested locally
  • ./builder test passes

Checklist

  • Commit messages follow conventional commits
  • No secrets or credentials included
  • Wiki updated (if applicable)
  • Breaking changes documented (if applicable)

Linked Issue

#613

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>
@joshuadarron
joshuadarron requested a review from kwit75 as a code owner April 3, 2026 23:55
@joshuadarron joshuadarron linked an issue Apr 3, 2026 that may be closed by this pull request
5 tasks
@github-actions github-actions Bot added the ci/cd CI/CD and build system label Apr 3, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between cb14933 and 3eff03b.

📒 Files selected for processing (1)
  • .github/workflows/discord-pr.yml

Comment thread .github/workflows/discord-pr.yml Resolved
Comment thread .github/workflows/discord-pr.yml Resolved
Comment thread .github/workflows/discord-pr.yml Resolved
@rocketride-org rocketride-org deleted a comment from github-actions Bot Apr 4, 2026
@joshuadarron joshuadarron self-assigned this Apr 4, 2026
…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>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3eff03b and 50120c9.

📒 Files selected for processing (1)
  • .github/workflows/discord-pr.yml

Comment thread .github/workflows/discord-pr.yml Resolved
Comment thread .github/workflows/discord-pr.yml Resolved
Comment thread .github/workflows/discord-pr.yml Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 50120c9 and 3ec8447.

📒 Files selected for processing (1)
  • .github/workflows/discord-pr.yml

Comment thread .github/workflows/discord-pr.yml Resolved
Comment thread .github/workflows/discord-pr.yml Resolved
Comment thread .github/workflows/discord-pr.yml Resolved
Comment thread .github/workflows/discord-pr.yml Resolved
@rocketride-org rocketride-org deleted a comment from coderabbitai Bot Apr 4, 2026
@rocketride-org rocketride-org deleted a comment from github-actions Bot Apr 4, 2026
@rocketride-org rocketride-org deleted a comment from github-actions Bot Apr 4, 2026
@rocketride-org rocketride-org deleted a comment from github-actions Bot Apr 4, 2026
@rocketride-org rocketride-org deleted a comment from github-actions Bot Apr 4, 2026
@rocketride-org rocketride-org deleted a comment from github-actions Bot Apr 4, 2026
@rocketride-org rocketride-org deleted a comment from github-actions Bot Apr 4, 2026
@rocketride-org rocketride-org deleted a comment from github-actions Bot Apr 4, 2026
@rocketride-org rocketride-org deleted a comment from github-actions Bot Apr 4, 2026
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>
@coderabbitai

coderabbitai Bot commented Apr 4, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Discord PR Workflow
.github/workflows/discord-pr.yml
Expanded triggers to many pull_request types and check_run: completed; increased permissions and added job concurrency/env vars; new inline script resolves PR for both event types (including check_run.head_sha with fork fallback), fetches live PR data and paginated/deduplicated check runs, computes dynamic status/color, transforms/truncates PR body (repairs fenced code blocks, strips HTML comments, converts checkboxes/headings), and implements idempotent Discord updates via discord-msg-id PR comment markers (PATCH existing message or POST new and store ID).

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 I hopped through events both new and old,

Fetched PRs and checks and made embeds bold.
If a message exists, I gently update;
Else I post and leave a marker to state.
Cheers — the Discord feed is neat and bold! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main changes: adding live CI check status and PR state tracking to the Discord embed, which aligns with the core objective of updating the Discord workflow to track PR state and display CI check results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/RR-613-featdiscord-add-live-ci-check-status-field-to-pr-embed

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (7)
.github/workflows/discord-pr.yml (7)

18-19: ⚠️ Potential issue | 🟠 Major

check_run will 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_run or 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 | 🟠 Major

Only 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 on github-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 | 🟠 Major

Guard missing webhook secrets at the top of the step.

Fork-originated pull_request runs do not receive repository secrets, so DISCORD_WEBHOOK_URL can be empty here. Bail out before parsing WEBHOOK_ID/WEBHOOK_TOKEN or calling curl.

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 | 🟠 Major

Add checks: read to the explicit permissions block.

Once a workflow declares permissions, every unspecified scope becomes none. This job later calls the check-runs REST API, so omitting checks: read can 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 | 🟠 Major

Skipped-only runs still render as green success.

Line 108 only checks FAILING and PENDING, 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: true reopens the duplicate-message race.

A newer run can cancel this job after the Discord POST succeeds but before the hidden discord-msg-id comment is written. The replacement run then sees no marker and creates a second message. This mutex needs cancel-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 | 🟠 Major

Handle 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3ec8447 and 0366b87.

📒 Files selected for processing (1)
  • .github/workflows/discord-pr.yml

joshuadarron and others added 2 commits April 3, 2026 20:42
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>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0366b87 and ab63f41.

📒 Files selected for processing (1)
  • .github/workflows/discord-pr.yml

Comment thread .github/workflows/discord-pr.yml Resolved
Comment thread .github/workflows/discord-pr.yml Resolved
joshuadarron and others added 2 commits April 3, 2026 21:51
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>
@joshuadarron

Copy link
Copy Markdown
Collaborator Author

resetting the checks

@joshuadarron joshuadarron reopened this Apr 4, 2026
@joshuadarron

Copy link
Copy Markdown
Collaborator Author

resetting checks

joshuadarron and others added 6 commits April 3, 2026 22:12
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>
joshuadarron and others added 4 commits April 6, 2026 13:49
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>
@joshuadarron
joshuadarron force-pushed the chore/RR-613-featdiscord-add-live-ci-check-status-field-to-pr-embed branch from a84282c to 9c35a4a Compare April 6, 2026 20:52
@joshuadarron
joshuadarron enabled auto-merge (squash) April 6, 2026 21:19

@kwit75 kwit75 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀 — thanks for the quick turnaround on the cleanup.

Verified against my prior comments:

  1. ✅ Lockfile churn gone — 3 files now, no pnpm-lock.yaml
  2. ✅ on: check_run removed (the dead trigger for GH Actions checks)
  3. ✅ Trigger model is exactly right — pull_request + workflow_call. workflow_run and check_run both gone, no more overlapping fire paths
  4. ✅ 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
  5. ✅ PR-by-SHA pagination concern is N/A now — PR number comes from event payload directly since the lookup paths are gone
  6. ✅ CHECKS_FIELD edge case is properly guarded by PASSING -gt 0
  7. ✅ gh api failure handling is if ! 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.

@joshuadarron
joshuadarron merged commit e76cd12 into develop Apr 6, 2026
14 checks passed
@joshuadarron
joshuadarron deleted the chore/RR-613-featdiscord-add-live-ci-check-status-field-to-pr-embed branch April 6, 2026 22:00
shashidharbabu pushed a commit that referenced this pull request Apr 7, 2026
#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>
AviNormie pushed a commit to AviNormie/rocketride-server that referenced this pull request Nov 9, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/cd CI/CD and build system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(discord): add live CI check status field to PR embed

2 participants