Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
- `owner`: Repository owner (string, required)
- `repo`: Repository name (string, required)
- `sha`: Branch name, tag, or commit SHA (string, optional)
- `author`: Author username or email address (string, optional)
- `path`: Only commits containing this file path (string, optional)
- `page`: Page number (number, optional)
- `perPage`: Results per page (number, optional)
Expand Down
4 changes: 4 additions & 0 deletions pkg/github/__toolsnaps__/list_commits.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
"sha": {
"description": "SHA or Branch name",
"type": "string"
},
"author": {
"description": "Author username or email address",
"type": "string"
}
},
"required": [
Expand Down
10 changes: 9 additions & 1 deletion pkg/github/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func ListCommits(getClient GetClientFn, t translations.TranslationHelperFunc) (t
mcp.WithString("sha",
mcp.Description("SHA or Branch name"),
),
mcp.WithString("author",
mcp.Description("Author username or email address"),
),
WithPagination(),
),
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
Expand All @@ -122,13 +125,18 @@ func ListCommits(getClient GetClientFn, t translations.TranslationHelperFunc) (t
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
author, err := OptionalParam[string](request, "author")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
pagination, err := OptionalPaginationParams(request)
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

opts := &github.CommitsListOptions{
SHA: sha,
SHA: sha,
Author: author,
ListOptions: github.ListOptions{
Page: pagination.page,
PerPage: pagination.perPage,
Expand Down
10 changes: 7 additions & 3 deletions pkg/github/repositories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ func Test_ListCommits(t *testing.T) {
assert.Contains(t, tool.InputSchema.Properties, "owner")
assert.Contains(t, tool.InputSchema.Properties, "repo")
assert.Contains(t, tool.InputSchema.Properties, "sha")
assert.Contains(t, tool.InputSchema.Properties, "author")
assert.Contains(t, tool.InputSchema.Properties, "page")
assert.Contains(t, tool.InputSchema.Properties, "perPage")
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo"})
Expand Down Expand Up @@ -712,6 +713,7 @@ func Test_ListCommits(t *testing.T) {
mock.WithRequestMatchHandler(
mock.GetReposCommitsByOwnerByRepo,
expectQueryParams(t, map[string]string{
"author": "username",
"sha": "main",
"page": "1",
"per_page": "30",
Expand All @@ -721,9 +723,10 @@ func Test_ListCommits(t *testing.T) {
),
),
requestArgs: map[string]interface{}{
"owner": "owner",
"repo": "repo",
"sha": "main",
"owner": "owner",
"repo": "repo",
"sha": "main",
"author": "username",
},
expectError: false,
expectedCommits: mockCommits,
Expand Down Expand Up @@ -800,6 +803,7 @@ func Test_ListCommits(t *testing.T) {
require.NoError(t, err)
assert.Len(t, returnedCommits, len(tc.expectedCommits))
for i, commit := range returnedCommits {
assert.Equal(t, *tc.expectedCommits[i].Author, *commit.Author)
assert.Equal(t, *tc.expectedCommits[i].SHA, *commit.SHA)
assert.Equal(t, *tc.expectedCommits[i].Commit.Message, *commit.Commit.Message)
assert.Equal(t, *tc.expectedCommits[i].Author.Login, *commit.Author.Login)
Expand Down