Skip to content

feat: Add get_commits method to pull_request_read#2608

Open
RossTarrant wants to merge 2 commits into
mainfrom
rosstarrant/add-get-commits-method
Open

feat: Add get_commits method to pull_request_read#2608
RossTarrant wants to merge 2 commits into
mainfrom
rosstarrant/add-get-commits-method

Conversation

@RossTarrant
Copy link
Copy Markdown
Contributor

Summary

Adds a get_commits method to pull_request_read so agents can list commits on a pull request. The response uses a compact PR-specific commit summary to keep the payload focused on commit-message review workflows.

Why

Fixes #2368

Review agents need access to the commits on a pull request so they can validate commit messages, for example checking whether commits follow Conventional Commits or another repository-specific format.

What changed

  • Added pull_request_read method get_commits.
  • Calls client.PullRequests.ListCommits() with existing page / perPage pagination support.
  • Added MinimalPullRequestCommit for a compact commit-list response.
  • Added unit coverage for success, pagination, error handling, and omitted noisy fields.
  • Updated pull_request_read toolsnap and generated README docs.

Response shape tradeoff

This PR uses a new lightweight MinimalPullRequestCommit instead of reusing the existing MinimalCommit type used by repository commit tools. MinimalCommit is a better fit for detailed commit views like get_commit, where nested git metadata, resolved GitHub users, stats, and files are useful.

For PR commit listing, the primary use case is commit-message inspection across multiple commits, so the new type avoids repeated author / committer blocks and resolved profile data that can quickly consume context without helping that workflow. If future use cases need richer commit details, callers can still fetch an individual commit through the existing repository commit tools.

Example tool/method response

[
  {
    "sha": "b1c3b16910cfa89f7d2f19e1c31b8db143938450",
    "html_url": "https://github.com/github/github-mcp-server/commit/b1c3b16910cfa89f7d2f19e1c31b8db143938450",
    "message": "feat: add pull request commit listing",
    "author": {
      "name": "Octocat",
      "email": "octocat@github.com",
      "date": "2026-06-05T08:30:00Z"
    }
  }
]

MCP impact

  • No tool or API changes
  • Tool schema or behavior changed
    • pull_request_read now accepts method: "get_commits" and returns a compact list of PR commits.
    • Toolsnaps were updated for the changed schema.
  • New tool added

Prompts tested (tool changes only)

  • "List the commits on pull request #XXX in github/github-mcp-server."
  • "Show me the commit messages for PR #XXX so I can review them."

Security / limits

  • No security or limits impact
  • Auth / permissions considered
    • Uses the existing repo scope required by pull_request_read.
  • Data exposure, filtering, or token/size limits considered
    • The response intentionally uses a compact commit summary and supports pagination.

Tool renaming

  • I am renaming tools as part of this PR (e.g. a part of a consolidation effort)
    • I have added the new tool aliases in deprecated_tool_aliases.go
  • I am not renaming tools as part of this PR

Lint & tests

  • Linted locally with ./script/lint
  • Tested locally with ./script/test

Docs

  • Not needed
  • Updated (README / docs / examples)

@RossTarrant RossTarrant requested a review from a team as a code owner June 5, 2026 08:04
Copilot AI review requested due to automatic review settings June 5, 2026 08:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new get_commits method to the existing pull_request_read tool so agents can list commits on a pull request with a compact, PR-focused response shape.

Changes:

  • Extended pull_request_read with method: "get_commits" and implemented GetPullRequestCommits using client.PullRequests.ListCommits() with existing page/perPage pagination.
  • Introduced MinimalPullRequestCommit and conversion helpers to return a lightweight commit list (sha, html_url, message, author).
  • Added unit tests plus updated the toolsnap and generated README tool docs to reflect the new method.
Show a summary per file
File Description
README.md Documents the new get_commits method under pull_request_read.
pkg/github/pullrequests.go Adds the get_commits dispatch case and implements GetPullRequestCommits.
pkg/github/pullrequests_test.go Adds unit coverage for get_commits (success, pagination, error).
pkg/github/minimal_types.go Adds MinimalPullRequestCommit and conversion logic for PR commit listing output.
pkg/github/helper_test.go Adds the REST route constant for the PR commits endpoint used by mocks.
pkg/github/toolsnaps/pull_request_read.snap Updates tool schema snapshot to include get_commits.

Copilot's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 1

Comment thread pkg/github/minimal_types.go
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.

pull_request_read.commits

2 participants