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

Skip to content

Commit 23b16cf

Browse files
anant-rustagiAnant rustagi
andauthored
feat: add pagination support to get_pull_request_files tool (#561)
- Add WithPagination() to tool definition - Use OptionalPaginationParams to handle page and perPage parameters - Pass pagination parameters to GitHub API ListFiles call - Update tests to include pagination scenarios - Update tool schema snapshot Fixes #527 Co-authored-by: Anant rustagi <[email protected]>
1 parent 2a2df24 commit 23b16cf

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

pkg/github/__toolsnaps__/get_pull_request_files.snap

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
"description": "Repository owner",
1111
"type": "string"
1212
},
13+
"page": {
14+
"description": "Page number for pagination (min 1)",
15+
"minimum": 1,
16+
"type": "number"
17+
},
18+
"perPage": {
19+
"description": "Results per page for pagination (min 1, max 100)",
20+
"maximum": 100,
21+
"minimum": 1,
22+
"type": "number"
23+
},
1324
"pullNumber": {
1425
"description": "Pull request number",
1526
"type": "number"

pkg/github/pullrequests.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ func GetPullRequestFiles(getClient GetClientFn, t translations.TranslationHelper
553553
mcp.Required(),
554554
mcp.Description("Pull request number"),
555555
),
556+
WithPagination(),
556557
),
557558
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
558559
owner, err := RequiredParam[string](request, "owner")
@@ -567,12 +568,19 @@ func GetPullRequestFiles(getClient GetClientFn, t translations.TranslationHelper
567568
if err != nil {
568569
return mcp.NewToolResultError(err.Error()), nil
569570
}
571+
pagination, err := OptionalPaginationParams(request)
572+
if err != nil {
573+
return mcp.NewToolResultError(err.Error()), nil
574+
}
570575

571576
client, err := getClient(ctx)
572577
if err != nil {
573578
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
574579
}
575-
opts := &github.ListOptions{}
580+
opts := &github.ListOptions{
581+
PerPage: pagination.perPage,
582+
Page: pagination.page,
583+
}
576584
files, resp, err := client.PullRequests.ListFiles(ctx, owner, repo, pullNumber, opts)
577585
if err != nil {
578586
return ghErrors.NewGitHubAPIErrorResponse(ctx,

pkg/github/pullrequests_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@ func Test_GetPullRequestFiles(t *testing.T) {
576576
assert.Contains(t, tool.InputSchema.Properties, "owner")
577577
assert.Contains(t, tool.InputSchema.Properties, "repo")
578578
assert.Contains(t, tool.InputSchema.Properties, "pullNumber")
579+
assert.Contains(t, tool.InputSchema.Properties, "page")
580+
assert.Contains(t, tool.InputSchema.Properties, "perPage")
579581
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo", "pullNumber"})
580582

581583
// Setup mock PR files for success case
@@ -622,6 +624,24 @@ func Test_GetPullRequestFiles(t *testing.T) {
622624
expectError: false,
623625
expectedFiles: mockFiles,
624626
},
627+
{
628+
name: "successful files fetch with pagination",
629+
mockedClient: mock.NewMockedHTTPClient(
630+
mock.WithRequestMatch(
631+
mock.GetReposPullsFilesByOwnerByRepoByPullNumber,
632+
mockFiles,
633+
),
634+
),
635+
requestArgs: map[string]interface{}{
636+
"owner": "owner",
637+
"repo": "repo",
638+
"pullNumber": float64(42),
639+
"page": float64(2),
640+
"perPage": float64(10),
641+
},
642+
expectError: false,
643+
expectedFiles: mockFiles,
644+
},
625645
{
626646
name: "files fetch fails",
627647
mockedClient: mock.NewMockedHTTPClient(

0 commit comments

Comments
 (0)