Skip to content

Commit 8ee25c7

Browse files
committed
add author field to list_commits for filtering
1 parent 3fe88ee commit 8ee25c7

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
705705
- `owner`: Repository owner (string, required)
706706
- `repo`: Repository name (string, required)
707707
- `sha`: Branch name, tag, or commit SHA (string, optional)
708+
- `author`: Author username or email address (string, optional)
708709
- `path`: Only commits containing this file path (string, optional)
709710
- `page`: Page number (number, optional)
710711
- `perPage`: Results per page (number, optional)

pkg/github/__toolsnaps__/list_commits.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
"sha": {
2929
"description": "SHA or Branch name",
3030
"type": "string"
31+
},
32+
"author": {
33+
"description": "Author username or email address",
34+
"type": "string"
3135
}
3236
},
3337
"required": [

pkg/github/repositories.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ func ListCommits(getClient GetClientFn, t translations.TranslationHelperFunc) (t
107107
mcp.WithString("sha",
108108
mcp.Description("SHA or Branch name"),
109109
),
110+
mcp.WithString("author",
111+
mcp.Description("Author username or email address"),
112+
),
110113
WithPagination(),
111114
),
112115
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
@@ -122,13 +125,18 @@ func ListCommits(getClient GetClientFn, t translations.TranslationHelperFunc) (t
122125
if err != nil {
123126
return mcp.NewToolResultError(err.Error()), nil
124127
}
128+
author, err := OptionalParam[string](request, "author")
129+
if err != nil {
130+
return mcp.NewToolResultError(err.Error()), nil
131+
}
125132
pagination, err := OptionalPaginationParams(request)
126133
if err != nil {
127134
return mcp.NewToolResultError(err.Error()), nil
128135
}
129136

130137
opts := &github.CommitsListOptions{
131-
SHA: sha,
138+
SHA: sha,
139+
Author: author,
132140
ListOptions: github.ListOptions{
133141
Page: pagination.page,
134142
PerPage: pagination.perPage,

pkg/github/repositories_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ func Test_ListCommits(t *testing.T) {
645645
assert.Contains(t, tool.InputSchema.Properties, "owner")
646646
assert.Contains(t, tool.InputSchema.Properties, "repo")
647647
assert.Contains(t, tool.InputSchema.Properties, "sha")
648+
assert.Contains(t, tool.InputSchema.Properties, "author")
648649
assert.Contains(t, tool.InputSchema.Properties, "page")
649650
assert.Contains(t, tool.InputSchema.Properties, "perPage")
650651
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo"})
@@ -712,6 +713,7 @@ func Test_ListCommits(t *testing.T) {
712713
mock.WithRequestMatchHandler(
713714
mock.GetReposCommitsByOwnerByRepo,
714715
expectQueryParams(t, map[string]string{
716+
"author": "username",
715717
"sha": "main",
716718
"page": "1",
717719
"per_page": "30",
@@ -721,9 +723,10 @@ func Test_ListCommits(t *testing.T) {
721723
),
722724
),
723725
requestArgs: map[string]interface{}{
724-
"owner": "owner",
725-
"repo": "repo",
726-
"sha": "main",
726+
"owner": "owner",
727+
"repo": "repo",
728+
"sha": "main",
729+
"author": "username",
727730
},
728731
expectError: false,
729732
expectedCommits: mockCommits,
@@ -800,6 +803,7 @@ func Test_ListCommits(t *testing.T) {
800803
require.NoError(t, err)
801804
assert.Len(t, returnedCommits, len(tc.expectedCommits))
802805
for i, commit := range returnedCommits {
806+
assert.Equal(t, *tc.expectedCommits[i].Author, *commit.Author)
803807
assert.Equal(t, *tc.expectedCommits[i].SHA, *commit.SHA)
804808
assert.Equal(t, *tc.expectedCommits[i].Commit.Message, *commit.Commit.Message)
805809
assert.Equal(t, *tc.expectedCommits[i].Author.Login, *commit.Author.Login)

0 commit comments

Comments
 (0)