Add compare_commits tool#2855
Open
Kowshik4593 wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
compare_commitstool 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_commitscalls and reconciling SHAs client-side, which loses ahead/behind counts, merge-base info, and the unified file diff between the two points.What changed
compare_commits(GET /repos/{owner}/{repo}/compare/{base}...{head}) to therepostoolset, takingowner,repo,base,head, and pagination params.detailparameter (none/stats/full_patch) controlling how much per-file diff content is returned, mirroring the existingdetailparameter onget_commit.MinimalCommitsComparisonand its converter inpkg/github/minimal_types.go, trimminggithub.CommitsComparisonthe same waylist_commitstrims commit lists.pkg/github/tools.go.pkg/github/repositories_test.go(default/full_patch/nonedetail levels, missing-param, and API-error cases), plus a mock endpoint constant inpkg/github/helper_test.go.pkg/github/__toolsnaps__/compare_commits.snap).README.mdviascript/generate-docs.MCP impact
Prompts tested (tool changes only)
compare_commitswith defaultdetailcompare_commitswithdetail: full_patchcompare_commitswithdetail: noneSecurity / limits
Commit content is trimmed to
MinimalCommitsComparison(mirroringlist_commits/get_commit) to avoid returning the full, verbosegithub.CommitsComparisonpayload. Thedetailparameter lets callers opt out of per-file patch content, which can be large. Confidentiality follows repo visibility, consistent with the existinglist_commits/get_commitIFC labeling (ifc.LabelCommitContents).Tool renaming
Lint & tests
./script/lint(viagolangci-lint runat the CI-pinned v2.9.0)./script/test(go test ./...— full suite passes)Docs