8000 add author field to list_commits for filtering (#569) · github/github-mcp-server@f631ff5 · GitHub
[go: up one dir, main page]

Skip to content

Commit f631ff5

Browse files
authored
add author field to list_commits for filtering (#569)
1 parent 2711384 commit f631ff5

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
@@ -108,6 +108,9 @@ func ListCommits(getClient GetClientFn, t translations.TranslationHelperFunc) (t
108108
mcp.WithString("sha",
109109
mcp.Description("SHA or Branch name"),
110110
),
111+
mcp.WithString("author",
112+
mcp.Description("Author username or email address"),
113+
),
111114
WithPagination(),
112115
),
113116
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
@@ -123,13 +126,18 @@ func ListCommits(getClient GetClientFn, t translations.TranslationHelperFunc) (t
123126
if err != nil {
124127
return mcp.NewToolResultError(err.Error()), nil
125128
}
129+
author, err := OptionalParam[string](request, "author")
130+
if err != nil {
131+
return mcp.NewToolResultError(err.Error()), nil
132+
}
126133
pagination, err := OptionalPaginationParams(request)
127134
if err != nil {
128135
return mcp.NewToolResultError(err.Error()), nil
129136
}
130137

131138
opts := &github.CommitsListOptions{
132-
SHA: sha,
139+
SHA: sha,
140+
Author: author,
133141
ListOptions: github.ListOptions{
134142
Page: pagination.page,
135143
PerPage: pagination.perPage,

pkg/github/repositories_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ func Test_ListCommits(t *testing.T) {
646646
assert.Contains(t, tool.InputSchema.Properties, "owner")
647647
assert.Contains(t, tool.InputSchema.Properties, "repo")
648648
assert.Contains(t, tool.InputSchema.Properties, "sha")
649+
assert.Contains(t, tool.InputSchema.Properties, "author")
649650
assert.Contains(t, tool.InputSchema.Properties, "page")
650651
assert.Contains(t, tool.InputSchema.Properties, "perPage")
651652
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo"})
@@ -713,6 +714,7 @@ func Test_ListCommits(t *testing.T) {
713714
mock.WithRequestMatchHandler(
714715
mock.GetReposCommitsByOwnerByRepo,
715716
expectQueryParams(t, map[string]string{
717+
"author": "username",
716718
"sha": "main",
717719
"page": "1",
718720
"per_page": "30",
@@ -722,9 +724,10 @@ func Test_ListCommits(t *testing.T) {
722724
),
723725
),
724726
requestArgs: map[string]interface{}{
725-
"owner": "owner",
726-
"repo": "repo",
727-
"sha": "main",
727+
"owner": "owner",
728+
"repo": "repo",
729+
"sha": "main",
730+
"author": "username",
728731
},
729732
expectError: false,
730733
expectedCommits: mockCommits,
@@ -801,6 +804,7 @@ func Test_ListCommits(t *testing.T) {
801804
require.NoError(t, err)
802805
assert.Len(t, returnedCommits, len(tc.expectedCommits))
803806
for i, commit := range returnedCommits {
807+
assert.Equal(t, *tc.expectedCommits[i].Author, *commit.Author)
804808
assert.Equal(t, *tc.expectedCommits[i].SHA, *commit.SHA)
805809
assert.Equal(t, *tc.expectedCommits[i].Commit.Message, *commit.Commit.Message)
806810
assert.Equal(t, *tc.expectedCommits[i].Author.Login, *commit.Author.Login)

0 commit comments

Comments
 (0)
0