From 5d9c3526b3e70077b8c856ed39b9d46d46197175 Mon Sep 17 00:00:00 2001 From: Timur Date: Thu, 29 Jan 2026 13:28:24 +0400 Subject: [PATCH] feat: add include_patch parameter to get_commit tool Add a new optional parameter `include_patch` (default: false) to the get_commit tool that controls whether the patch/diff content is included for each file in the response. This is a non-breaking change: - Existing behavior is preserved (patch not included by default) - Users can opt-in by setting include_patch: true - Only applies when include_diff is also true Changes: - Added `Patch` field to MinimalCommitFile struct - Added `include_patch` parameter to get_commit tool schema - Updated convertToMinimalCommit to accept includePatch parameter - Patch content is only included when explicitly requested Use case: AI agents and code review tools that need to analyze actual code changes without additional API calls. --- pkg/github/minimal_types.go | 6 +++++- pkg/github/repositories.go | 23 ++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/pkg/github/minimal_types.go b/pkg/github/minimal_types.go index c6a0ea849..f43fb7d83 100644 --- a/pkg/github/minimal_types.go +++ b/pkg/github/minimal_types.go @@ -75,6 +75,7 @@ type MinimalCommitFile struct { Additions int `json:"additions,omitempty"` Deletions int `json:"deletions,omitempty"` Changes int `json:"changes,omitempty"` + Patch string `json:"patch,omitempty"` } // MinimalCommit is the trimmed output type for commit objects. @@ -173,7 +174,7 @@ func convertToMinimalUser(user *github.User) *MinimalUser { } // convertToMinimalCommit converts a GitHub API RepositoryCommit to MinimalCommit -func convertToMinimalCommit(commit *github.RepositoryCommit, includeDiffs bool) MinimalCommit { +func convertToMinimalCommit(commit *github.RepositoryCommit, includeDiffs bool, includePatch bool) MinimalCommit { minimalCommit := MinimalCommit{ SHA: commit.GetSHA(), HTMLURL: commit.GetHTMLURL(), @@ -243,6 +244,9 @@ func convertToMinimalCommit(commit *github.RepositoryCommit, includeDiffs bool) Deletions: file.GetDeletions(), Changes: file.GetChanges(), } + if includePatch { + minimalFile.Patch = file.GetPatch() + } minimalCommit.Files = append(minimalCommit.Files, minimalFile) } } diff --git a/pkg/github/repositories.go b/pkg/github/repositories.go index f6203f39f..a5c71c2a8 100644 --- a/pkg/github/repositories.go +++ b/pkg/github/repositories.go @@ -45,11 +45,16 @@ func GetCommit(t translations.TranslationHelperFunc) inventory.ServerTool { Type: "string", Description: "Commit SHA, branch name, or tag name", }, - "include_diff": { - Type: "boolean", - Description: "Whether to include file diffs and stats in the response. Default is true.", - Default: json.RawMessage(`true`), - }, + "include_diff": { + Type: "boolean", + Description: "Whether to include file diffs and stats in the response. Default is true.", + Default: json.RawMessage(`true`), + }, + "include_patch": { + Type: "boolean", + Description: "Whether to include the patch (unified diff) content for each file. Only applies when include_diff is true. Default is false.", + Default: json.RawMessage(`false`), + }, }, Required: []string{"owner", "repo", "sha"}, }), @@ -72,6 +77,10 @@ func GetCommit(t translations.TranslationHelperFunc) inventory.ServerTool { if err != nil { return utils.NewToolResultError(err.Error()), nil, nil } + includePatch, err := OptionalBoolParamWithDefault(args, "include_patch", false) + if err != nil { + return utils.NewToolResultError(err.Error()), nil, nil + } pagination, err := OptionalPaginationParams(args) if err != nil { return utils.NewToolResultError(err.Error()), nil, nil @@ -105,7 +114,7 @@ func GetCommit(t translations.TranslationHelperFunc) inventory.ServerTool { } // Convert to minimal commit - minimalCommit := convertToMinimalCommit(commit, includeDiff) + minimalCommit := convertToMinimalCommit(commit, includeDiff, includePatch) r, err := json.Marshal(minimalCommit) if err != nil { @@ -212,7 +221,7 @@ func ListCommits(t translations.TranslationHelperFunc) inventory.ServerTool { // Convert to minimal commits minimalCommits := make([]MinimalCommit, len(commits)) for i, commit := range commits { - minimalCommits[i] = convertToMinimalCommit(commit, false) + minimalCommits[i] = convertToMinimalCommit(commit, false, false) } r, err := json.Marshal(minimalCommits)