@@ -11,6 +11,7 @@ import (
1111 "strings"
1212 "time"
1313
14+ "github.com/cli/go-gh/v2"
1415 "github.com/fatih/color"
1516 "github.com/spf13/cobra"
1617)
@@ -93,10 +94,9 @@ func getReposWithOpenPRs(ctx context.Context) (map[string][]PullRequestInfo, err
9394 }
9495 `
9596
96- cmd := exec .CommandContext (ctx , "gh" , "api" , "graphql" , "-f" , fmt .Sprintf ("query=%s" , query ))
97- out , err := cmd .CombinedOutput ()
97+ stdout , stderr , err := gh .ExecContext (ctx , "api" , "graphql" , "-f" , fmt .Sprintf ("query=%s" , query ))
9898 if err != nil {
99- return nil , fmt .Errorf ("error fetching open PRs: %v\n Output: %s" , err , string ( out ))
99+ return nil , fmt .Errorf ("error fetching open PRs: %v\n Output: %s" , err , stderr . String ( ))
100100 }
101101
102102 // Parse the GraphQL response
@@ -111,7 +111,7 @@ func getReposWithOpenPRs(ctx context.Context) (map[string][]PullRequestInfo, err
111111 }
112112
113113 var resp Response
114- if err := json .Unmarshal (out , & resp ); err != nil {
114+ if err := json .Unmarshal (stdout . Bytes () , & resp ); err != nil {
115115 return nil , fmt .Errorf ("error parsing GraphQL response: %v" , err )
116116 }
117117
@@ -183,10 +183,10 @@ func getForks(ctx context.Context) ([]Repo, error) {
183183 if cursor != "" {
184184 args = append (args , "-f" , fmt .Sprintf ("after=%s" , cursor ))
185185 }
186- cmd := exec . CommandContext ( ctx , "gh" , args ... )
187- out , err := cmd . CombinedOutput ( )
186+
187+ stdout , stderr , err := gh . ExecContext ( ctx , args ... )
188188 if err != nil {
189- return nil , fmt .Errorf ("error fetching forks: %v\n Output: %s" , err , string ( out ))
189+ return nil , fmt .Errorf ("error fetching forks: %v\n Output: %s" , err , stderr . String ( ))
190190 }
191191
192192 // Parse the GraphQL response
@@ -205,7 +205,7 @@ func getForks(ctx context.Context) ([]Repo, error) {
205205 }
206206
207207 var resp Response
208- if err := json .Unmarshal (out , & resp ); err != nil {
208+ if err := json .Unmarshal (stdout . Bytes () , & resp ); err != nil {
209209 return nil , fmt .Errorf ("error parsing GraphQL response: %v" , err )
210210 }
211211
@@ -228,22 +228,22 @@ func getCommitComparison(ctx context.Context, fork Repo) (*CommitComparison, err
228228 }
229229
230230 // Use gh api to get the comparison between the fork and its parent
231- cmd := exec .CommandContext (ctx , "gh" , "api" ,
231+ stdout , stderr , err := gh .ExecContext (ctx ,
232+ "api" ,
232233 fmt .Sprintf ("repos/%s/compare/%s...%s:%s" ,
233234 fork .Parent .NameWithOwner ,
234235 fork .Parent .DefaultBranchRef .Name ,
235236 fork .Owner .Login ,
236237 fork .DefaultBranchRef .Name ,
237238 ),
238239 )
239- out , err := cmd .CombinedOutput ()
240240 if err != nil {
241- return nil , fmt .Errorf ("error comparing repositories: %v \n Output: %s" , err , string ( out ))
241+ return nil , fmt .Errorf ("error comparing repositories: %w \n Output: %s" , err , stderr . String ( ))
242242 }
243243
244244 var comparison CommitComparison
245- if err := json .Unmarshal (out , & comparison ); err != nil {
246- return nil , fmt .Errorf ("error parsing comparison response: %v " , err )
245+ if err := json .Unmarshal (stdout . Bytes () , & comparison ); err != nil {
246+ return nil , fmt .Errorf ("error parsing comparison response: %w " , err )
247247 }
248248
249249 return & comparison , nil
@@ -374,11 +374,11 @@ func cleanupForks(cmd *cobra.Command, args []string) error {
374374 }
375375
376376 color .New (color .FgRed ).Printf ("🗑️ Deleting %s...\n " , fork .NameWithOwner )
377- deleteCmd := exec . CommandContext (ctx , "gh" , "repo" , "delete" , fork .NameWithOwner , "--yes" )
378- if err := deleteCmd . Run (); err != nil {
379- fmt .Fprintf (os .Stderr , "Error deleting %s: %v\n " , fork .NameWithOwner , err )
377+ stdout , stderr , err := gh . ExecContext (ctx , "repo" , "delete" , fork .NameWithOwner , "--yes" )
378+ if err != nil {
379+ fmt .Fprintf (os .Stderr , "Error deleting %s: %v %s \n " , fork .NameWithOwner , err , stderr . String () )
380380 } else {
381- color .New (color .FgGreen ).Printf ("✅ Successfully deleted %s.\n " , fork . NameWithOwner )
381+ color .New (color .FgGreen ).Printf ("✅ Successfully deleted %s.\n " , stdout . String () )
382382 }
383383 }
384384 fmt .Println ()
0 commit comments