@@ -457,7 +457,7 @@ func ReprioritizeSubIssue(getClient GetClientFn, t translations.TranslationHelpe
457
457
),
458
458
mcp .WithNumber ("sub_issue_id" ,
459
459
mcp .Required (),
460
- mcp .Description ("The ID of the sub-issue to reprioritize" ),
460
+ mcp .Description ("The ID of the sub-issue to reprioritize. Note: This is NOT the same as the issue number. " ),
461
461
),
462
462
mcp .WithNumber ("after_id" ,
463
463
mcp .Description ("The ID of the sub-issue to be prioritized after (either after_id OR before_id should be specified)" ),
@@ -503,68 +503,48 @@ func ReprioritizeSubIssue(getClient GetClientFn, t translations.TranslationHelpe
503
503
}
504
504
505
505
client , err := getClient (ctx )
506
- if err != nil {
507
- return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
508
- }
509
-
510
- // Create the request body
511
- requestBody := map [string ]interface {}{
512
- "sub_issue_id" : subIssueID ,
513
- }
514
- if afterID != 0 {
515
- requestBody ["after_id" ] = afterID
516
- }
517
- if beforeID != 0 {
518
- requestBody ["before_id" ] = beforeID
519
- }
520
-
521
- // Since the go-github library might not have sub-issues support yet,
522
- // we'll make a direct HTTP request using the client's HTTP client
523
- reqBodyBytes , err := json .Marshal (requestBody )
524
- if err != nil {
525
- return nil , fmt .Errorf ("failed to marshal request body: %w" , err )
526
- }
527
-
528
- url := fmt .Sprintf ("%srepos/%s/%s/issues/%d/sub_issues/priority" ,
529
- client .BaseURL .String (), owner , repo , issueNumber )
530
- req , err := http .NewRequestWithContext (ctx , "PATCH" , url , strings .NewReader (string (reqBodyBytes )))
531
- if err != nil {
532
- return nil , fmt .Errorf ("failed to create request: %w" , err )
533
- }
506
+ if err != nil {
507
+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
508
+ }
534
509
535
- req . Header . Set ( "Accept" , "application/vnd. github+json" )
536
- req . Header . Set ( "Content-Type" , "application/json" )
537
- req . Header . Set ( "X-GitHub-Api-Version" , "2022-11-28" )
510
+ subIssueRequest := github. SubIssueRequest {
511
+ SubIssueID : int64 ( subIssueID ),
512
+ }
538
513
539
- // Use the same authentication as the GitHub client
540
- httpClient := client .Client ()
541
- resp , err := httpClient .Do (req )
542
- if err != nil {
543
- return nil , fmt .Errorf ("failed to reprioritize sub-issue: %w" , err )
544
- }
545
- defer func () { _ = resp .Body .Close () }()
514
+ if afterID != 0 {
515
+ afterIDInt64 := int64 (afterID )
516
+ subIssueRequest .AfterID = & afterIDInt64
517
+ }
518
+ if beforeID != 0 {
519
+ beforeIDInt64 := int64 (beforeID )
520
+ subIssueRequest .BeforeID = & beforeIDInt64
521
+ }
546
522
547
- body , err := io .ReadAll (resp .Body )
548
- if err != nil {
549
- return nil , fmt .Errorf ("failed to read response body: %w" , err )
550
- }
523
+ subIssue , resp , err := client .SubIssue .Reprioritize (ctx , owner , repo , int64 (issueNumber ), subIssueRequest )
524
+ if err != nil {
525
+ return ghErrors .NewGitHubAPIErrorResponse (ctx ,
526
+ "failed to reprioritize sub-issue" ,
527
+ resp ,
528
+ err ,
529
+ ), nil
530
+ }
551
531
552
- if resp .StatusCode != http .StatusOK {
553
- return mcp .NewToolResultError (fmt .Sprintf ("failed to reprioritize sub-issue: %s" , string (body ))), nil
554
- }
532
+ defer func () { _ = resp .Body .Close () }()
555
533
556
- // Parse and re-marshal to ensure consistent formatting
557
- var result interface {}
558
- if err := json .Unmarshal (body , & result ); err != nil {
559
- return nil , fmt .Errorf ("failed to unmarshal response: %w" , err )
560
- }
534
+ if resp .StatusCode != http .StatusOK {
535
+ body , err := io .ReadAll (resp .Body )
536
+ if err != nil {
537
+ return nil , fmt .Errorf ("failed to read response body: %w" , err )
538
+ }
539
+ return mcp .NewToolResultError (fmt .Sprintf ("failed to reprioritize sub-issue: %s" , string (body ))), nil
540
+ }
561
541
562
- r , err := json .Marshal (result )
563
- if err != nil {
564
- return nil , fmt .Errorf ("failed to marshal response: %w" , err )
565
- }
542
+ r , err := json .Marshal (subIssue )
543
+ if err != nil {
544
+ return nil , fmt .Errorf ("failed to marshal response: %w" , err )
545
+ }
566
546
567
- return mcp .NewToolResultText (string (r )), nil
547
+ return mcp .NewToolResultText (string (r )), nil
568
548
}
569
549
}
570
550
0 commit comments