@@ -2,6 +2,7 @@ package command
22
33import (
44 "fmt"
5+ "io"
56 "os"
67 "os/exec"
78 "strconv"
@@ -78,30 +79,32 @@ func prStatus(cmd *cobra.Command, args []string) error {
7879 return err
7980 }
8081
81- printHeader ("Current branch" )
82+ out := colorableOut (cmd )
83+
84+ printHeader (out , "Current branch" )
8285 if prPayload .CurrentPR != nil {
83- printPrs (* prPayload .CurrentPR )
86+ printPrs (out , * prPayload .CurrentPR )
8487 } else {
8588 message := fmt .Sprintf (" There is no pull request associated with %s" , utils .Cyan ("[" + currentBranch + "]" ))
86- printMessage (message )
89+ printMessage (out , message )
8790 }
88- fmt .Println ( )
91+ fmt .Fprintln ( out )
8992
90- printHeader ("Created by you" )
93+ printHeader (out , "Created by you" )
9194 if len (prPayload .ViewerCreated ) > 0 {
92- printPrs (prPayload .ViewerCreated ... )
95+ printPrs (out , prPayload .ViewerCreated ... )
9396 } else {
94- printMessage (" You have no open pull requests" )
97+ printMessage (out , " You have no open pull requests" )
9598 }
96- fmt .Println ( )
99+ fmt .Fprintln ( out )
97100
98- printHeader ("Requesting a code review from you" )
101+ printHeader (out , "Requesting a code review from you" )
99102 if len (prPayload .ReviewRequested ) > 0 {
100- printPrs (prPayload .ReviewRequested ... )
103+ printPrs (out , prPayload .ReviewRequested ... )
101104 } else {
102- printMessage (" You have no pull requests to review" )
105+ printMessage (out , " You have no pull requests to review" )
103106 }
104- fmt .Println ( )
107+ fmt .Fprintln ( out )
105108
106109 return nil
107110}
@@ -330,15 +333,15 @@ func prCheckout(cmd *cobra.Command, args []string) error {
330333 return nil
331334}
332335
333- func printPrs (prs ... api.PullRequest ) {
336+ func printPrs (w io. Writer , prs ... api.PullRequest ) {
334337 for _ , pr := range prs {
335338 prNumber := fmt .Sprintf ("#%d" , pr .Number )
336- fmt .Printf ( " %s %s %s" , utils .Yellow (prNumber ), truncate (50 , pr .Title ), utils .Cyan ("[" + pr .HeadLabel ()+ "]" ))
339+ fmt .Fprintf ( w , " %s %s %s" , utils .Yellow (prNumber ), truncate (50 , pr .Title ), utils .Cyan ("[" + pr .HeadLabel ()+ "]" ))
337340
338341 checks := pr .ChecksStatus ()
339342 reviews := pr .ReviewStatus ()
340343 if checks .Total > 0 || reviews .ChangesRequested || reviews .Approved {
341- fmt .Printf ( "\n " )
344+ fmt .Fprintf ( w , "\n " )
342345 }
343346
344347 if checks .Total > 0 {
@@ -354,27 +357,27 @@ func printPrs(prs ...api.PullRequest) {
354357 } else if checks .Passing == checks .Total {
355358 summary = utils .Green ("Checks passing" )
356359 }
357- fmt .Printf ( " - %s" , summary )
360+ fmt .Fprintf ( w , " - %s" , summary )
358361 }
359362
360363 if reviews .ChangesRequested {
361- fmt .Printf ( " - %s" , utils .Red ("changes requested" ))
364+ fmt .Fprintf ( w , " - %s" , utils .Red ("changes requested" ))
362365 } else if reviews .ReviewRequired {
363- fmt .Printf ( " - %s" , utils .Yellow ("review required" ))
366+ fmt .Fprintf ( w , " - %s" , utils .Yellow ("review required" ))
364367 } else if reviews .Approved {
365- fmt .Printf ( " - %s" , utils .Green ("approved" ))
368+ fmt .Fprintf ( w , " - %s" , utils .Green ("approved" ))
366369 }
367370
368- fmt .Printf ( "\n " )
371+ fmt .Fprint ( w , "\n " )
369372 }
370373}
371374
372- func printHeader (s string ) {
373- fmt .Println ( utils .Bold (s ))
375+ func printHeader (w io. Writer , s string ) {
376+ fmt .Fprintln ( w , utils .Bold (s ))
374377}
375378
376- func printMessage (s string ) {
377- fmt .Println ( utils .Gray (s ))
379+ func printMessage (w io. Writer , s string ) {
380+ fmt .Fprintln ( w , utils .Gray (s ))
378381}
379382
380383func truncate (maxLength int , title string ) string {
0 commit comments