Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add pagination support to get_pull_request_files tool #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions pkg/github/__toolsnaps__/get_pull_request_files.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
"description": "Repository owner",
"type": "string"
},
"page": {
"description": "Page number for pagination (min 1)",
"minimum": 1,
"type": "number"
},
"perPage": {
"description": "Results per page for pagination (min 1, max 100)",
"maximum": 100,
"minimum": 1,
"type": "number"
},
"pullNumber": {
"description": "Pull request number",
"type": "number"
Expand Down
10 changes: 9 additions & 1 deletion pkg/github/pullrequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ func GetPullRequestFiles(getClient GetClientFn, t translations.TranslationHelper
mcp.Required(),
mcp.Description("Pull request number"),
),
WithPagination(),
),
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
owner, err := RequiredParam[string](request, "owner")
Expand All @@ -546,12 +547,19 @@ func GetPullRequestFiles(getClient GetClientFn, t translations.TranslationHelper
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
pagination, err := OptionalPaginationParams(request)
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

client, err := getClient(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
}
opts := &github.ListOptions{}
opts := &github.ListOptions{
PerPage: pagination.perPage,
Page: pagination.page,
}
files, resp, err := client.PullRequests.ListFiles(ctx, owner, repo, pullNumber, opts)
if err != nil {
return nil, fmt.Errorf("failed to get pull request files: %w", err)
Expand Down
20 changes: 20 additions & 0 deletions pkg/github/pullrequests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ func Test_GetPullRequestFiles(t *testing.T) {
assert.Contains(t, tool.InputSchema.Properties, "owner")
assert.Contains(t, tool.InputSchema.Properties, "repo")
assert.Contains(t, tool.InputSchema.Properties, "pullNumber")
assert.Contains(t, tool.InputSchema.Properties, "page")
assert.Contains(t, tool.InputSchema.Properties, "perPage")
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo", "pullNumber"})

// Setup mock PR files for success case
Expand Down Expand Up @@ -614,6 +616,24 @@ func Test_GetPullRequestFiles(t *testing.T) {
expectError: false,
expectedFiles: mockFiles,
},
{
name: "successful files fetch with pagination",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.GetReposPullsFilesByOwnerByRepoByPullNumber,
mockFiles,
),
),
requestArgs: map[string]interface{}{
"owner": "owner",
"repo": "repo",
"pullNumber": float64(42),
"page": float64(2),
"perPage": float64(10),
},
expectError: false,
expectedFiles: mockFiles,
},
{
name: "files fetch fails",
mockedClient: mock.NewMockedHTTPClient(
Expand Down