Skip to content

feat: comment/summary rendering module (Phase 5a)#613

Draft
rdhar wants to merge 2 commits into
mainfrom
feat-comment-module
Draft

feat: comment/summary rendering module (Phase 5a)#613
rdhar wants to merge 2 commits into
mainfrom
feat-comment-module

Conversation

@rdhar

@rdhar rdhar commented Jun 28, 2026

Copy link
Copy Markdown
Member

Phase 5a — Comment/summary rendering (comment.ts)

First half of Phase 5 (part of #582, tracking #568), built on Phase 4 (#612). No behavioural change: comment.ts is added and unit-tested but not wired into main.ts, so dist/ is unchanged. It's the last pure module before the runtime cutover.

Reproduces the composite action's post-step markdown as pure, testable functions:

  • parseDiff(showOutput) — turns terraform show # … lines into +/-/!/~/#-prefixed diff lines (first-match-wins, mirroring the sequential sed), plus the changed-resource count (excludes # lines).
  • parseSummary(consoleOutput) — the last Error: / Plan: / Apply complete! / No changes. / Success line, else View output. (mirrors the awk).
  • truncate(text, maxCodePoints)code-point truncation with a \n… sentinel (per Q5, so a multi-byte char is never split).
  • buildCommentBody(parts) — assembles the exact heredoc layout: the six comment-pos-* placeholders, the ```fish command block, the collapsible diff, the collapsible summary with the actor footer + (view log) link, the console block, and the trailing `` the upsert keys off.

Checklist

  • bun run typecheck (strict, no any in src/)
  • bun run format:check
  • bun test — 87 pass (+18)
  • bun run build:check — no dist/ drift

Why split Phase 5

Phase 5 bundles comment + orchestrator + the action.yml using: node24 flip. That flip is the one change that alters runtime behaviour and retires all the bash, so it deserves its own focused, closely-reviewed PR. This PR lands the pure rendering so the cutover PR is just wiring.

Next — Phase 5b (the cutover, separate PR)

orchestrator.ts sequencing every module + setting the 11 action outputs; main.ts wiring; action.ymlusing: node24 (+ GH_CHECK_RUN_ID: ${{ job.check_run_id }}, $GITHUB_STEP_SUMMARY write, the hide/show-args command filtering, check-run token = github.token); then README rewrite + major version tag (#583). The full test_ci/test_aws matrix runs against the flipped action there.

Draft until reviewed.


Generated by Claude Code

First half of Phase 5 (part of #582, tracking #568): the last pure module.
No behavioural change — added and unit-tested but not wired in; dist unchanged.

- comment.ts: parseDiff (terraform show -> +/-/!/~/# symbol-prefixed lines +
  change count), parseSummary (last Error:/Plan:/Apply complete!/No changes./
  Success line, else "View output."), truncate (Unicode code-point truncation
  with \n… sentinel, per Q5), and buildCommentBody (reproduces the composite
  post-step markdown: 6 comment-pos placeholders, ```fish command block,
  collapsible diff, collapsible summary with actor footer + view-log link,
  console block, trailing <!-- marker -->).
- 18 new tests.

Next (Phase 5b): orchestrator.ts wiring all modules + flip action.yml to
using: node24 + README/major-tag — the runtime cutover, as its own PR.

Co-authored-by: Rishav Dhar <[email protected]>

Copilot AI 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.

Pull request overview

Adds the Phase 5a pure rendering module for PR comments and job summaries, extracting the composite action’s markdown construction into unit-tested TypeScript helpers as part of the ongoing TS migration.

Changes:

  • Added src/comment.ts with pure functions for diff parsing, summary extraction, code-point truncation, and comment body assembly.
  • Added unit tests covering the rendering and parsing behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/comment.ts Implements the comment/summary rendering helpers intended to mirror the composite action’s post-step markdown output.
tests/comment.test.ts Adds unit tests for diff parsing, summary parsing, truncation, and comment body layout.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/comment.ts
Comment thread __tests__/comment.test.ts
Comment thread src/comment.ts Outdated
…eview)

Drop the escaped dot in parseSummary so the "No changes." token matches the
composite awk byte-for-byte (and a future "No changes:"/"!" variant matches
identically). Comment-only behaviour otherwise unchanged.

Co-authored-by: Rishav Dhar <[email protected]>

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread src/comment.ts
Comment on lines +97 to +99
/** The collapsible diff block, or "" when there are no changed-resource lines. */
function renderDiffBlock(parts: CommentParts): string {
if (parts.diff.lines.length === 0) return "";
Comment thread src/comment.ts
Comment on lines +139 to +140
<!-- ${parts.marker} -->
${pos6}`;
Comment thread __tests__/comment.test.ts
Comment on lines +116 to +118
for (const p of ["P1", "P2", "P3", "P4", "P5", "P6"])
expect(body).toContain(p);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants