@@ -2,8 +2,11 @@ package command
22
33import (
44 "fmt"
5+ "strings"
56
67 "github.com/github/gh-cli/api"
8+ "github.com/github/gh-cli/git"
9+ "github.com/logrusorgru/aurora"
710 "github.com/spf13/cobra"
811)
912
@@ -37,22 +40,62 @@ func ExecutePr() error {
3740 return err
3841 }
3942
40- fmt . Printf ("Current Pr \n " )
43+ printHeader ("Current branch " )
4144 if prPayload .CurrentPR != nil {
42- printPr (* prPayload .CurrentPR )
45+ printPrs (* prPayload .CurrentPR )
46+ } else {
47+ message := fmt .Sprintf (" There is no pull request associated with %s" , aurora .Cyan ("[" + currentBranch ()+ "]" ))
48+ printMessage (message )
4349 }
44- fmt .Printf ("Your Prs\n " )
45- for _ , pr := range prPayload .ViewerCreated {
46- printPr (pr )
50+ fmt .Println ()
51+
52+ printHeader ("Created by you" )
53+ if len (prPayload .ViewerCreated ) > 0 {
54+ printPrs (prPayload .ViewerCreated ... )
55+ } else {
56+ printMessage (" You have no open pull requests" )
4757 }
48- fmt .Printf ("Prs you need to review\n " )
49- for _ , pr := range prPayload .ReviewRequested {
50- printPr (pr )
58+ fmt .Println ()
59+
60+ printHeader ("Requesting a code review from you" )
61+ if len (prPayload .ReviewRequested ) > 0 {
62+ printPrs (prPayload .ReviewRequested ... )
63+ } else {
64+ printMessage (" You have no pull requests to review" )
5165 }
66+ fmt .Println ()
5267
5368 return nil
5469}
5570
56- func printPr (pr api.PullRequest ) {
57- fmt .Printf (" #%d %s [%s]\n " , pr .Number , pr .Title , pr .HeadRefName )
71+ func printPrs (prs ... api.PullRequest ) {
72+ for _ , pr := range prs {
73+ fmt .Printf (" #%d %s [%s]\n " , pr .Number , truncateTitle (pr .Title ), aurora .Cyan (pr .HeadRefName ))
74+ }
75+ }
76+
77+ func printHeader (s string ) {
78+ fmt .Println (aurora .Bold (s ))
79+ }
80+
81+ func printMessage (s string ) {
82+ fmt .Println (aurora .Gray (8 , s ))
83+ }
84+
85+ func truncateTitle (title string ) string {
86+ const maxLength = 50
87+
88+ if len (title ) > maxLength {
89+ return title [0 :maxLength - 3 ] + "..."
90+ }
91+ return title
92+ }
93+
94+ func currentBranch () string {
95+ currentBranch , err := git .Head ()
96+ if err != nil {
97+ panic (err )
98+ }
99+
100+ return strings .Replace (currentBranch , "refs/heads/" , "" , 1 )
58101}
0 commit comments