@@ -296,48 +296,40 @@ func ListSubIssues(getClient GetClientFn, t translations.TranslationHelperFunc)
296296 return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
297297 }
298298
299- // Since the go-github library might not have sub-issues support yet,
300- // we'll make a direct HTTP request using the client's HTTP client
301- url := fmt .Sprintf ("%srepos/%s/%s/issues/%d/sub_issues?page=%d&per_page=%d" ,
302- client .BaseURL .String (), owner , repo , issueNumber , page , perPage )
303- req , err := http .NewRequestWithContext (ctx , "GET" , url , nil )
304- if err != nil {
305- return nil , fmt .Errorf ("failed to create request: %w" , err )
306- }
307-
308- req .Header .Set ("Accept" , "application/vnd.github+json" )
309- req .Header .Set ("X-GitHub-Api-Version" , "2022-11-28" )
299+ opts := & github.IssueListOptions {
300+ ListOptions : github.ListOptions {
301+ Page : page ,
302+ PerPage : perPage ,
303+ },
304+ }
310305
311- // Use the same authentication as the GitHub client
312- httpClient := client .Client ()
313- resp , err := httpClient .Do (req )
306+ subIssues , resp , err := client .SubIssue .ListByIssue (ctx , owner , repo , int64 (issueNumber ), opts )
314307 if err != nil {
315- return nil , fmt .Errorf ("failed to list sub-issues: %w" , err )
308+ return ghErrors .NewGitHubAPIErrorResponse (ctx ,
309+ "failed to list sub-issues" ,
310+ resp ,
311+ err ,
312+ ), nil
316313 }
317- defer func () { _ = resp .Body .Close () }()
318314
319- body , err := io .ReadAll (resp .Body )
320- if err != nil {
321- return nil , fmt .Errorf ("failed to read response body: %w" , err )
322- }
315+ defer func () { _ = resp .Body .Close () }()
323316
324317 if resp .StatusCode != http .StatusOK {
318+ body , err := io .ReadAll (resp .Body )
319+ if err != nil {
320+ return nil , fmt .Errorf ("failed to read response body: %w" , err )
321+ }
325322 return mcp .NewToolResultError (fmt .Sprintf ("failed to list sub-issues: %s" , string (body ))), nil
326323 }
327324
328- // Parse and re-marshal to ensure consistent formatting
329- var result interface {}
330- if err := json .Unmarshal (body , & result ); err != nil {
331- return nil , fmt .Errorf ("failed to unmarshal response: %w" , err )
332- }
333-
334- r , err := json .Marshal (result )
325+ r , err := json .Marshal (subIssues )
335326 if err != nil {
336327 return nil , fmt .Errorf ("failed to marshal response: %w" , err )
337328 }
338329
339330 return mcp .NewToolResultText (string (r )), nil
340331 }
332+
341333}
342334
343335// RemoveSubIssue creates a tool to remove a sub-issue from a parent issue.
0 commit comments