@@ -632,6 +632,14 @@ func DeleteFile(getClient GetClientFn, t translations.TranslationHelperFunc) (to
632
632
}
633
633
defer func () { _ = resp .Body .Close () }()
634
634
635
+ if resp .StatusCode != http .StatusOK {
636
+ body , err := io .ReadAll (resp .Body )
637
+ if err != nil {
638
+ return nil , fmt .Errorf ("failed to read response body: %w" , err )
639
+ }
640
+ return mcp .NewToolResultError (fmt .Sprintf ("failed to get commit: %s" , string (body ))), nil
641
+ }
642
+
635
643
// Create a tree entry for the file deletion by setting SHA to nil
636
644
treeEntries := []* github.TreeEntry {
637
645
{
@@ -649,6 +657,14 @@ func DeleteFile(getClient GetClientFn, t translations.TranslationHelperFunc) (to
649
657
}
650
658
defer func () { _ = resp .Body .Close () }()
651
659
660
+ if resp .StatusCode != http .StatusCreated {
661
+ body , err := io .ReadAll (resp .Body )
662
+ if err != nil {
663
+ return nil , fmt .Errorf ("failed to read response body: %w" , err )
664
+ }
665
+ return mcp .NewToolResultError (fmt .Sprintf ("failed to create tree: %s" , string (body ))), nil
666
+ }
667
+
652
668
// Create a new commit with the new tree
653
669
commit := & github.Commit {
654
670
Message : github .Ptr (message ),
@@ -661,6 +677,14 @@ func DeleteFile(getClient GetClientFn, t translations.TranslationHelperFunc) (to
661
677
}
662
678
defer func () { _ = resp .Body .Close () }()
663
679
680
+ if resp .StatusCode != http .StatusCreated {
681
+ body , err := io .ReadAll (resp .Body )
682
+ if err != nil {
683
+ return nil , fmt .Errorf ("failed to read response body: %w" , err )
684
+ }
685
+ return mcp .NewToolResultError (fmt .Sprintf ("failed to create commit: %s" , string (body ))), nil
686
+ }
687
+
664
688
// Update the branch reference to point to the new commit
665
689
ref .Object .SHA = newCommit .SHA
666
690
_ , resp , err = client .Git .UpdateRef (ctx , owner , repo , ref , false )
@@ -669,6 +693,14 @@ func DeleteFile(getClient GetClientFn, t translations.TranslationHelperFunc) (to
669
693
}
670
694
defer func () { _ = resp .Body .Close () }()
671
695
696
+ if resp .StatusCode != http .StatusOK {
697
+ body , err := io .ReadAll (resp .Body )
698
+ if err != nil {
699
+ return nil , fmt .Errorf ("failed to read response body: %w" , err )
700
+ }
701
+ return mcp .NewToolResultError (fmt .Sprintf ("failed to update reference: %s" , string (body ))), nil
702
+ }
703
+
672
704
// Create a response similar to what the DeleteFile API would return
673
705
response := map [string ]interface {}{
674
706
"commit" : newCommit ,
0 commit comments