Skip to content

Commit d90d894

Browse files
authored
Merge branch 'main' into add-pr-search
2 parents 0c4c71c + 23b16cf commit d90d894

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
@@ -641,6 +641,7 @@ func GetPullRequestFiles(getClient GetClientFn, t translations.TranslationHelper
641641
mcp.Required(),
642642
mcp.Description("Pull request number"),
643643
),
644+
WithPagination(),
644645
),
645646
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
646647
owner, err := RequiredParam[string](request, "owner")
@@ -655,12 +656,19 @@ func GetPullRequestFiles(getClient GetClientFn, t translations.TranslationHelper
655656
if err != nil {
656657
return mcp.NewToolResultError(err.Error()), nil
657658
}
659+
pagination, err := OptionalPaginationParams(request)
660+
if err != nil {
661+
return mcp.NewToolResultError(err.Error()), nil
662+
}
658663

659664
client, err := getClient(ctx)
660665
if err != nil {
661666
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
662667
}
663-
opts := &github.ListOptions{}
668+
opts := &github.ListOptions{
669+
PerPage: pagination.perPage,
670+
Page: pagination.page,
671+
}
664672
files, resp, err := client.PullRequests.ListFiles(ctx, owner, repo, pullNumber, opts)
665673
if err != nil {
666674
return ghErrors.NewGitHubAPIErrorResponse(ctx,

pkg/github/pullrequests_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,8 @@ func Test_GetPullRequestFiles(t *testing.T) {
732732
assert.Contains(t, tool.InputSchema.Properties, "owner")
733733
assert.Contains(t, tool.InputSchema.Properties, "repo")
734734
assert.Contains(t, tool.InputSchema.Properties, "pullNumber")
735+
assert.Contains(t, tool.InputSchema.Properties, "page")
736+
assert.Contains(t, tool.InputSchema.Properties, "perPage")
735737
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo", "pullNumber"})
736738

737739
// Setup mock PR files for success case
@@ -778,6 +780,24 @@ func Test_GetPullRequestFiles(t *testing.T) {
778780
expectError: false,
779781
expectedFiles: mockFiles,
780782
},
783+
{
784+
name: "successful files fetch with pagination",
785+
mockedClient: mock.NewMockedHTTPClient(
786+
mock.WithRequestMatch(
787+
mock.GetReposPullsFilesByOwnerByRepoByPullNumber,
788+
mockFiles,
789+
),
790+
),
791+
requestArgs: map[string]interface{}{
792+
"owner": "owner",
793+
"repo": "repo",
794+
"pullNumber": float64(42),
795+
"page": float64(2),
796+
"perPage": float64(10),
797+
},
798+
expectError: false,
799+
expectedFiles: mockFiles,
800+
},
781801
{
782802
name: "files fetch fails",
783803
mockedClient: mock.NewMockedHTTPClient(

0 commit comments

Comments
 (0)