Skip to content

fix(github): expand bot template placeholders in PR review/comment fetches#164

Merged
MementoRC merged 1 commit into
developmentfrom
fix/pr-review-bot-suggestions
May 5, 2026
Merged

fix(github): expand bot template placeholders in PR review/comment fetches#164
MementoRC merged 1 commit into
developmentfrom
fix/pr-review-bot-suggestions

Conversation

@MementoRC
Copy link
Copy Markdown
Owner

Summary

github_get_pr_reviews and github_get_pr_comments returned the raw markdown body from the GitHub REST API. When a bot (Copilot review, custom GitHub App) posts a comment whose body contains template placeholders such as ${{ metadata.patch }}, GitHub renders those server-side only when the response is requested with the application/vnd.github.full+json media type (which adds body_html and body_text to the payload). Until now we always sent application/vnd.github.v3+json, so callers received the un-expanded template and had no way to recover the actual diff suggestion content.

Changes

  • client.pyGitHubClient.get() gains a keyword-only accept parameter (default unchanged). Backward-compatible per-call override; other HTTP methods untouched.
  • pr_actions.py — both PR comment fetches request application/vnd.github.full+json. New _select_rendered_body() helper returns body_text when the markdown body contains ${{ template syntax, otherwise preserves the markdown body so links and code formatting survive for normal human-authored comments.
  • pr_actions.pygithub_get_pr_reviews now surfaces the comment's diff_hunk in a fenced ```diff block (omitted when empty), giving callers the code context for inline suggestions.
  • registry_github.py — tool descriptions document the placeholder expansion and diff-hunk inclusion.
  • tests/unit/github/test_pr_actions.py — new test module (8 tests) covering placeholder→body_text fallback, markdown preservation, diff_hunk inclusion/omission, accept-header propagation, and empty-response handling for both functions.

Why this matters

Users running PR review automation against PRs that include bot-authored review suggestions previously saw ${{ metadata.patch }} verbatim in the response, which is unusable. The fix recovers the rendered patch and adds the diff hunk so the agent driving the review has enough context to act on the suggestion.

Test plan

  • pixi run -e quality lint — clean (ruff F/E9 zero violations on touched files)
  • pixi run -e quality test tests/unit/github/test_pr_actions.py — 8/8 pass
  • pixi run -e quality test — full suite green, no regressions
  • Manual verification against a real PR containing a Copilot review suggestion (recommended for reviewer)

Backward compatibility

  • GitHubClient.get() keyword-only accept defaults to the existing media type, so all other call sites are unaffected.
  • Output format for github_get_pr_comments is unchanged for non-bot comments (markdown body preserved).
  • Output format for github_get_pr_reviews adds an optional Diff hunk: block per comment when the API returns one. Existing parsers reading the human-readable text will see additional lines but no removed fields.

…tches

github_get_pr_reviews and github_get_pr_comments returned the raw
markdown `body` from the GitHub REST API. When a bot (Copilot review,
custom GitHub App) posts a comment whose body contains template
placeholders such as `${{ metadata.patch }}`, GitHub renders those
server-side ONLY when the response is requested with the
`application/vnd.github.full+json` media type, which adds `body_html`
and `body_text` to the payload. Callers therefore saw the un-expanded
template and had no way to recover the actual diff suggestion text.

Changes:

- client.py: GitHubClient.get() gains a keyword-only `accept`
  parameter (default unchanged) so callers can request alternate
  media types without affecting other endpoints.

- pr_actions.py: both PR comment fetches request the full media
  type. New _select_rendered_body() helper returns body_text when
  the markdown body contains `${{` template syntax, otherwise
  preserves the markdown body so links and code formatting survive
  for normal human-authored comments.

- pr_actions.py: github_get_pr_reviews now also surfaces the
  comment's diff_hunk in a fenced ```diff block. Inline review
  comments without diff context are common, so the hunk is omitted
  when empty.

- registry_github.py: tool descriptions note the placeholder
  expansion and diff-hunk inclusion so callers understand the
  rendered output.

- tests/unit/github/test_pr_actions.py: new test module covering
  template-placeholder fallback, markdown preservation, diff_hunk
  inclusion/omission, accept-header propagation, and empty-response
  handling for both functions (8 tests).

Full suite: 649 passed, 0 failed.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Claude finished @MementoRC's task —— View job


PR Review Complete ✅

This is a well-implemented fix for an important issue with GitHub bot template placeholder expansion. The code quality is high with good test coverage and attention to backward compatibility.

Task List:

  • Read repository guidelines (CLAUDE.md)
  • Analyze client.py changes
  • Review pr_actions.py modifications
  • Check registry_github.py updates
  • Examine test coverage and quality
  • Provide comprehensive feedback

Code Review Feedback

Strengths

1. Clean, Backward-Compatible Design

  • GitHubClient.get() keyword-only accept parameter maintains full backward compatibility
  • Smart fallback logic in _select_rendered_body() preserves markdown formatting for human comments
  • Well-documented behavior in tool descriptions

2. Excellent Test Coverage

  • Comprehensive test suite (8 tests) covering all critical scenarios
  • Tests both placeholder expansion and markdown preservation paths
  • Validates media type usage and empty response handling
  • Good use of helper functions and mocking

3. Proper Implementation Details

  • Correct media type application/vnd.github.full+json for template expansion
  • Diff hunk inclusion provides valuable context for review suggestions
  • Consistent error handling patterns across functions

🔍 Minor Observations

1. Code Quality & Style

  • Code follows consistent patterns and naming conventions
  • Good separation of concerns with the _select_rendered_body() helper
  • Clear docstrings and inline documentation

2. Security Considerations

  • No security concerns identified
  • Proper handling of API responses without exposing sensitive data
  • No injection vulnerabilities in string processing

3. Performance Considerations

  • Minimal performance impact - only affects PR comment/review fetches
  • Efficient string operations and conditional logic
  • No unnecessary API calls or data processing

📝 Detailed Analysis

client.py (src/mcp_server_git/github/client.py:43-58)

  • Clean keyword-only parameter addition maintains API compatibility
  • Default value preserves existing behavior for all other callers

pr_actions.py (src/mcp_server_git/github/pr_actions.py:11-28)

  • Smart template detection using _BOT_TEMPLATE_MARKER constant
  • Robust fallback logic handles edge cases (empty body_text)
  • Diff hunk formatting adds valuable context without breaking existing parsers

registry_github.py (src/mcp_server_git/lean/registry_github.py:249-275)

  • Documentation clearly explains the new placeholder expansion behavior
  • Tool descriptions are accurate and helpful for users

Test Coverage (tests/unit/github/test_pr_actions.py)

  • Comprehensive test scenarios covering both success and edge cases
  • Good test isolation with proper mocking
  • Clear test naming follows descriptive patterns

Overall Assessment

This PR successfully addresses a real user pain point where bot-generated review suggestions were unusable due to unexpanded template placeholders. The implementation is:

  • Well-designed: Backward compatible with smart fallback logic
  • Thoroughly tested: 8 comprehensive tests covering all scenarios
  • Properly documented: Clear descriptions and inline documentation
  • Performance-conscious: Minimal overhead, efficient implementation
  • Security-aware: No security concerns identified

The code follows established patterns in the codebase and maintains high quality standards. The fix will significantly improve the user experience when working with bot-generated PR reviews.

Recommendation: ✅ Approve - This PR is ready to merge. It's a solid implementation that solves an important problem without introducing any risks.


@MementoRC MementoRC merged commit ec5f21e into development May 5, 2026
16 checks passed
@MementoRC MementoRC deleted the fix/pr-review-bot-suggestions branch May 5, 2026 16:18
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