@@ -506,67 +506,39 @@ func RemoveSubIssue(getClient GetClientFn, t translations.TranslationHelperFunc)
506506 }
507507
508508 client , err := getClient (ctx )
509- if err != nil {
510- return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
511- }
512-
513- // Create the request body
514- requestBody := map [string ]interface {}{
515- "sub_issue_id" : subIssueID ,
516- }
517- reqBodyBytes , err := json .Marshal (requestBody )
518- if err != nil {
519- return nil , fmt .Errorf ("failed to marshal request body: %w" , err )
520- }
521-
522- // Create the HTTP request
523- url := fmt .Sprintf ("%srepos/%s/%s/issues/%d/sub_issue" ,
524- client .BaseURL .String (), owner , repo , issueNumber )
525- req , err := http .NewRequestWithContext (ctx , "DELETE" , url , strings .NewReader (string (reqBodyBytes )))
526- if err != nil {
527- return nil , fmt .Errorf ("failed to create request: %w" , err )
528- }
529- req .Header .Set ("Accept" , "application/vnd.github+json" )
530- req .Header .Set ("Content-Type" , "application/json" )
531- req .Header .Set ("X-GitHub-Api-Version" , "2022-11-28" )
532-
533- httpClient := client .Client () // Use authenticated GitHub client
534- resp , err := httpClient .Do (req )
535- if err != nil {
536- var ghResp * github.Response
537- if resp != nil {
538- ghResp = & github.Response {Response : resp }
539- }
540- return ghErrors .NewGitHubAPIErrorResponse (ctx ,
541- "failed to remove sub-issue" ,
542- ghResp ,
543- err ,
544- ), nil
545- }
546- defer func () { _ = resp .Body .Close () }()
547-
548- body , err := io .ReadAll (resp .Body )
549- if err != nil {
550- return nil , fmt .Errorf ("failed to read response body: %w" , err )
551- }
552-
553- if resp .StatusCode != http .StatusOK {
554- return mcp .NewToolResultError (fmt .Sprintf ("failed to remove sub-issue: %s" , string (body ))), nil
555- }
556-
557- // Parse and re-marshal to ensure consistent formatting
558- var result interface {}
559- if err := json .Unmarshal (body , & result ); err != nil {
560- return nil , fmt .Errorf ("failed to unmarshal response: %w" , err )
561- }
562-
563- r , err := json .Marshal (result )
564- if err != nil {
565- return nil , fmt .Errorf ("failed to marshal response: %w" , err )
566- }
567-
568- return mcp .NewToolResultText (string (r )), nil
569- }
509+ if err != nil {
510+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
511+ }
512+
513+ subIssueRequest := github.SubIssueRequest {
514+ SubIssueID : int64 (subIssueID ),
515+ }
516+
517+ subIssue , resp , err := client .SubIssue .Remove (ctx , owner , repo , int64 (issueNumber ), subIssueRequest )
518+ if err != nil {
519+ return ghErrors .NewGitHubAPIErrorResponse (ctx ,
520+ "failed to remove sub-issue" ,
521+ resp ,
522+ err ,
523+ ), nil
524+ }
525+ defer func () { _ = resp .Body .Close () }()
526+
527+ if resp .StatusCode != http .StatusOK {
528+ body , err := io .ReadAll (resp .Body )
529+ if err != nil {
530+ return nil , fmt .Errorf ("failed to read response body: %w" , err )
531+ }
532+ return mcp .NewToolResultError (fmt .Sprintf ("failed to remove sub-issue: %s" , string (body ))), nil
533+ }
534+
535+ r , err := json .Marshal (subIssue )
536+ if err != nil {
537+ return nil , fmt .Errorf ("failed to marshal response: %w" , err )
538+ }
539+
540+ return mcp .NewToolResultText (string (r )), nil
541+ }
570542}
571543
572544// ReprioritizeSubIssue creates a tool to reprioritize a sub-issue to a different position in the parent list.
0 commit comments