Skip to content

Commit 7e0bb3c

Browse files
authored
Merge branch 'main' into feat/131-support-brew-install
2 parents eefe118 + ff1f16e commit 7e0bb3c

File tree

12 files changed

+192
-125
lines changed

12 files changed

+192
-125
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
227227
- `sort`: Sort field (string, optional)
228228
- `order`: Sort order (string, optional)
229229
- `page`: Page number (number, optional)
230-
- `per_page`: Results per page (number, optional)
230+
- `perPage`: Results per page (number, optional)
231231

232232
### Pull Requests
233233

pkg/github/issues.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,7 @@ func searchIssues(client *github.Client, t translations.TranslationHelperFunc) (
162162
mcp.Description("Sort order ('asc' or 'desc')"),
163163
mcp.Enum("asc", "desc"),
164164
),
165-
mcp.WithNumber("per_page",
166-
mcp.Description("Results per page (max 100)"),
167-
mcp.Min(1),
168-
mcp.Max(100),
169-
),
170-
mcp.WithNumber("page",
171-
mcp.Description("Page number"),
172-
mcp.Min(1),
173-
),
165+
withPagination(),
174166
),
175167
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
176168
query, err := requiredParam[string](request, "q")
@@ -185,11 +177,7 @@ func searchIssues(client *github.Client, t translations.TranslationHelperFunc) (
185177
if err != nil {
186178
return mcp.NewToolResultError(err.Error()), nil
187179
}
188-
perPage, err := optionalIntParamWithDefault(request, "per_page", 30)
189-
if err != nil {
190-
return mcp.NewToolResultError(err.Error()), nil
191-
}
192-
page, err := optionalIntParamWithDefault(request, "page", 1)
180+
pagination, err := optionalPaginationParams(request)
193181
if err != nil {
194182
return mcp.NewToolResultError(err.Error()), nil
195183
}
@@ -198,8 +186,8 @@ func searchIssues(client *github.Client, t translations.TranslationHelperFunc) (
198186
Sort: sort,
199187
Order: order,
200188
ListOptions: github.ListOptions{
201-
PerPage: perPage,
202-
Page: page,
189+
PerPage: pagination.perPage,
190+
Page: pagination.page,
203191
},
204192
}
205193

@@ -375,12 +363,7 @@ func listIssues(client *github.Client, t translations.TranslationHelperFunc) (to
375363
mcp.WithString("since",
376364
mcp.Description("Filter by date (ISO 8601 timestamp)"),
377365
),
378-
mcp.WithNumber("page",
379-
mcp.Description("Page number"),
380-
),
381-
mcp.WithNumber("per_page",
382-
mcp.Description("Results per page"),
383-
),
366+
withPagination(),
384367
),
385368
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
386369
owner, err := requiredParam[string](request, "owner")
@@ -432,7 +415,7 @@ func listIssues(client *github.Client, t translations.TranslationHelperFunc) (to
432415
opts.Page = int(page)
433416
}
434417

435-
if perPage, ok := request.Params.Arguments["per_page"].(float64); ok {
418+
if perPage, ok := request.Params.Arguments["perPage"].(float64); ok {
436419
opts.PerPage = int(perPage)
437420
}
438421

pkg/github/issues_test.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func Test_SearchIssues(t *testing.T) {
244244
assert.Contains(t, tool.InputSchema.Properties, "q")
245245
assert.Contains(t, tool.InputSchema.Properties, "sort")
246246
assert.Contains(t, tool.InputSchema.Properties, "order")
247-
assert.Contains(t, tool.InputSchema.Properties, "per_page")
247+
assert.Contains(t, tool.InputSchema.Properties, "perPage")
248248
assert.Contains(t, tool.InputSchema.Properties, "page")
249249
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"q"})
250250

@@ -289,17 +289,28 @@ func Test_SearchIssues(t *testing.T) {
289289
{
290290
name: "successful issues search with all parameters",
291291
mockedClient: mock.NewMockedHTTPClient(
292-
mock.WithRequestMatch(
292+
mock.WithRequestMatchHandler(
293293
mock.GetSearchIssues,
294-
mockSearchResult,
294+
expectQueryParams(
295+
t,
296+
map[string]string{
297+
"q": "repo:owner/repo is:issue is:open",
298+
"sort": "created",
299+
"order": "desc",
300+
"page": "1",
301+
"per_page": "30",
302+
},
303+
).andThen(
304+
mockResponse(t, http.StatusOK, mockSearchResult),
305+
),
295306
),
296307
),
297308
requestArgs: map[string]interface{}{
298-
"q": "repo:owner/repo is:issue is:open",
299-
"sort": "created",
300-
"order": "desc",
301-
"page": float64(1),
302-
"per_page": float64(30),
309+
"q": "repo:owner/repo is:issue is:open",
310+
"sort": "created",
311+
"order": "desc",
312+
"page": float64(1),
313+
"perPage": float64(30),
303314
},
304315
expectError: false,
305316
expectedResult: mockSearchResult,
@@ -567,7 +578,7 @@ func Test_ListIssues(t *testing.T) {
567578
assert.Contains(t, tool.InputSchema.Properties, "direction")
568579
assert.Contains(t, tool.InputSchema.Properties, "since")
569580
assert.Contains(t, tool.InputSchema.Properties, "page")
570-
assert.Contains(t, tool.InputSchema.Properties, "per_page")
581+
assert.Contains(t, tool.InputSchema.Properties, "perPage")
571582
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo"})
572583

573584
// Setup mock issues for success case
@@ -641,7 +652,7 @@ func Test_ListIssues(t *testing.T) {
641652
"direction": "desc",
642653
"since": "2023-01-01T00:00:00Z",
643654
"page": float64(1),
644-
"per_page": float64(30),
655+
"perPage": float64(30),
645656
},
646657
expectError: false,
647658
expectedIssues: mockIssues,

pkg/github/pullrequests.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,7 @@ func listPullRequests(client *github.Client, t translations.TranslationHelperFun
9494
mcp.WithString("direction",
9595
mcp.Description("Sort direction ('asc', 'desc')"),
9696
),
97-
mcp.WithNumber("per_page",
98-
mcp.Description("Results per page (max 100)"),
99-
),
100-
mcp.WithNumber("page",
101-
mcp.Description("Page number"),
102-
),
97+
withPagination(),
10398
),
10499
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
105100
owner, err := requiredParam[string](request, "owner")
@@ -130,11 +125,7 @@ func listPullRequests(client *github.Client, t translations.TranslationHelperFun
130125
if err != nil {
131126
return mcp.NewToolResultError(err.Error()), nil
132127
}
133-
perPage, err := optionalIntParamWithDefault(request, "per_page", 30)
134-
if err != nil {
135-
return mcp.NewToolResultError(err.Error()), nil
136-
}
137-
page, err := optionalIntParamWithDefault(request, "page", 1)
128+
pagination, err := optionalPaginationParams(request)
138129
if err != nil {
139130
return mcp.NewToolResultError(err.Error()), nil
140131
}
@@ -146,8 +137,8 @@ func listPullRequests(client *github.Client, t translations.TranslationHelperFun
146137
Sort: sort,
147138
Direction: direction,
148139
ListOptions: github.ListOptions{
149-
PerPage: perPage,
150-
Page: page,
140+
PerPage: pagination.perPage,
141+
Page: pagination.page,
151142
},
152143
}
153144

pkg/github/pullrequests_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func Test_ListPullRequests(t *testing.T) {
140140
assert.Contains(t, tool.InputSchema.Properties, "base")
141141
assert.Contains(t, tool.InputSchema.Properties, "sort")
142142
assert.Contains(t, tool.InputSchema.Properties, "direction")
143-
assert.Contains(t, tool.InputSchema.Properties, "per_page")
143+
assert.Contains(t, tool.InputSchema.Properties, "perPage")
144144
assert.Contains(t, tool.InputSchema.Properties, "page")
145145
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo"})
146146

@@ -190,7 +190,7 @@ func Test_ListPullRequests(t *testing.T) {
190190
"state": "all",
191191
"sort": "created",
192192
"direction": "desc",
193-
"per_page": float64(30),
193+
"perPage": float64(30),
194194
"page": float64(1),
195195
},
196196
expectError: false,

pkg/github/repositories.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ func listCommits(client *github.Client, t translations.TranslationHelperFunc) (t
2828
mcp.WithString("sha",
2929
mcp.Description("Branch name"),
3030
),
31-
mcp.WithNumber("page",
32-
mcp.Description("Page number"),
33-
),
34-
mcp.WithNumber("perPage",
35-
mcp.Description("Number of records per page"),
36-
),
31+
withPagination(),
3732
),
3833
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
3934
owner, err := requiredParam[string](request, "owner")
@@ -48,20 +43,16 @@ func listCommits(client *github.Client, t translations.TranslationHelperFunc) (t
4843
if err != nil {
4944
return mcp.NewToolResultError(err.Error()), nil
5045
}
51-
page, err := optionalIntParamWithDefault(request, "page", 1)
52-
if err != nil {
53-
return mcp.NewToolResultError(err.Error()), nil
54-
}
55-
perPage, err := optionalIntParamWithDefault(request, "per_page", 30)
46+
pagination, err := optionalPaginationParams(request)
5647
if err != nil {
5748
return mcp.NewToolResultError(err.Error()), nil
5849
}
5950

6051
opts := &github.CommitsListOptions{
6152
SHA: sha,
6253
ListOptions: github.ListOptions{
63-
Page: page,
64-
PerPage: perPage,
54+
Page: pagination.page,
55+
PerPage: pagination.perPage,
6556
},
6657
}
6758

pkg/github/repositories_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,10 @@ func Test_ListCommits(t *testing.T) {
582582
),
583583
),
584584
requestArgs: map[string]interface{}{
585-
"owner": "owner",
586-
"repo": "repo",
587-
"page": float64(2),
588-
"per_page": float64(10),
585+
"owner": "owner",
586+
"repo": "repo",
587+
"page": float64(2),
588+
"perPage": float64(10),
589589
},
590590
expectError: false,
591591
expectedCommits: mockCommits,

pkg/github/repository_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func getRepositoryResourcePrContent(client *github.Client, t translations.Transl
6464

6565
func repositoryResourceContentsHandler(client *github.Client) func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
6666
return func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
67-
// the matcher will give []string with one elemenent
67+
// the matcher will give []string with one element
6868
// https://github.com/mark3labs/mcp-go/pull/54
6969
o, ok := request.Params.Arguments["owner"].([]string)
7070
if !ok || len(o) == 0 {

pkg/github/search.go

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,22 @@ func searchRepositories(client *github.Client, t translations.TranslationHelperF
2020
mcp.Required(),
2121
mcp.Description("Search query"),
2222
),
23-
mcp.WithNumber("page",
24-
mcp.Description("Page number for pagination"),
25-
),
26-
mcp.WithNumber("perPage",
27-
mcp.Description("Results per page (max 100)"),
28-
),
23+
withPagination(),
2924
),
3025
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
3126
query, err := requiredParam[string](request, "query")
3227
if err != nil {
3328
return mcp.NewToolResultError(err.Error()), nil
3429
}
35-
page, err := optionalIntParamWithDefault(request, "page", 1)
36-
if err != nil {
37-
return mcp.NewToolResultError(err.Error()), nil
38-
}
39-
perPage, err := optionalIntParamWithDefault(request, "perPage", 30)
30+
pagination, err := optionalPaginationParams(request)
4031
if err != nil {
4132
return mcp.NewToolResultError(err.Error()), nil
4233
}
4334

4435
opts := &github.SearchOptions{
4536
ListOptions: github.ListOptions{
46-
Page: page,
47-
PerPage: perPage,
37+
Page: pagination.page,
38+
PerPage: pagination.perPage,
4839
},
4940
}
5041

@@ -86,15 +77,7 @@ func searchCode(client *github.Client, t translations.TranslationHelperFunc) (to
8677
mcp.Description("Sort order ('asc' or 'desc')"),
8778
mcp.Enum("asc", "desc"),
8879
),
89-
mcp.WithNumber("per_page",
90-
mcp.Description("Results per page (max 100)"),
91-
mcp.Min(1),
92-
mcp.Max(100),
93-
),
94-
mcp.WithNumber("page",
95-
mcp.Description("Page number"),
96-
mcp.Min(1),
97-
),
80+
withPagination(),
9881
),
9982
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
10083
query, err := requiredParam[string](request, "q")
@@ -109,11 +92,7 @@ func searchCode(client *github.Client, t translations.TranslationHelperFunc) (to
10992
if err != nil {
11093
return mcp.NewToolResultError(err.Error()), nil
11194
}
112-
perPage, err := optionalIntParamWithDefault(request, "per_page", 30)
113-
if err != nil {
114-
return mcp.NewToolResultError(err.Error()), nil
115-
}
116-
page, err := optionalIntParamWithDefault(request, "page", 1)
95+
pagination, err := optionalPaginationParams(request)
11796
if err != nil {
11897
return mcp.NewToolResultError(err.Error()), nil
11998
}
@@ -122,8 +101,8 @@ func searchCode(client *github.Client, t translations.TranslationHelperFunc) (to
122101
Sort: sort,
123102
Order: order,
124103
ListOptions: github.ListOptions{
125-
PerPage: perPage,
126-
Page: page,
104+
PerPage: pagination.perPage,
105+
Page: pagination.page,
127106
},
128107
}
129108

@@ -166,15 +145,7 @@ func searchUsers(client *github.Client, t translations.TranslationHelperFunc) (t
166145
mcp.Description("Sort order ('asc' or 'desc')"),
167146
mcp.Enum("asc", "desc"),
168147
),
169-
mcp.WithNumber("per_page",
170-
mcp.Description("Results per page (max 100)"),
171-
mcp.Min(1),
172-
mcp.Max(100),
173-
),
174-
mcp.WithNumber("page",
175-
mcp.Description("Page number"),
176-
mcp.Min(1),
177-
),
148+
withPagination(),
178149
),
179150
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
180151
query, err := requiredParam[string](request, "q")
@@ -189,11 +160,7 @@ func searchUsers(client *github.Client, t translations.TranslationHelperFunc) (t
189160
if err != nil {
190161
return mcp.NewToolResultError(err.Error()), nil
191162
}
192-
perPage, err := optionalIntParamWithDefault(request, "per_page", 30)
193-
if err != nil {
194-
return mcp.NewToolResultError(err.Error()), nil
195-
}
196-
page, err := optionalIntParamWithDefault(request, "page", 1)
163+
pagination, err := optionalPaginationParams(request)
197164
if err != nil {
198165
return mcp.NewToolResultError(err.Error()), nil
199166
}
@@ -202,8 +169,8 @@ func searchUsers(client *github.Client, t translations.TranslationHelperFunc) (t
202169
Sort: sort,
203170
Order: order,
204171
ListOptions: github.ListOptions{
205-
PerPage: perPage,
206-
Page: page,
172+
PerPage: pagination.perPage,
173+
Page: pagination.page,
207174
},
208175
}
209176

0 commit comments

Comments
 (0)