Skip to content

Commit 6c2a159

Browse files
Support pagination for get_issue_comments
1 parent f1813d7 commit 6c2a159

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

pkg/github/issues.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,12 @@ func getIssueComments(client *github.Client, t translations.TranslationHelperFun
613613
mcp.Required(),
614614
mcp.Description("Issue number"),
615615
),
616+
mcp.WithNumber("page",
617+
mcp.Description("Page number"),
618+
),
619+
mcp.WithNumber("per_page",
620+
mcp.Description("Number of records per page"),
621+
),
616622
),
617623
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
618624
owner, err := requiredParam[string](request, "owner")
@@ -627,10 +633,19 @@ func getIssueComments(client *github.Client, t translations.TranslationHelperFun
627633
if err != nil {
628634
return mcp.NewToolResultError(err.Error()), nil
629635
}
636+
page, err := optionalIntParamWithDefault(request, "page", 1)
637+
if err != nil {
638+
return mcp.NewToolResultError(err.Error()), nil
639+
}
640+
perPage, err := optionalIntParamWithDefault(request, "per_page", 30)
641+
if err != nil {
642+
return mcp.NewToolResultError(err.Error()), nil
643+
}
630644

631645
opts := &github.IssueListCommentsOptions{
632646
ListOptions: github.ListOptions{
633-
PerPage: 100,
647+
Page: page,
648+
PerPage: perPage,
634649
},
635650
}
636651

pkg/github/issues_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,8 @@ func Test_GetIssueComments(t *testing.T) {
995995
assert.Contains(t, tool.InputSchema.Properties, "owner")
996996
assert.Contains(t, tool.InputSchema.Properties, "repo")
997997
assert.Contains(t, tool.InputSchema.Properties, "issue_number")
998+
assert.Contains(t, tool.InputSchema.Properties, "page")
999+
assert.Contains(t, tool.InputSchema.Properties, "per_page")
9981000
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo", "issue_number"})
9991001

10001002
// Setup mock comments for success case
@@ -1041,6 +1043,29 @@ func Test_GetIssueComments(t *testing.T) {
10411043
expectError: false,
10421044
expectedComments: mockComments,
10431045
},
1046+
{
1047+
name: "successful comments retrieval with pagination",
1048+
mockedClient: mock.NewMockedHTTPClient(
1049+
mock.WithRequestMatchHandler(
1050+
mock.GetReposIssuesCommentsByOwnerByRepoByIssueNumber,
1051+
expectQueryParams(t, map[string]string{
1052+
"page": "2",
1053+
"per_page": "10",
1054+
}).andThen(
1055+
mockResponse(t, http.StatusOK, mockComments),
1056+
),
1057+
),
1058+
),
1059+
requestArgs: map[string]interface{}{
1060+
"owner": "owner",
1061+
"repo": "repo",
1062+
"issue_number": float64(42),
1063+
"page": float64(2),
1064+
"per_page": float64(10),
1065+
},
1066+
expectError: false,
1067+
expectedComments: mockComments,
1068+
},
10441069
{
10451070
name: "issue not found",
10461071
mockedClient: mock.NewMockedHTTPClient(

0 commit comments

Comments
 (0)