fix(github): expand bot template placeholders in PR review/comment fetches#164
Conversation
…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.
|
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:
Code Review Feedback✅ Strengths1. Clean, Backward-Compatible Design
2. Excellent Test Coverage
3. Proper Implementation Details
🔍 Minor Observations1. Code Quality & Style
2. Security Considerations
3. Performance Considerations
📝 Detailed Analysisclient.py (
pr_actions.py (
registry_github.py (
Test Coverage (
✅ Overall AssessmentThis PR successfully addresses a real user pain point where bot-generated review suggestions were unusable due to unexpanded template placeholders. The implementation is:
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. |
Summary
github_get_pr_reviewsandgithub_get_pr_commentsreturned the raw markdownbodyfrom 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 theapplication/vnd.github.full+jsonmedia type (which addsbody_htmlandbody_textto the payload). Until now we always sentapplication/vnd.github.v3+json, so callers received the un-expanded template and had no way to recover the actual diff suggestion content.Changes
client.py—GitHubClient.get()gains a keyword-onlyacceptparameter (default unchanged). Backward-compatible per-call override; other HTTP methods untouched.pr_actions.py— both PR comment fetches requestapplication/vnd.github.full+json. New_select_rendered_body()helper returnsbody_textwhen the markdown body contains${{template syntax, otherwise preserves the markdownbodyso links and code formatting survive for normal human-authored comments.pr_actions.py—github_get_pr_reviewsnow surfaces the comment'sdiff_hunkin 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 passpixi run -e quality test— full suite green, no regressionsBackward compatibility
GitHubClient.get()keyword-onlyacceptdefaults to the existing media type, so all other call sites are unaffected.github_get_pr_commentsis unchanged for non-bot comments (markdown body preserved).github_get_pr_reviewsadds an optionalDiff hunk:block per comment when the API returns one. Existing parsers reading the human-readable text will see additional lines but no removed fields.