Skip to content

Add compare_commits tool#2855

Open
Kowshik4593 wants to merge 1 commit into
github:mainfrom
Kowshik4593:add-compare-commits-tool
Open

Add compare_commits tool#2855
Kowshik4593 wants to merge 1 commit into
github:mainfrom
Kowshik4593:add-compare-commits-tool

Conversation

@Kowshik4593

Copy link
Copy Markdown

Summary

Adds a compare_commits tool wrapping GitHub's "Compare two commits" REST endpoint, so agents can diff two branches, tags, or commit SHAs directly.

Why

Fixes #1910

Comparing two refs currently requires approximating it with two list_commits calls and reconciling SHAs client-side, which loses ahead/behind counts, merge-base info, and the unified file diff between the two points.

What changed

  • Added compare_commits (GET /repos/{owner}/{repo}/compare/{base}...{head}) to the repos toolset, taking owner, repo, base, head, and pagination params.
  • Added a detail parameter (none/stats/full_patch) controlling how much per-file diff content is returned, mirroring the existing detail parameter on get_commit.
  • Added MinimalCommitsComparison and its converter in pkg/github/minimal_types.go, trimming github.CommitsComparison the same way list_commits trims commit lists.
  • Registered the tool in pkg/github/tools.go.
  • Added table-driven tests in pkg/github/repositories_test.go (default/full_patch/none detail levels, missing-param, and API-error cases), plus a mock endpoint constant in pkg/github/helper_test.go.
  • Generated the toolsnap (pkg/github/__toolsnaps__/compare_commits.snap).
  • Regenerated README.md via script/generate-docs.

MCP impact

  • New tool added

Prompts tested (tool changes only)

  • "How many commits is my feature branch ahead of main?" → compare_commits with default detail
  • "Show me the full diff between commit abc123 and def456." → compare_commits with detail: full_patch
  • "Just tell me if release/2.0 has diverged from main, I don't need the file list." → compare_commits with detail: none

Security / limits

  • Data exposure, filtering, or token/size limits considered

Commit content is trimmed to MinimalCommitsComparison (mirroring list_commits/get_commit) to avoid returning the full, verbose github.CommitsComparison payload. The detail parameter lets callers opt out of per-file patch content, which can be large. Confidentiality follows repo visibility, consistent with the existing list_commits/get_commit IFC labeling (ifc.LabelCommitContents).

Tool renaming

  • I am renaming tools as part of this PR (e.g. a part of a consolidation effort)
  • I am not renaming tools as part of this PR

Lint & tests

  • Linted locally with ./script/lint (via golangci-lint run at the CI-pinned v2.9.0)
  • Tested locally with ./script/test (go test ./... — full suite passes)

Docs

  • Updated (README / docs / examples)

Adds a compare_commits tool wrapping the GitHub "Compare two commits"
REST endpoint (GET /repos/{owner}/{repo}/compare/{base}...{head}), so
agents can diff two branches, tags, or commit SHAs directly instead of
approximating it with two list_commits calls.

Returns ahead/behind counts, the commits unique to head, and the
changed files, trimmed via a new MinimalCommitsComparison type. A
`detail` parameter (none/stats/full_patch, matching get_commit)
controls how much per-file diff content is included.
@Kowshik4593 Kowshik4593 requested a review from a team as a code owner July 11, 2026 20:19
Copilot AI review requested due to automatic review settings July 11, 2026 20:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

Add compare_commits tool for branch/commit diff analysis

2 participants