Skip to content

Commit 0520255

Browse files
committed
migrate to the new table configs
Signed-off-by: Carlos Panato <[email protected]>
1 parent 63fe85e commit 0520255

File tree

3 files changed

+113
-25
lines changed

3 files changed

+113
-25
lines changed

cmd/schedule-builder/cmd/markdown.go

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"time"
2727

2828
"github.com/olekukonko/tablewriter"
29+
"github.com/olekukonko/tablewriter/renderer"
30+
"github.com/olekukonko/tablewriter/tw"
2931
"github.com/sirupsen/logrus"
3032

3133
"sigs.k8s.io/release-utils/util"
@@ -42,9 +44,30 @@ func parsePatchSchedule(patchSchedule PatchSchedule) string {
4244
if len(patchSchedule.UpcomingReleases) > 0 {
4345
output = append(output, "### Upcoming Monthly Releases\n")
4446
tableString := &strings.Builder{}
45-
table := tablewriter.NewWriter(tableString)
46-
table.SetAutoWrapText(false)
47-
table.SetHeader([]string{"Monthly Patch Release", "Cherry Pick Deadline", "Target Date"})
47+
table := tablewriter.NewTable(tableString,
48+
tablewriter.WithConfig(tablewriter.Config{
49+
Header: tw.CellConfig{
50+
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
51+
},
52+
}),
53+
tablewriter.WithHeader([]string{"Monthly Patch Release", "Cherry Pick Deadline", "Target Date"}),
54+
tablewriter.WithRenderer(renderer.NewMarkdown()),
55+
tablewriter.WithRendition(tw.Rendition{
56+
Symbols: tw.NewSymbols(tw.StyleMarkdown),
57+
Borders: tw.Border{
58+
Left: tw.On,
59+
Top: tw.Off,
60+
Right: tw.On,
61+
Bottom: tw.Off,
62+
},
63+
Settings: tw.Settings{
64+
Separators: tw.Separators{
65+
BetweenRows: tw.On,
66+
},
67+
},
68+
}),
69+
tablewriter.WithRowAutoWrap(tw.WrapNone),
70+
)
4871

4972
for _, upcoming := range patchSchedule.UpcomingReleases {
5073
targetDate, err := time.Parse(refDate, upcoming.TargetDate)
@@ -61,8 +84,6 @@ func parsePatchSchedule(patchSchedule PatchSchedule) string {
6184
})
6285
}
6386

64-
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
65-
table.SetCenterSeparator("|")
6687
table.Render()
6788

6889
output = append(output, tableString.String())
@@ -79,9 +100,30 @@ func parsePatchSchedule(patchSchedule PatchSchedule) string {
79100
)
80101

81102
tableString := &strings.Builder{}
82-
table := tablewriter.NewWriter(tableString)
83-
table.SetAutoWrapText(false)
84-
table.SetHeader([]string{"Patch Release", "Cherry Pick Deadline", "Target Date", "Note"})
103+
table := tablewriter.NewTable(tableString,
104+
tablewriter.WithConfig(tablewriter.Config{
105+
Header: tw.CellConfig{
106+
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
107+
},
108+
}),
109+
tablewriter.WithHeader([]string{"Patch Release", "Cherry Pick Deadline", "Target Date", "Note"}),
110+
tablewriter.WithRenderer(renderer.NewMarkdown()),
111+
tablewriter.WithRendition(tw.Rendition{
112+
Symbols: tw.NewSymbols(tw.StyleMarkdown),
113+
Borders: tw.Border{
114+
Left: tw.On,
115+
Top: tw.Off,
116+
Right: tw.On,
117+
Bottom: tw.Off,
118+
},
119+
Settings: tw.Settings{
120+
Separators: tw.Separators{
121+
BetweenRows: tw.On,
122+
},
123+
},
124+
}),
125+
tablewriter.WithRowAutoWrap(tw.WrapNone),
126+
)
85127

86128
// Check if the next patch release is in the Previous Patch list, if yes dont read in the output
87129
if !patchReleaseInPreviousList(releaseSchedule.Next.Release, releaseSchedule.PreviousPatches) {
@@ -92,8 +134,6 @@ func parsePatchSchedule(patchSchedule PatchSchedule) string {
92134
table.Append([]string{strings.TrimSpace(previous.Release), strings.TrimSpace(previous.CherryPickDeadline), strings.TrimSpace(previous.TargetDate), strings.TrimSpace(previous.Note)})
93135
}
94136

95-
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
96-
table.SetCenterSeparator("|")
97137
table.Render()
98138

99139
output = append(output, tableString.String())
@@ -131,16 +171,35 @@ func parseReleaseSchedule(releaseSchedule ReleaseSchedule) string {
131171

132172
for _, releaseSchedule := range releaseSchedule.Releases {
133173
tableString := &strings.Builder{}
134-
table := tablewriter.NewWriter(tableString)
135-
table.SetAutoWrapText(false)
136-
table.SetHeader([]string{"**What**", "**Who**", "**When**", "**WEEK**", "**CI Signal**"})
174+
table := tablewriter.NewTable(tableString,
175+
tablewriter.WithConfig(tablewriter.Config{
176+
Header: tw.CellConfig{
177+
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
178+
},
179+
}),
180+
tablewriter.WithHeader([]string{"**What**", "**Who**", "**When**", "**WEEK**", "**CI Signal**"}),
181+
tablewriter.WithRenderer(renderer.NewMarkdown()),
182+
tablewriter.WithRendition(tw.Rendition{
183+
Symbols: tw.NewSymbols(tw.StyleMarkdown),
184+
Borders: tw.Border{
185+
Left: tw.On,
186+
Top: tw.Off,
187+
Right: tw.On,
188+
Bottom: tw.Off,
189+
},
190+
Settings: tw.Settings{
191+
Separators: tw.Separators{
192+
BetweenRows: tw.On,
193+
},
194+
},
195+
}),
196+
tablewriter.WithRowAutoWrap(tw.WrapNone),
197+
)
137198

138199
for _, timeline := range releaseSchedule.Timeline {
139200
table.Append([]string{strings.TrimSpace(timeline.What), strings.TrimSpace(timeline.Who), strings.TrimSpace(timeline.When), strings.TrimSpace(timeline.Week), strings.TrimSpace(timeline.CISignal), ""})
140201
}
141202

142-
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
143-
table.SetCenterSeparator("|")
144203
table.Render()
145204

146205
relSched.TimelineOutput = tableString.String()

pkg/gcp/build/build.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929

3030
"github.com/google/uuid"
3131
"github.com/olekukonko/tablewriter"
32+
"github.com/olekukonko/tablewriter/renderer"
33+
"github.com/olekukonko/tablewriter/tw"
3234
"github.com/sirupsen/logrus"
3335
"golang.org/x/net/context"
3436
"google.golang.org/api/cloudbuild/v1"
@@ -404,8 +406,17 @@ func ListJobs(project string, lastJobs int64) error {
404406
return fmt.Errorf("failed to listing the builds: %w", err)
405407
}
406408

407-
table := tablewriter.NewWriter(os.Stdout)
408-
table.SetHeader([]string{"Start Time", "Finish Time", "Status", "Console Logs"})
409+
table := tablewriter.NewTable(os.Stdout,
410+
tablewriter.WithConfig(tablewriter.Config{
411+
Header: tw.CellConfig{
412+
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
413+
},
414+
}),
415+
tablewriter.WithHeader([]string{"Start Time", "Finish Time", "Status", "Console Logs"}),
416+
tablewriter.WithRenderer(renderer.NewMarkdown()),
417+
tablewriter.WithRendition(tw.Rendition{Symbols: tw.NewSymbols(tw.StyleMarkdown)}),
418+
tablewriter.WithRowAutoWrap(tw.WrapNone),
419+
)
409420

410421
for _, build := range req.Builds {
411422
table.Append([]string{strings.TrimSpace(build.StartTime), strings.TrimSpace(build.FinishTime), strings.TrimSpace(build.Status), strings.TrimSpace(build.LogUrl)})

pkg/gcp/gcb/history.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"time"
2424

2525
"github.com/olekukonko/tablewriter"
26+
"github.com/olekukonko/tablewriter/renderer"
27+
"github.com/olekukonko/tablewriter/tw"
2628
"github.com/sirupsen/logrus"
2729
"google.golang.org/api/cloudbuild/v1"
2830

@@ -121,10 +123,30 @@ func (h *History) Run() error {
121123
}
122124

123125
tableString := &strings.Builder{}
124-
table := tablewriter.NewWriter(tableString)
125-
table.SetAutoWrapText(false)
126-
127-
table.SetHeader([]string{"Step", "Command", "Link", "Start", "Duration", "Succeeded?"})
126+
table := tablewriter.NewTable(tableString,
127+
tablewriter.WithConfig(tablewriter.Config{
128+
Header: tw.CellConfig{
129+
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
130+
},
131+
}),
132+
tablewriter.WithHeader([]string{"Step", "Command", "Link", "Start", "Duration", "Succeeded?"}),
133+
tablewriter.WithRenderer(renderer.NewMarkdown()),
134+
tablewriter.WithRendition(tw.Rendition{
135+
Symbols: tw.NewSymbols(tw.StyleMarkdown),
136+
Borders: tw.Border{
137+
Left: tw.On,
138+
Top: tw.Off,
139+
Right: tw.On,
140+
Bottom: tw.Off,
141+
},
142+
Settings: tw.Settings{
143+
Separators: tw.Separators{
144+
BetweenRows: tw.On,
145+
},
146+
},
147+
}),
148+
tablewriter.WithRowAutoWrap(tw.WrapNone),
149+
)
128150

129151
for i := len(jobs) - 1; i >= 0; i-- {
130152
job := jobs[i]
@@ -189,10 +211,6 @@ func (h *History) Run() error {
189211
})
190212
}
191213

192-
table.SetBorders(tablewriter.Border{
193-
Left: true, Top: false, Right: true, Bottom: false,
194-
})
195-
table.SetCenterSeparator("|")
196214
table.Render()
197215

198216
fmt.Print(tableString.String())

0 commit comments

Comments
 (0)