@@ -2,60 +2,35 @@ package printer
2
2
3
3
import (
4
4
"fmt"
5
- "os"
6
- "strings"
7
5
"time"
8
6
9
7
"github.com/gruntwork-io/git-xargs/types"
10
- "github.com/kataras/tablewriter"
11
- "github.com/landoop/tableprinter"
8
+ "github.com/pterm/pterm"
12
9
)
13
10
14
- // configurePrinterStyling accepts a pointer to a table printer and sets up the styles commonly used across them
15
- // resulting in uniform tabular output to STDOUT following each run of the CLI
16
- func configurePrinterStyling (printer * tableprinter.Printer ) {
17
- printer .BorderTop , printer .BorderBottom , printer .BorderLeft , printer .BorderRight = false , false , true , true
18
- printer .CenterSeparator = "|"
19
- printer .ColumnSeparator = "|"
20
- printer .RowSeparator = "-"
21
- printer .HeaderBgColor = tablewriter .BgBlackColor
22
- printer .HeaderFgColor = tablewriter .FgGreenColor
23
- }
24
-
25
11
func PrintRepoReport (allEvents []types.AnnotatedEvent , runReport * types.RunReport ) {
26
- fmt .Print ("\n \n " )
27
- fmt .Println ("*****************************************************************" )
28
- fmt .Printf (" GIT-XARGS RUN SUMMARY @ %v\n " , time .Now ().UTC ())
29
- fmt .Printf (" Runtime in seconds: %v\n " , runReport .RuntimeSeconds )
30
- fmt .Println ("*****************************************************************" )
31
-
32
- // If there were any allowed repos provided via file, print out the list of them
33
- fileProvidedReposPrinter := tableprinter .New (os .Stdout )
34
- configurePrinterStyling (fileProvidedReposPrinter )
35
-
36
- fmt .Print ("\n \n " )
37
-
38
- fmt .Println ("COMMAND SUPPLIED" )
39
- fmt .Println ()
40
- fmt .Println (runReport .Command )
41
- fmt .Println ()
42
- fmt .Println ("REPO SELECTION METHOD USED FOR THIS RUN - (see README.md for more information)" )
43
- fmt .Println ()
44
- fmt .Println (runReport .SelectionMode )
45
-
46
- // If the user selected repos via a flat file, print a table showing which repos they were
12
+ renderSection (fmt .Sprintf ("Git-xargs run summary @ %s" , time .Now ().UTC ()))
13
+
14
+ pterm .DefaultBulletList .WithItems ([]pterm.BulletListItem {
15
+ {Level : 0 , Text : fmt .Sprintf ("Runtime in seconds: %d" , runReport .RuntimeSeconds )},
16
+ {Level : 0 , Text : fmt .Sprintf ("Command supplied: %s" , runReport .Command )},
17
+ {Level : 0 , Text : fmt .Sprintf ("Repo selection method: %s" , runReport .SelectionMode )},
18
+ }).Render ()
19
+
47
20
if len (runReport .FileProvidedRepos ) > 0 {
48
- fmt .Println (" REPOS SUPPLIED VIA --repos FILE FLAG" )
49
- fileProvidedReposPrinter .Print (runReport .FileProvidedRepos )
21
+ renderSection ("Repos supplied via --repos file flag" )
22
+ data := make ([][]string , len (runReport .FileProvidedRepos ))
23
+ for idx , fileProvidedRepo := range runReport .FileProvidedRepos {
24
+ data [idx ] = []string {fmt .Sprintf ("%s/%s" , fileProvidedRepo .Organization , fileProvidedRepo .Name )}
25
+ }
26
+ renderTableWithHeader ([]string {"Repo name" }, data )
50
27
}
51
- // For each event type, print a summary of the repos in that category
28
+
29
+ // For each event type, print a summary table of the repos in that category
52
30
for _ , ae := range allEvents {
53
31
54
32
var reducedRepos []types.ReducedRepo
55
33
56
- printer := tableprinter .New (os .Stdout )
57
- configurePrinterStyling (printer )
58
-
59
34
for _ , repo := range runReport .Repos [ae .Event ] {
60
35
rr := types.ReducedRepo {
61
36
Name : repo .GetName (),
@@ -65,10 +40,14 @@ func PrintRepoReport(allEvents []types.AnnotatedEvent, runReport *types.RunRepor
65
40
}
66
41
67
42
if len (reducedRepos ) > 0 {
68
- fmt .Println ()
69
- fmt .Printf (" %s\n " , strings .ToUpper (ae .Description ))
70
- printer .Print (reducedRepos )
71
- fmt .Println ()
43
+
44
+ renderSection (ae .Description )
45
+ data := make ([][]string , len (reducedRepos ))
46
+ for idx , repo := range reducedRepos {
47
+ data [idx ] = []string {repo .Name , repo .URL }
48
+ }
49
+
50
+ renderTableWithHeader ([]string {"Repo name" , "Repo URL" }, data )
72
51
}
73
52
}
74
53
@@ -93,26 +72,44 @@ func PrintRepoReport(allEvents []types.AnnotatedEvent, runReport *types.RunRepor
93
72
}
94
73
95
74
if len (pullRequests ) > 0 {
96
- fmt .Println ()
97
- fmt .Println ("*****************************************************" )
98
- fmt .Println (" PULL REQUESTS OPENED" )
99
- fmt .Println ("*****************************************************" )
100
- pullRequestPrinter := tableprinter .New (os .Stdout )
101
- configurePrinterStyling (pullRequestPrinter )
102
- pullRequestPrinter .Print (pullRequests )
103
- fmt .Println ()
75
+ renderSection ("Pull requests opened" )
104
76
77
+ data := make ([][]string , len (pullRequests ))
78
+ for idx , pullRequest := range pullRequests {
79
+ data [idx ] = []string {pullRequest .Repo , pullRequest .URL }
80
+ }
81
+
82
+ renderTableWithHeader ([]string {"Repo name" , "Pull request URL" }, data )
105
83
}
106
84
107
85
if len (draftPullRequests ) > 0 {
108
- fmt .Println ()
109
- fmt .Println ("*****************************************************" )
110
- fmt .Println (" DRAFT PULL REQUESTS OPENED" )
111
- fmt .Println ("*****************************************************" )
112
- pullRequestPrinter := tableprinter .New (os .Stdout )
113
- configurePrinterStyling (pullRequestPrinter )
114
- pullRequestPrinter .Print (draftPullRequests )
115
- fmt .Println ()
86
+ renderSection ("Draft Pull requests opened" )
87
+
88
+ data := make ([][]string , len (draftPullRequests ))
89
+ for idx , draftPullRequest := range draftPullRequests {
90
+ data [idx ] = []string {draftPullRequest .Repo , draftPullRequest .URL }
91
+ }
92
+
93
+ renderTableWithHeader ([]string {"Repo name" , "Draft Pull request URL" }, data )
94
+ }
95
+ }
116
96
97
+ func renderSection (sectionTitle string ) {
98
+ pterm .DefaultSection .Style = pterm .NewStyle (pterm .FgLightCyan )
99
+ pterm .DefaultSection .WithLevel (0 ).Println (sectionTitle )
100
+ }
101
+
102
+ func renderTableWithHeader (headers []string , data [][]string ) {
103
+ tableData := pterm.TableData {
104
+ headers ,
105
+ }
106
+ for idx := range data {
107
+ tableData = append (tableData , data [idx ])
117
108
}
109
+ pterm .DefaultTable .
110
+ WithHasHeader ().
111
+ WithBoxed (true ).
112
+ WithRowSeparator ("-" ).
113
+ WithData (tableData ).
114
+ Render ()
118
115
}
0 commit comments