Skip to content

Commit 5d9c352

Browse files
TimurTimur
authored andcommitted
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.
1 parent 1820a0f commit 5d9c352

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

pkg/github/minimal_types.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type MinimalCommitFile struct {
7575
Additions int `json:"additions,omitempty"`
7676
Deletions int `json:"deletions,omitempty"`
7777
Changes int `json:"changes,omitempty"`
78+
Patch string `json:"patch,omitempty"`
7879
}
7980

8081
// MinimalCommit is the trimmed output type for commit objects.
@@ -173,7 +174,7 @@ func convertToMinimalUser(user *github.User) *MinimalUser {
173174
}
174175

175176
// convertToMinimalCommit converts a GitHub API RepositoryCommit to MinimalCommit
176-
func convertToMinimalCommit(commit *github.RepositoryCommit, includeDiffs bool) MinimalCommit {
177+
func convertToMinimalCommit(commit *github.RepositoryCommit, includeDiffs bool, includePatch bool) MinimalCommit {
177178
minimalCommit := MinimalCommit{
178179
SHA: commit.GetSHA(),
179180
HTMLURL: commit.GetHTMLURL(),
@@ -243,6 +244,9 @@ func convertToMinimalCommit(commit *github.RepositoryCommit, includeDiffs bool)
243244
Deletions: file.GetDeletions(),
244245
Changes: file.GetChanges(),
245246
}
247+
if includePatch {
248+
minimalFile.Patch = file.GetPatch()
249+
}
246250
minimalCommit.Files = append(minimalCommit.Files, minimalFile)
247251
}
248252
}

pkg/github/repositories.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,16 @@ func GetCommit(t translations.TranslationHelperFunc) inventory.ServerTool {
4545
Type: "string",
4646
Description: "Commit SHA, branch name, or tag name",
4747
},
48-
"include_diff": {
49-
Type: "boolean",
50-
Description: "Whether to include file diffs and stats in the response. Default is true.",
51-
Default: json.RawMessage(`true`),
52-
},
48+
"include_diff": {
49+
Type: "boolean",
50+
Description: "Whether to include file diffs and stats in the response. Default is true.",
51+
Default: json.RawMessage(`true`),
52+
},
53+
"include_patch": {
54+
Type: "boolean",
55+
Description: "Whether to include the patch (unified diff) content for each file. Only applies when include_diff is true. Default is false.",
56+
Default: json.RawMessage(`false`),
57+
},
5358
},
5459
Required: []string{"owner", "repo", "sha"},
5560
}),
@@ -72,6 +77,10 @@ func GetCommit(t translations.TranslationHelperFunc) inventory.ServerTool {
7277
if err != nil {
7378
return utils.NewToolResultError(err.Error()), nil, nil
7479
}
80+
includePatch, err := OptionalBoolParamWithDefault(args, "include_patch", false)
81+
if err != nil {
82+
return utils.NewToolResultError(err.Error()), nil, nil
83+
}
7584
pagination, err := OptionalPaginationParams(args)
7685
if err != nil {
7786
return utils.NewToolResultError(err.Error()), nil, nil
@@ -105,7 +114,7 @@ func GetCommit(t translations.TranslationHelperFunc) inventory.ServerTool {
105114
}
106115

107116
// Convert to minimal commit
108-
minimalCommit := convertToMinimalCommit(commit, includeDiff)
117+
minimalCommit := convertToMinimalCommit(commit, includeDiff, includePatch)
109118

110119
r, err := json.Marshal(minimalCommit)
111120
if err != nil {
@@ -212,7 +221,7 @@ func ListCommits(t translations.TranslationHelperFunc) inventory.ServerTool {
212221
// Convert to minimal commits
213222
minimalCommits := make([]MinimalCommit, len(commits))
214223
for i, commit := range commits {
215-
minimalCommits[i] = convertToMinimalCommit(commit, false)
224+
minimalCommits[i] = convertToMinimalCommit(commit, false, false)
216225
}
217226

218227
r, err := json.Marshal(minimalCommits)

0 commit comments

Comments
 (0)