Skip to content

Commit 8bd7152

Browse files
JoannaaKLSamMorrowDrums
authored andcommitted
Add repo and owner
1 parent 805358b commit 8bd7152

File tree

7 files changed

+201
-0
lines changed

7 files changed

+201
-0
lines changed

pkg/github/__toolsnaps__/search_issues.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
],
1515
"type": "string"
1616
},
17+
"owner": {
18+
"description": "Optional repository owner. If provided with repo, only notifications for this repository are listed.",
19+
"type": "string"
20+
},
1721
"page": {
1822
"description": "Page number for pagination (min 1)",
1923
"minimum": 1,
@@ -29,6 +33,10 @@
2933
"description": "Search query using GitHub issues search syntax",
3034
"type": "string"
3135
},
36+
"repo": {
37+
"description": "Optional repository name. If provided with owner, only notifications for this repository are listed.",
38+
"type": "string"
39+
},
3240
"sort": {
3341
"description": "Sort field by number of matches of categories, defaults to best match",
3442
"enum": [

pkg/github/__toolsnaps__/search_pull_requests.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
],
1515
"type": "string"
1616
},
17+
"owner": {
18+
"description": "Optional repository owner. If provided with repo, only notifications for this repository are listed.",
19+
"type": "string"
20+
},
1721
"page": {
1822
"description": "Page number for pagination (min 1)",
1923
"minimum": 1,
@@ -29,6 +33,10 @@
2933
"description": "Search query using GitHub pull request search syntax",
3034
"type": "string"
3135
},
36+
"repo": {
37+
"description": "Optional repository name. If provided with owner, only notifications for this repository are listed.",
38+
"type": "string"
39+
},
3240
"sort": {
3341
"description": "Sort field by number of matches of categories, defaults to best match",
3442
"enum": [

pkg/github/issues.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ func SearchIssues(getClient GetClientFn, t translations.TranslationHelperFunc) (
165165
mcp.Required(),
166166
mcp.Description("Search query using GitHub issues search syntax"),
167167
),
168+
mcp.WithString("owner",
169+
mcp.Description("Optional repository owner. If provided with repo, only notifications for this repository are listed."),
170+
),
171+
mcp.WithString("repo",
172+
mcp.Description("Optional repository name. If provided with owner, only notifications for this repository are listed."),
173+
),
168174
mcp.WithString("sort",
169175
mcp.Description("Sort field by number of matches of categories, defaults to best match"),
170176
mcp.Enum(

pkg/github/issues_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ func Test_SearchIssues(t *testing.T) {
238238
assert.Equal(t, "search_issues", tool.Name)
239239
assert.NotEmpty(t, tool.Description)
240240
assert.Contains(t, tool.InputSchema.Properties, "query")
241+
assert.Contains(t, tool.InputSchema.Properties, "owner")
242+
assert.Contains(t, tool.InputSchema.Properties, "repo")
241243
assert.Contains(t, tool.InputSchema.Properties, "sort")
242244
assert.Contains(t, tool.InputSchema.Properties, "order")
243245
assert.Contains(t, tool.InputSchema.Properties, "perPage")
@@ -311,6 +313,83 @@ func Test_SearchIssues(t *testing.T) {
311313
expectError: false,
312314
expectedResult: mockSearchResult,
313315
},
316+
{
317+
name: "issues search with owner and repo parameters",
318+
mockedClient: mock.NewMockedHTTPClient(
319+
mock.WithRequestMatchHandler(
320+
mock.GetSearchIssues,
321+
expectQueryParams(
322+
t,
323+
map[string]string{
324+
"q": "repo:test-owner/test-repo is:issue is:open",
325+
"sort": "created",
326+
"order": "asc",
327+
"page": "1",
328+
"per_page": "30",
329+
},
330+
).andThen(
331+
mockResponse(t, http.StatusOK, mockSearchResult),
332+
),
333+
),
334+
),
335+
requestArgs: map[string]interface{}{
336+
"query": "is:open",
337+
"owner": "test-owner",
338+
"repo": "test-repo",
339+
"sort": "created",
340+
"order": "asc",
341+
},
342+
expectError: false,
343+
expectedResult: mockSearchResult,
344+
},
345+
{
346+
name: "issues search with only owner parameter (should ignore it)",
347+
mockedClient: mock.NewMockedHTTPClient(
348+
mock.WithRequestMatchHandler(
349+
mock.GetSearchIssues,
350+
expectQueryParams(
351+
t,
352+
map[string]string{
353+
"q": "is:issue bug",
354+
"page": "1",
355+
"per_page": "30",
356+
},
357+
).andThen(
358+
mockResponse(t, http.StatusOK, mockSearchResult),
359+
),
360+
),
361+
),
362+
requestArgs: map[string]interface{}{
363+
"query": "bug",
364+
"owner": "test-owner",
365+
},
366+
expectError: false,
367+
expectedResult: mockSearchResult,
368+
},
369+
{
370+
name: "issues search with only repo parameter (should ignore it)",
371+
mockedClient: mock.NewMockedHTTPClient(
372+
mock.WithRequestMatchHandler(
373+
mock.GetSearchIssues,
374+
expectQueryParams(
375+
t,
376+
map[string]string{
377+
"q": "is:issue feature",
378+
"page": "1",
379+
"per_page": "30",
380+
},
381+
).andThen(
382+
mockResponse(t, http.StatusOK, mockSearchResult),
383+
),
384+
),
385+
),
386+
requestArgs: map[string]interface{}{
387+
"query": "feature",
388+
"repo": "test-repo",
389+
},
390+
expectError: false,
391+
expectedResult: mockSearchResult,
392+
},
314393
{
315394
name: "issues search with minimal parameters",
316395
mockedClient: mock.NewMockedHTTPClient(

pkg/github/pullrequests.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,12 @@ func SearchPullRequests(getClient GetClientFn, t translations.TranslationHelperF
545545
mcp.Required(),
546546
mcp.Description("Search query using GitHub pull request search syntax"),
547547
),
548+
mcp.WithString("owner",
549+
mcp.Description("Optional repository owner. If provided with repo, only notifications for this repository are listed."),
550+
),
551+
mcp.WithString("repo",
552+
mcp.Description("Optional repository name. If provided with owner, only notifications for this repository are listed."),
553+
),
548554
mcp.WithString("sort",
549555
mcp.Description("Sort field by number of matches of categories, defaults to best match"),
550556
mcp.Enum(

pkg/github/pullrequests_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ func Test_SearchPullRequests(t *testing.T) {
573573
assert.Equal(t, "search_pull_requests", tool.Name)
574574
assert.NotEmpty(t, tool.Description)
575575
assert.Contains(t, tool.InputSchema.Properties, "query")
576+
assert.Contains(t, tool.InputSchema.Properties, "owner")
577+
assert.Contains(t, tool.InputSchema.Properties, "repo")
576578
assert.Contains(t, tool.InputSchema.Properties, "sort")
577579
assert.Contains(t, tool.InputSchema.Properties, "order")
578580
assert.Contains(t, tool.InputSchema.Properties, "perPage")
@@ -645,6 +647,83 @@ func Test_SearchPullRequests(t *testing.T) {
645647
expectError: false,
646648
expectedResult: mockSearchResult,
647649
},
650+
{
651+
name: "pull request search with owner and repo parameters",
652+
mockedClient: mock.NewMockedHTTPClient(
653+
mock.WithRequestMatchHandler(
654+
mock.GetSearchIssues,
655+
expectQueryParams(
656+
t,
657+
map[string]string{
658+
"q": "repo:test-owner/test-repo is:pr draft:false",
659+
"sort": "updated",
660+
"order": "asc",
661+
"page": "1",
662+
"per_page": "30",
663+
},
664+
).andThen(
665+
mockResponse(t, http.StatusOK, mockSearchResult),
666+
),
667+
),
668+
),
669+
requestArgs: map[string]interface{}{
670+
"query": "draft:false",
671+
"owner": "test-owner",
672+
"repo": "test-repo",
673+
"sort": "updated",
674+
"order": "asc",
675+
},
676+
expectError: false,
677+
expectedResult: mockSearchResult,
678+
},
679+
{
680+
name: "pull request search with only owner parameter (should ignore it)",
681+
mockedClient: mock.NewMockedHTTPClient(
682+
mock.WithRequestMatchHandler(
683+
mock.GetSearchIssues,
684+
expectQueryParams(
685+
t,
686+
map[string]string{
687+
"q": "is:pr feature",
688+
"page": "1",
689+
"per_page": "30",
690+
},
691+
).andThen(
692+
mockResponse(t, http.StatusOK, mockSearchResult),
693+
),
694+
),
695+
),
696+
requestArgs: map[string]interface{}{
697+
"query": "feature",
698+
"owner": "test-owner",
699+
},
700+
expectError: false,
701+
expectedResult: mockSearchResult,
702+
},
703+
{
704+
name: "pull request search with only repo parameter (should ignore it)",
705+
mockedClient: mock.NewMockedHTTPClient(
706+
mock.WithRequestMatchHandler(
707+
mock.GetSearchIssues,
708+
expectQueryParams(
709+
t,
710+
map[string]string{
711+
"q": "is:pr review-required",
712+
"page": "1",
713+
"per_page": "30",
714+
},
715+
).andThen(
716+
mockResponse(t, http.StatusOK, mockSearchResult),
717+
),
718+
),
719+
),
720+
requestArgs: map[string]interface{}{
721+
"query": "review-required",
722+
"repo": "test-repo",
723+
},
724+
expectError: false,
725+
expectedResult: mockSearchResult,
726+
},
648727
{
649728
name: "pull request search with minimal parameters",
650729
mockedClient: mock.NewMockedHTTPClient(

pkg/github/search_utils.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ func searchHandler(
2424
}
2525
query = fmt.Sprintf("is:%s %s", searchType, query)
2626

27+
owner, err := OptionalParam[string](request, "owner")
28+
if err != nil {
29+
return mcp.NewToolResultError(err.Error()), nil
30+
}
31+
32+
repo, err := OptionalParam[string](request, "repo")
33+
if err != nil {
34+
return mcp.NewToolResultError(err.Error()), nil
35+
}
36+
37+
if owner != "" && repo != "" {
38+
query = fmt.Sprintf("repo:%s/%s %s", owner, repo, query)
39+
}
40+
2741
sort, err := OptionalParam[string](request, "sort")
2842
if err != nil {
2943
return mcp.NewToolResultError(err.Error()), nil
@@ -38,6 +52,7 @@ func searchHandler(
3852
}
3953

4054
opts := &github.SearchOptions{
55+
// Default to "created" if no sort is provided, as it's a common use case.
4156
Sort: sort,
4257
Order: order,
4358
ListOptions: github.ListOptions{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy