Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/github/minimal_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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)
}
}
Expand Down
23 changes: 16 additions & 7 deletions pkg/github/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}),
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down