From f631ff5548b14d5257d49b5a5b87c88796397994 Mon Sep 17 00:00:00 2001 From: David Byttow <1735553+davidbyttow@users.noreply.github.com> Date: Tue, 24 Jun 2025 03:15:25 -0400 Subject: [PATCH] add author field to list_commits for filtering (#569) --- README.md | 1 + pkg/github/__toolsnaps__/list_commits.snap | 4 ++++ pkg/github/repositories.go | 10 +++++++++- pkg/github/repositories_test.go | 10 +++++++--- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 14596650..9706ef66 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/pkg/github/__toolsnaps__/list_commits.snap b/pkg/github/__toolsnaps__/list_commits.snap index 7be03a7f..6603bdf5 100644 --- a/pkg/github/__toolsnaps__/list_commits.snap +++ b/pkg/github/__toolsnaps__/list_commits.snap @@ -28,6 +28,10 @@ "sha": { "description": "SHA or Branch name", "type": "string" + }, + "author": { + "description": "Author username or email address", + "type": "string" } }, "required": [ diff --git a/pkg/github/repositories.go b/pkg/github/repositories.go index 85fa2d7b..a943340f 100644 --- a/pkg/github/repositories.go +++ b/pkg/github/repositories.go @@ -108,6 +108,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) { @@ -123,13 +126,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, diff --git a/pkg/github/repositories_test.go b/pkg/github/repositories_test.go index 3f632120..7ce2fec1 100644 --- a/pkg/github/repositories_test.go +++ b/pkg/github/repositories_test.go @@ -646,6 +646,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"}) @@ -713,6 +714,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", @@ -722,9 +724,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, @@ -801,6 +804,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)