Skip to content

[FEAT] add gh_pr_review tool to fetch PR review comments#13

Closed
four-bytes-robby wants to merge 2 commits into
mainfrom
feat/12-gh-pr-review-tool
Closed

[FEAT] add gh_pr_review tool to fetch PR review comments#13
four-bytes-robby wants to merge 2 commits into
mainfrom
feat/12-gh-pr-review-tool

Conversation

@four-bytes-robby

@four-bytes-robby four-bytes-robby commented Jun 14, 2026

Copy link
Copy Markdown
Member

Summary

Adds a new gh_pr_review tool that fetches review comments and review submissions from a GitHub pull request, returning structured output (author, state, body, timestamp) instead of raw gh pr view JSON.

Motivation

The supertools plugin could already add a PR comment (gh_pr_comment) and check PR status (gh_pr_status), but had no way to read review feedback. Code-reviewer subagents and humans had to scrape gh pr view via bash. This saves ~90% tokens on typical review-fetch flows.

Changes

  • src/tools/gh-pr-review.ts (new, 107 lines) — ghPrReviewTool exporting pr: number, repo?: string. Calls gh pr view <N> --json comments,reviews, parses, formats into two sections:
    • ## Reviews — formal review submissions, with state badge [APPROVED], [COMMENTED], [CHANGES_REQUESTED], author, timestamp, body (truncated to 500 chars). Empty-body reviews (bare approval clicks) are filtered out.
    • ## Comments — issue/timeline comments with author, timestamp, body (truncated to 300 chars).
    • Empty case: No review comments on PR #N.
  • src/four-opencode-supertools.ts — registered as gh_pr_review.

Notes

  • Confirmed via gh pr view --json that both comments and reviews are valid fields in current gh CLI.
  • Inline diff comments (with path/line) are NOT included in v1 — they require a separate GraphQL query against repository.pullRequest.reviews.comments. Out of scope for this PR; can be added as a follow-up if needed.
  • Follows the same patterns as existing gh-pr-comment.ts: runGh + resolveRepo from ../lib/gh-utils, logDebugEvent for observability.

Verification

  • bun run build — passes (31 modules bundled, 105.77 KB output)
  • bun test tests/gh-tools.test.ts — all 26 existing tests pass
  • npx eslint src/tools/gh-pr-review.ts — clean
  • bun run typecheck — no new errors (pre-existing gitlab-utils.ts(69,47) TS2339 is unrelated to this PR; confirmed by stashing changes)
  • Smoke-tested formatter against real data from anthropics/claude-code#1 (39 comments, 11 reviews) — output renders correctly with empty-body reviews filtered

Closes #12


Summary by cubic

Adds gh_pr_review to fetch GitHub PR review submissions and timeline comments, returning compact, structured text for easier consumption. Addresses #12 by enabling tools and subagents to read review feedback without scraping gh pr view.

  • New Features

    • Retrieves comments and reviews via gh pr view --json; outputs “Reviews” (state, author, timestamp, body) and “Comments”; truncates long bodies and filters empty-body approvals.
    • Accepts pr and optional repo; uses shared runGh/resolveRepo with debug logging.
    • Registered in src/four-opencode-supertools.ts as gh_pr_review; v1 excludes inline diff comments.
  • Bug Fixes

    • In gitlab-utils.ts, cast data to any when reading .message to fix a typecheck error in error handling.

Written for commit cbec041. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features
    • Added a GitHub PR review tool to the plugin system that retrieves and formats pull request comments and formal reviews in a structured, token-efficient format. Displays a clear message when there are no review comments or substantive reviews.
  • Bug Fixes
    • Improved GitLab API error handling to prefer the most relevant message field when requests fail.

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d2c1bfb7-3371-4c65-af77-418cd99f062b

📥 Commits

Reviewing files that changed from the base of the PR and between 4be8181 and cbec041.

📒 Files selected for processing (1)
  • src/lib/gitlab-utils.ts

📝 Walkthrough

Walkthrough

A new ghPrReviewTool is added in src/tools/gh-pr-review.ts. It accepts a PR number and optional repo, runs gh pr view to retrieve issue comments and formal reviews as JSON, filters out empty-body reviews, and returns formatted text or a "No review comments" message. The tool is imported and registered as gh_pr_review in the plugin's tool map. Additionally, GitLab API error message extraction is improved to prefer the message field from the parsed response payload.

Changes

gh_pr_review Tool

Layer / File(s) Summary
Tool implementation: fetch and format PR reviews
src/tools/gh-pr-review.ts
Defines and exports ghPrReviewTool with args { pr: number, repo?: string }. Resolves repo via resolveRepo, runs gh pr view <N> --json comments,reviews, JSON-parses results into typed shapes, filters reviews with empty/whitespace bodies, conditionally renders "Reviews" and "Comments" sections with author and timestamp, returns "No review comments" when both are absent, and logs start/success/error debug events. Returns an error string prefixed with "Error fetching PR comments: …" on exceptions.
Plugin registration
src/four-opencode-supertools.ts
Adds import for ghPrReviewTool and registers it in the plugin's tool map under the gh_pr_review key.

GitLab API Error Handling

Layer / File(s) Summary
Error message extraction
src/lib/gitlab-utils.ts
Updates gitlabApi's error field to extract the message from the parsed response payload using type-safe access (data as any)?.message instead of data?.message when HTTP response is not OK.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The GitLab utils change (error message extraction) appears unrelated to the gh_pr_review feature and issue #12 requirements, representing an out-of-scope modification. Remove the unrelated GitLab utils change from this PR or explain its necessity. The gh_pr_review feature implementation should focus solely on GitHub PR review functionality.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely describes the main change: adding the gh_pr_review tool to fetch PR review comments, which aligns perfectly with the changeset.
Linked Issues check ✅ Passed All acceptance criteria from issue #12 are met: new tool file exports ghPrReviewTool with correct signature (pr: number, repo?: string), formatted output includes comments and reviews with author/body/timestamp, empty bodies filtered, truncation implemented (500/300 chars), empty case handled, logging integrated, tool registered, and build verified.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/12-gh-pr-review-tool

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

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 2 files

Re-trigger cubic

@four-bytes-robby

Copy link
Copy Markdown
Member Author

The gh_pr_review tool was already merged via PR #19 (which fixed the bodyless-review bug). This PR's feature is superseded — closing as obsolete.

@four-bytes-robby four-bytes-robby deleted the feat/12-gh-pr-review-tool branch June 14, 2026 21:48
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.

[FEAT] add gh_pr_review tool to fetch PR review comments

1 participant