Skip to content

fix: improve summary prompt for cleaner markdown rendering#98

Merged
waynesun09 merged 3 commits into
mainfrom
improve-summary-format
May 22, 2026
Merged

fix: improve summary prompt for cleaner markdown rendering#98
waynesun09 merged 3 commits into
mainfrom
improve-summary-format

Conversation

@waynesun09

@waynesun09 waynesun09 commented May 22, 2026

Copy link
Copy Markdown
Owner

Summary

  • Update _SUMMARY_RULES prompt to produce emoji severity headings (### 🟠 Major (2)), numbered lists, bold file paths (**\file`**`), inline suggestions, and Overall Assessment footer
  • Update _format_finding_md fallback: bold file paths, remove existing_code rendering (stays in findings dict only), inline suggestions
  • Update _unpack_bare_array fallback: emoji headings, numbered lists

Test plan

  • uv run pytest tests/unit/test_delegation_summarizer.py -q — 85 passed
  • Local run against cicaddy-action PR docs: update documentation and bump version to v0.6.1 #32 — verified proper ### 🟠 Major (2), ### 🟡 Minor (1), ### 🔵 Nit (1) headings, numbered items, bold file paths, and Overall Assessment in review body
  • In-place comment update working (PATCH to existing bot comment)
  • 4 inline review comments posted on correct diff lines with severity badges

Summary by CodeRabbit

  • Style

    • Improved markdown formatting of code review summaries with emoji-labeled severity headings, numbered findings per severity level, enhanced file path display, and clearer suggestion formatting.
  • Tests

    • Updated test expectations to align with the new summary output formatting, including file references, code snippets, and suggestion labels.

Review Change Stack

Update _SUMMARY_RULES to produce emoji severity headings
(### 🟠 Major), numbered lists, bold file paths, and inline
suggestions. Update _format_finding_md fallback to match.

Signed-off-by: Wayne Sun <gsun@redhat.com>
@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@waynesun09 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 45 minutes and 32 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3784dbf0-ec43-45fb-ad3d-2900538d5c30

📥 Commits

Reviewing files that changed from the base of the PR and between 4c9a1b0 and 2665597.

📒 Files selected for processing (2)
  • src/cicaddy/delegation/summarizer.py
  • tests/unit/test_delegation_summarizer.py
📝 Walkthrough

Walkthrough

The PR refines how the summarizer formats code review findings in markdown. The AI rules prompt is updated to require emoji severity headings and structured finding layout, the _format_finding_md function is rewritten to produce richer multi-part blocks, bare-array unpacking integrates the new formatter, and test assertions validate the new output format.

Changes

Markdown Format Refinement for Finding Summaries

Layer / File(s) Summary
Markdown format rules and finding renderer
src/cicaddy/delegation/summarizer.py
Updated _SUMMARY_RULES prompt to enforce emoji severity headings, numbered findings per severity, inline **\file`**syntax, and specific markdown structure. Rewrote_format_finding_md to construct multi-part rich blocks: "In \file`:" header, optional unindented fenced code block, optional bold "Suggestion:" line, and joined string output.
Bare-array unpacking with new formatter
src/cicaddy/delegation/summarizer.py
Modified bare-array unpacking to iterate severities, skip empty groups, format each finding via the new _format_finding_md, and remove per-severity (count) headings and the introductory "identified N finding(s)" line.
Test coverage for new markdown format
tests/unit/test_delegation_summarizer.py
Updated assertions across five test cases to validate severity headers without counts, inline backticked file paths, bold suggestion labels, code-snippet preservation, and correct existing_code field storage in findings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • waynesun09/cicaddy#97: Both PRs modify _format_finding_md and _unpack_bare_array output formatting for severity headings, finding rendering, file-path backticks, and suggestion labels.
  • waynesun09/cicaddy#86: #86 adds parsing for bare JSON array responses, while this PR changes how those extracted findings are formatted into markdown.
  • waynesun09/cicaddy#54: Directly related to introduction of Finding.existing_code field that the new formatter and tests now render and validate.

Poem

🐰 A rabbit hops through summaries,
Emoji headings bright and clear,
Findings numbered, files backticked true,
Suggestions bolded without a tear,
Markdown blooms where structure grows! 🌱

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: improving the summary prompt for cleaner markdown rendering, which aligns with the core objectives of updating the prompt rules, formatting functions, and markdown output.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 improve-summary-format

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.

Replace flat numbered-list format in _unpack_bare_array with
heading-per-finding style matching individual agent output.
Update _format_finding_md to produce rich blocks with file
references, fenced code snippets, and bold suggestion labels.
Simplify _SUMMARY_RULES to let the AI format naturally rather
than over-constraining markdown structure.

Signed-off-by: Wayne Sun <gsun@redhat.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/cicaddy/delegation/summarizer.py (1)

507-519: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fallback summary drops findings with unexpected severity labels.

Lines 508-519 bucket by raw severity, but only critical|major|minor|nit groups are rendered later. Any other severity stays in findings but disappears from synthesized summary.

Proposed fix
         for f in findings:
             sev = str(f.get("severity", "minor")).lower()
+            if sev not in _VALID_SEVERITIES:
+                sev = "minor"
             msg = f.get("message", "")
             if msg:
                 severity_groups.setdefault(sev, []).append(f)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cicaddy/delegation/summarizer.py` around lines 507 - 519, The current
bucket logic in summarizer.py stores findings by raw sev (variable sev) but the
rendering loop only iterates ("critical","major","minor","nit"), so any finding
with an unexpected severity is lost; update the rendering to include a fallback
bucket or dynamically render any remaining keys in severity_groups after the
known-order pass (e.g., build an ordered list: the known severities in that
order, then append sorted(severity_groups.keys() - set(known))) and iterate that
list when building parts/finding_num so all findings (variables: findings,
severity_groups, sev, parts, finding_num) are included in the synthesized
summary.
🧹 Nitpick comments (1)
src/cicaddy/delegation/summarizer.py (1)

129-134: ⚡ Quick win

Use Google-style docstring sections for _format_finding_md.

The updated docstring should follow Google-style (Args, Returns) for src/**/*.py.

Proposed refactor
 def _format_finding_md(entry: dict) -> str:
-    """Format a single finding dict as a rich markdown block.
-
-    Mirrors the structure individual review agents produce naturally:
-    file reference, issue description, code snippet, and suggestion
-    as separate visual blocks.
-    """
+    """Format a single finding dictionary as markdown.
+
+    Args:
+        entry: Finding payload containing message, file, and optional
+            existing_code/suggestion fields.
+
+    Returns:
+        A markdown string for one formatted finding block.
+    """

As per coding guidelines, src/**/*.py: Use type hints and Google-style docstrings in Python code.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cicaddy/delegation/summarizer.py` around lines 129 - 134, The function
_format_finding_md has a plain docstring; update it to a Google-style docstring
including Args (describe parameters and their types) and Returns (return type
and description), and add missing type hints to the _format_finding_md signature
and any parameters mentioned in the docstring (e.g., the finding dict parameter
and returned str), so the docstring and signature match; ensure the docstring
briefly documents parameter types and what the formatted markdown string
contains.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/cicaddy/delegation/summarizer.py`:
- Around line 145-147: The current rendering appends raw existing_code inside
triple-backtick fences (see existing_code and parts.append usage in
summarizer.py), which breaks Markdown if the snippet contains ```; update the
logic to choose a fence that doesn't appear in the snippet (e.g., use "```" by
default and switch to "````" or a longer fence when the snippet contains the
default fence), trim the snippet once, then append using the chosen fence for
both opening and closing so the fenced code block cannot be prematurely
terminated by content inside existing_code.

---

Outside diff comments:
In `@src/cicaddy/delegation/summarizer.py`:
- Around line 507-519: The current bucket logic in summarizer.py stores findings
by raw sev (variable sev) but the rendering loop only iterates
("critical","major","minor","nit"), so any finding with an unexpected severity
is lost; update the rendering to include a fallback bucket or dynamically render
any remaining keys in severity_groups after the known-order pass (e.g., build an
ordered list: the known severities in that order, then append
sorted(severity_groups.keys() - set(known))) and iterate that list when building
parts/finding_num so all findings (variables: findings, severity_groups, sev,
parts, finding_num) are included in the synthesized summary.

---

Nitpick comments:
In `@src/cicaddy/delegation/summarizer.py`:
- Around line 129-134: The function _format_finding_md has a plain docstring;
update it to a Google-style docstring including Args (describe parameters and
their types) and Returns (return type and description), and add missing type
hints to the _format_finding_md signature and any parameters mentioned in the
docstring (e.g., the finding dict parameter and returned str), so the docstring
and signature match; ensure the docstring briefly documents parameter types and
what the formatted markdown string contains.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 87c58e43-1577-4b1e-a601-caf467766350

📥 Commits

Reviewing files that changed from the base of the PR and between 7bcc353 and 4c9a1b0.

📒 Files selected for processing (2)
  • src/cicaddy/delegation/summarizer.py
  • tests/unit/test_delegation_summarizer.py

Comment thread src/cicaddy/delegation/summarizer.py
- Fix leading newline when finding has no file path
- Use ~~~ fences when existing_code contains backticks
- Map unknown severities (high/medium/low/error) to canonical values
- Fix heading hierarchy: ## section → ### finding (was ####)
- Add edge case tests for all fixes (90 tests total)

Signed-off-by: Wayne Sun <gsun@redhat.com>
@sonarqubecloud

Copy link
Copy Markdown

@waynesun09
waynesun09 merged commit f6d7fee into main May 22, 2026
8 checks passed
@waynesun09
waynesun09 deleted the improve-summary-format branch May 22, 2026 22:28
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.

1 participant