From 8ee25c737290312730d9401ca99667db990a5324 Mon Sep 17 00:00:00 2001 From: David Byttow Date: Sun, 22 Jun 2025 23:17:34 -0400 Subject: [PATCH] add author field to list_commits for filtering --- 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 145966505..9706ef664 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 7be03a7fe..6603bdf5b 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 3475167b1..ca0ea468f 100644 --- a/pkg/github/repositories.go +++ b/pkg/github/repositories.go @@ -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) { @@ -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, diff --git a/pkg/github/repositories_test.go b/pkg/github/repositories_test.go index 3ba0f1aa7..d04f7ca28 100644 --- a/pkg/github/repositories_test.go +++ b/pkg/github/repositories_test.go @@ -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"}) @@ -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", @@ -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, @@ -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) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy