@@ -829,23 +829,45 @@ func Test_SearchPullRequests(t *testing.T) {
829829 assert .Contains (t , schema .Properties , "repo" )
830830 assert .Contains (t , schema .Properties , "sort" )
831831 assert .Contains (t , schema .Properties , "order" )
832+ assert .Contains (t , schema .Properties , "minimal_output" )
832833 assert .Contains (t , schema .Properties , "perPage" )
833834 assert .Contains (t , schema .Properties , "page" )
834835 assert .ElementsMatch (t , schema .Required , []string {"query" })
835836
837+ createdAt := & github.Timestamp {Time : time .Date (2026 , 6 , 10 , 12 , 0 , 0 , 0 , time .UTC )}
838+ updatedAt := & github.Timestamp {Time : time .Date (2026 , 6 , 11 , 15 , 30 , 0 , 0 , time .UTC )}
836839 mockSearchResult := & github.IssuesSearchResult {
837840 Total : github .Ptr (2 ),
838841 IncompleteResults : github .Ptr (false ),
839842 Issues : []* github.Issue {
840843 {
841- Number : github .Ptr (42 ),
842- Title : github .Ptr ("Test PR 1" ),
843- Body : github .Ptr ("Updated tests." ),
844- State : github .Ptr ("open" ),
845- HTMLURL : github .Ptr ("https://github.com/owner/repo/pull/1" ),
846- Comments : github .Ptr (5 ),
844+ Number : github .Ptr (42 ),
845+ Title : github .Ptr ("Test PR 1" ),
846+ Body : github .Ptr ("Updated tests." ),
847+ State : github .Ptr ("open" ),
848+ Draft : github .Ptr (true ),
849+ HTMLURL : github .Ptr ("https://github.com/owner/repo/pull/1" ),
850+ RepositoryURL : github .Ptr ("https://api.github.com/repos/owner/repo" ),
851+ Comments : github .Ptr (5 ),
852+ CreatedAt : createdAt ,
853+ UpdatedAt : updatedAt ,
847854 User : & github.User {
848- Login : github .Ptr ("user1" ),
855+ Login : github .Ptr ("user1" ),
856+ URL : github .Ptr ("https://api.github.com/users/user1" ),
857+ AvatarURL : github .Ptr ("https://avatars.githubusercontent.com/u/1?v=4" ),
858+ },
859+ Repository : & github.Repository {
860+ FullName : github .Ptr ("owner/repo" ),
861+ },
862+ Labels : []* github.Label {
863+ {Name : github .Ptr ("ci" )},
864+ {Name : github .Ptr ("backend" )},
865+ },
866+ PullRequestLinks : & github.PullRequestLinks {
867+ URL : github .Ptr ("https://api.github.com/repos/owner/repo/pulls/1" ),
868+ HTMLURL : github .Ptr ("https://github.com/owner/repo/pull/1" ),
869+ DiffURL : github .Ptr ("https://github.com/owner/repo/pull/1.diff" ),
870+ PatchURL : github .Ptr ("https://github.com/owner/repo/pull/1.patch" ),
849871 },
850872 },
851873 {
@@ -863,12 +885,14 @@ func Test_SearchPullRequests(t *testing.T) {
863885 }
864886
865887 tests := []struct {
866- name string
867- mockedClient * http.Client
868- requestArgs map [string ]any
869- expectError bool
870- expectedResult * github.IssuesSearchResult
871- expectedErrMsg string
888+ name string
889+ mockedClient * http.Client
890+ requestArgs map [string ]any
891+ expectError bool
892+ expectRaw bool
893+ expectedResult * github.IssuesSearchResult
894+ expectedErrMsg string
895+ expectedJSONLack []string
872896 }{
873897 {
874898 name : "successful pull request search with all parameters" ,
@@ -972,8 +996,9 @@ func Test_SearchPullRequests(t *testing.T) {
972996 requestArgs : map [string ]any {
973997 "query" : "is:pr repo:owner/repo is:open" ,
974998 },
975- expectError : false ,
976- expectedResult : mockSearchResult ,
999+ expectError : false ,
1000+ expectedResult : mockSearchResult ,
1001+ expectedJSONLack : []string {"avatar_url" , "\" url\" :\" https://api.github.com/users/user1\" " },
9771002 },
9781003 {
9791004 name : "query with existing is:pr filter - no duplication" ,
@@ -1051,6 +1076,18 @@ func Test_SearchPullRequests(t *testing.T) {
10511076 expectError : true ,
10521077 expectedErrMsg : "failed to search pull requests" ,
10531078 },
1079+ {
1080+ name : "pull request search with minimal_output false returns raw result" ,
1081+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
1082+ GetSearchIssues : mockResponse (t , http .StatusOK , mockSearchResult ),
1083+ }),
1084+ requestArgs : map [string ]any {
1085+ "query" : "is:pr repo:owner/repo is:open" ,
1086+ "minimal_output" : false ,
1087+ },
1088+ expectRaw : true ,
1089+ expectedResult : mockSearchResult ,
1090+ },
10541091 }
10551092
10561093 for _ , tc := range tests {
@@ -1084,20 +1121,57 @@ func Test_SearchPullRequests(t *testing.T) {
10841121 // Parse the result and get the text content if no error
10851122 textContent := getTextResult (t , result )
10861123
1087- // Unmarshal and verify the result
1088- var returnedResult github.IssuesSearchResult
1124+ if tc .expectRaw {
1125+ var returnedResult github.IssuesSearchResult
1126+ err = json .Unmarshal ([]byte (textContent .Text ), & returnedResult )
1127+ require .NoError (t , err )
1128+ assert .Equal (t , * tc .expectedResult .Total , * returnedResult .Total )
1129+ assert .Equal (t , * tc .expectedResult .IncompleteResults , * returnedResult .IncompleteResults )
1130+ assert .Len (t , returnedResult .Issues , len (tc .expectedResult .Issues ))
1131+ for i , issue := range returnedResult .Issues {
1132+ assert .Equal (t , * tc .expectedResult .Issues [i ].Number , * issue .Number )
1133+ assert .Equal (t , * tc .expectedResult .Issues [i ].Title , * issue .Title )
1134+ assert .Equal (t , * tc .expectedResult .Issues [i ].State , * issue .State )
1135+ assert .Equal (t , * tc .expectedResult .Issues [i ].HTMLURL , * issue .HTMLURL )
1136+ assert .Equal (t , * tc .expectedResult .Issues [i ].User .Login , * issue .User .Login )
1137+ }
1138+ assert .Contains (t , textContent .Text , "\" avatar_url\" :\" https://avatars.githubusercontent.com/u/1?v=4\" " )
1139+ return
1140+ }
1141+
1142+ for _ , missingJSON := range tc .expectedJSONLack {
1143+ assert .NotContains (t , textContent .Text , missingJSON )
1144+ }
1145+
1146+ var returnedResult MinimalSearchPullRequestsResult
10891147 err = json .Unmarshal ([]byte (textContent .Text ), & returnedResult )
10901148 require .NoError (t , err )
1091- assert .Equal (t , * tc .expectedResult .Total , * returnedResult .Total )
1092- assert .Equal (t , * tc .expectedResult .IncompleteResults , * returnedResult .IncompleteResults )
1093- assert .Len (t , returnedResult .Issues , len (tc .expectedResult .Issues ))
1094- for i , issue := range returnedResult .Issues {
1095- assert .Equal (t , * tc .expectedResult .Issues [i ].Number , * issue .Number )
1096- assert .Equal (t , * tc .expectedResult .Issues [i ].Title , * issue .Title )
1097- assert .Equal (t , * tc .expectedResult .Issues [i ].State , * issue .State )
1098- assert .Equal (t , * tc .expectedResult .Issues [i ].HTMLURL , * issue .HTMLURL )
1099- assert .Equal (t , * tc .expectedResult .Issues [i ].User .Login , * issue .User .Login )
1100- }
1149+ assert .Equal (t , tc .expectedResult .GetTotal (), returnedResult .TotalCount )
1150+ assert .Equal (t , tc .expectedResult .GetIncompleteResults (), returnedResult .IncompleteResults )
1151+ assert .Len (t , returnedResult .Items , len (tc .expectedResult .Issues ))
1152+
1153+ first := returnedResult .Items [0 ]
1154+ assert .Equal (t , 42 , first .Number )
1155+ assert .Equal (t , "Test PR 1" , first .Title )
1156+ assert .Equal (t , "open" , first .State )
1157+ assert .True (t , first .Draft )
1158+ assert .Equal (t , "user1" , first .User )
1159+ assert .Equal (t , createdAt .Format (time .RFC3339 ), first .CreatedAt )
1160+ assert .Equal (t , updatedAt .Format (time .RFC3339 ), first .UpdatedAt )
1161+ assert .Equal (t , "https://github.com/owner/repo/pull/1" , first .HTMLURL )
1162+ assert .Equal (t , "owner/repo" , first .Repository )
1163+ assert .Equal (t , "https://api.github.com/repos/owner/repo" , first .RepositoryURL )
1164+ assert .Equal (t , []string {"ci" , "backend" }, first .Labels )
1165+ assert .Equal (t , 5 , first .Comments )
1166+ require .NotNil (t , first .PullRequest )
1167+ assert .Equal (t , "https://api.github.com/repos/owner/repo/pulls/1" , first .PullRequest .URL )
1168+ assert .Equal (t , "https://github.com/owner/repo/pull/1" , first .PullRequest .HTMLURL )
1169+ assert .Equal (t , "https://github.com/owner/repo/pull/1.diff" , first .PullRequest .DiffURL )
1170+ assert .Equal (t , "https://github.com/owner/repo/pull/1.patch" , first .PullRequest .PatchURL )
1171+
1172+ second := returnedResult .Items [1 ]
1173+ assert .Equal (t , 43 , second .Number )
1174+ assert .Equal (t , "user2" , second .User )
11011175 })
11021176 }
11031177
0 commit comments