99 "strings"
1010 "time"
1111
12+ ghErrors "github.com/github/github-mcp-server/pkg/errors"
1213 "github.com/github/github-mcp-server/pkg/translations"
1314 "github.com/go-viper/mapstructure/v2"
1415 "github.com/google/go-github/v69/github"
@@ -58,7 +59,11 @@ func GetIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (tool
5859 }
5960 issue , resp , err := client .Issues .Get (ctx , owner , repo , issueNumber )
6061 if err != nil {
61- return nil , fmt .Errorf ("failed to get issue: %w" , err )
62+ return nil , ghErrors .NewGitHubAPIError (
63+ fmt .Sprintf ("failed to get issue with number '%d'" , issueNumber ),
64+ resp ,
65+ err ,
66+ )
6267 }
6368 defer func () { _ = resp .Body .Close () }()
6469
@@ -132,7 +137,11 @@ func AddIssueComment(getClient GetClientFn, t translations.TranslationHelperFunc
132137 }
133138 createdComment , resp , err := client .Issues .CreateComment (ctx , owner , repo , issueNumber , comment )
134139 if err != nil {
135- return nil , fmt .Errorf ("failed to create comment: %w" , err )
140+ return nil , ghErrors .NewGitHubAPIError (
141+ fmt .Sprintf ("failed to create comment on issue '%d'" , issueNumber ),
142+ resp ,
143+ err ,
144+ )
136145 }
137146 defer func () { _ = resp .Body .Close () }()
138147
@@ -220,7 +229,11 @@ func SearchIssues(getClient GetClientFn, t translations.TranslationHelperFunc) (
220229 }
221230 result , resp , err := client .Search .Issues (ctx , query , opts )
222231 if err != nil {
223- return nil , fmt .Errorf ("failed to search issues: %w" , err )
232+ return nil , ghErrors .NewGitHubAPIError (
233+ "failed to search issues" ,
234+ resp ,
235+ err ,
236+ )
224237 }
225238 defer func () { _ = resp .Body .Close () }()
226239
@@ -342,7 +355,11 @@ func CreateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t
342355 }
343356 issue , resp , err := client .Issues .Create (ctx , owner , repo , issueRequest )
344357 if err != nil {
345- return nil , fmt .Errorf ("failed to create issue: %w" , err )
358+ return nil , ghErrors .NewGitHubAPIError (
359+ "failed to create issue" ,
360+ resp ,
361+ err ,
362+ )
346363 }
347364 defer func () { _ = resp .Body .Close () }()
348365
@@ -464,7 +481,11 @@ func ListIssues(getClient GetClientFn, t translations.TranslationHelperFunc) (to
464481 }
465482 issues , resp , err := client .Issues .ListByRepo (ctx , owner , repo , opts )
466483 if err != nil {
467- return nil , fmt .Errorf ("failed to list issues: %w" , err )
484+ return nil , ghErrors .NewGitHubAPIError (
485+ "failed to list issues" ,
486+ resp ,
487+ err ,
488+ )
468489 }
469490 defer func () { _ = resp .Body .Close () }()
470491
@@ -610,7 +631,11 @@ func UpdateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t
610631 }
611632 updatedIssue , resp , err := client .Issues .Edit (ctx , owner , repo , issueNumber , issueRequest )
612633 if err != nil {
613- return nil , fmt .Errorf ("failed to update issue: %w" , err )
634+ return nil , ghErrors .NewGitHubAPIError (
635+ "failed to update issue" ,
636+ resp ,
637+ err ,
638+ )
614639 }
615640 defer func () { _ = resp .Body .Close () }()
616641
@@ -693,7 +718,11 @@ func GetIssueComments(getClient GetClientFn, t translations.TranslationHelperFun
693718 }
694719 comments , resp , err := client .Issues .ListComments (ctx , owner , repo , issueNumber , opts )
695720 if err != nil {
696- return nil , fmt .Errorf ("failed to get issue comments: %w" , err )
721+ return nil , ghErrors .NewGitHubAPIError (
722+ "failed to get issue comments" ,
723+ resp ,
724+ err ,
725+ )
697726 }
698727 defer func () { _ = resp .Body .Close () }()
699728
@@ -824,7 +853,10 @@ func AssignCopilotToIssue(getGQLClient GetGQLClientFn, t translations.Translatio
824853 var query suggestedActorsQuery
825854 err := client .Query (ctx , & query , variables )
826855 if err != nil {
827- return nil , err
856+ return nil , ghErrors .NewGitHubGraphQLError (
857+ "failed to list suggested actors" ,
858+ err ,
859+ )
828860 }
829861
830862 // Iterate all the returned nodes looking for the copilot bot, which is supposed to have the
@@ -870,7 +902,10 @@ func AssignCopilotToIssue(getGQLClient GetGQLClientFn, t translations.Translatio
870902 }
871903
872904 if err := client .Query (ctx , & getIssueQuery , variables ); err != nil {
873- return mcp .NewToolResultError (fmt .Sprintf ("failed to get issue ID: %v" , err )), nil
905+ return nil , ghErrors .NewGitHubGraphQLError (
906+ "failed to get issue ID" ,
907+ err ,
908+ )
874909 }
875910
876911 // Finally, do the assignment. Just for reference, assigning copilot to an issue that it is already
@@ -896,7 +931,10 @@ func AssignCopilotToIssue(getGQLClient GetGQLClientFn, t translations.Translatio
896931 },
897932 nil ,
898933 ); err != nil {
899- return nil , fmt .Errorf ("failed to replace actors for assignable: %w" , err )
934+ return nil , ghErrors .NewGitHubGraphQLError (
935+ "failed to replace actors for assignable" ,
936+ err ,
937+ )
900938 }
901939
902940 return mcp .NewToolResultText ("successfully assigned copilot to issue" ), nil
0 commit comments