Skip to content

Commit 52483f8

Browse files
committed
migrate to the new table configs
Signed-off-by: Carlos Panato <ctadeu@gmail.com> more fixes Signed-off-by: Carlos Panato <ctadeu@gmail.com> fix lints Signed-off-by: Carlos Panato <ctadeu@gmail.com> more fixes Signed-off-by: Carlos Panato <ctadeu@gmail.com> revert upgrade for now
1 parent e169c8e commit 52483f8

File tree

8 files changed

+243
-113
lines changed

8 files changed

+243
-113
lines changed

cmd/ci-reporter/cmd/root.go

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ import (
2525
"time"
2626

2727
"github.com/olekukonko/tablewriter"
28+
"github.com/olekukonko/tablewriter/renderer"
29+
"github.com/olekukonko/tablewriter/tw"
2830
"github.com/shurcooL/githubv4"
2931
"github.com/spf13/cobra"
3032
"github.com/tj/go-spin"
3133
"golang.org/x/net/context"
34+
35+
"sigs.k8s.io/release-utils/util"
3236
)
3337

3438
var rootCmd = &cobra.Command{
@@ -245,18 +249,38 @@ func PrintReporterData(cfg *Config, reports *CIReportDataFields) error {
245249
return fmt.Errorf("could not write to output stream: %w", err)
246250
}
247251

248-
table := tablewriter.NewWriter(out)
249252
data := [][]string{}
253+
table := util.NewTableWriter(out, tablewriter.WithConfig(tablewriter.Config{
254+
Header: tw.CellConfig{
255+
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
256+
},
257+
}),
258+
tablewriter.WithHeader([]string{"TESTGRID BOARD", "TITLE", "STATUS", "STATUS DETAILS"}),
259+
tablewriter.WithRenderer(renderer.NewMarkdown()),
260+
tablewriter.WithRendition(tw.Rendition{
261+
Symbols: tw.NewSymbols(tw.StyleMarkdown),
262+
Borders: tw.Border{
263+
Left: tw.On,
264+
Top: tw.Off,
265+
Right: tw.On,
266+
Bottom: tw.Off,
267+
},
268+
Settings: tw.Settings{
269+
Separators: tw.Separators{
270+
BetweenRows: tw.On,
271+
},
272+
},
273+
}),
274+
tablewriter.WithRowAutoWrap(tw.WrapNone),
275+
)
250276

251277
// table in short version differs from regular table
252278
if cfg.ShortReport {
253-
table.SetHeader([]string{"TESTGRID BOARD", "TITLE", "STATUS", "STATUS DETAILS"})
254-
255279
for _, record := range r.Records {
256280
data = append(data, []string{record.TestgridBoard, record.Title, record.Status, record.StatusDetails})
257281
}
258282
} else {
259-
table.SetHeader([]string{"TESTGRID BOARD", "TITLE", "STATUS", "STATUS DETAILS", "URL", "UPDATED AT"})
283+
table.Options(tablewriter.WithHeader([]string{"TESTGRID BOARD", "TITLE", "STATUS", "STATUS DETAILS", "URL", "UPDATED AT"}))
260284

261285
for _, record := range r.Records {
262286
data = append(data, []string{
@@ -269,10 +293,13 @@ func PrintReporterData(cfg *Config, reports *CIReportDataFields) error {
269293
}
270294
}
271295

272-
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
273-
table.AppendBulk(data)
274-
table.SetCenterSeparator("|")
275-
table.Render()
296+
if err := table.Bulk(data); err != nil {
297+
return err
298+
}
299+
300+
if err := table.Render(); err != nil {
301+
return err
302+
}
276303

277304
// write a summary
278305
countCategories := map[string]int{}

cmd/schedule-builder/cmd/markdown.go

Lines changed: 88 additions & 22 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)
@@ -54,16 +77,14 @@ func parsePatchSchedule(patchSchedule PatchSchedule) string {
5477
continue
5578
}
5679

57-
table.Append([]string{
80+
_ = table.Append([]string{
5881
targetDate.Format(refDateMonthly),
5982
strings.TrimSpace(upcoming.CherryPickDeadline),
6083
strings.TrimSpace(upcoming.TargetDate),
6184
})
6285
}
6386

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

6889
output = append(output, tableString.String())
6990
}
@@ -79,22 +100,44 @@ 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+
Row: tw.CellConfig{
109+
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
110+
},
111+
}),
112+
tablewriter.WithHeader([]string{"Patch Release", "Cherry Pick Deadline", "Target Date", "Note"}),
113+
tablewriter.WithRenderer(renderer.NewMarkdown()),
114+
tablewriter.WithRendition(tw.Rendition{
115+
Symbols: tw.NewSymbols(tw.StyleMarkdown),
116+
Borders: tw.Border{
117+
Left: tw.On,
118+
Top: tw.Off,
119+
Right: tw.On,
120+
Bottom: tw.Off,
121+
},
122+
Settings: tw.Settings{
123+
Separators: tw.Separators{
124+
BetweenRows: tw.On,
125+
},
126+
},
127+
}),
128+
tablewriter.WithRowAutoWrap(tw.WrapNone),
129+
)
85130

86131
// Check if the next patch release is in the Previous Patch list, if yes dont read in the output
87132
if !patchReleaseInPreviousList(releaseSchedule.Next.Release, releaseSchedule.PreviousPatches) {
88-
table.Append([]string{strings.TrimSpace(releaseSchedule.Next.Release), strings.TrimSpace(releaseSchedule.Next.CherryPickDeadline), strings.TrimSpace(releaseSchedule.Next.TargetDate), ""})
133+
_ = table.Append([]string{strings.TrimSpace(releaseSchedule.Next.Release), strings.TrimSpace(releaseSchedule.Next.CherryPickDeadline), strings.TrimSpace(releaseSchedule.Next.TargetDate), ""})
89134
}
90135

91136
for _, previous := range releaseSchedule.PreviousPatches {
92-
table.Append([]string{strings.TrimSpace(previous.Release), strings.TrimSpace(previous.CherryPickDeadline), strings.TrimSpace(previous.TargetDate), strings.TrimSpace(previous.Note)})
137+
_ = table.Append([]string{strings.TrimSpace(previous.Release), strings.TrimSpace(previous.CherryPickDeadline), strings.TrimSpace(previous.TargetDate), strings.TrimSpace(previous.Note)})
93138
}
94139

95-
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
96-
table.SetCenterSeparator("|")
97-
table.Render()
140+
_ = table.Render()
98141

99142
output = append(output, tableString.String())
100143
}
@@ -131,17 +174,40 @@ func parseReleaseSchedule(releaseSchedule ReleaseSchedule) string {
131174

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

138206
for _, timeline := range releaseSchedule.Timeline {
139-
table.Append([]string{strings.TrimSpace(timeline.What), strings.TrimSpace(timeline.Who), strings.TrimSpace(timeline.When), strings.TrimSpace(timeline.Week), strings.TrimSpace(timeline.CISignal), ""})
207+
_ = table.Append([]string{strings.TrimSpace(timeline.What), strings.TrimSpace(timeline.Who), strings.TrimSpace(timeline.When), strings.TrimSpace(timeline.Week), strings.TrimSpace(timeline.CISignal), ""})
140208
}
141209

142-
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
143-
table.SetCenterSeparator("|")
144-
table.Render()
210+
_ = table.Render()
145211

146212
relSched.TimelineOutput = tableString.String()
147213
}

cmd/schedule-builder/cmd/markdown_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
const expectedPatchSchedule = `### Upcoming Monthly Releases
3232
3333
| MONTHLY PATCH RELEASE | CHERRY PICK DEADLINE | TARGET DATE |
34-
|-----------------------|----------------------|-------------|
34+
|:----------------------|:---------------------|:------------|
3535
| June 2020 | 2020-06-12 | 2020-06-17 |
3636
3737
### Timeline
@@ -43,7 +43,7 @@ Next patch release is **X.Y.ZZZ**
4343
**X.Y** enters maintenance mode on **THEN** and End of Life is on **NOW**.
4444
4545
| PATCH RELEASE | CHERRY PICK DEADLINE | TARGET DATE | NOTE |
46-
|---------------|----------------------|-------------|------|
46+
|:--------------|:---------------------|:------------|:-----|
4747
| X.Y.ZZZ | 2020-06-12 | 2020-06-17 | |
4848
| X.Y.XXX | 2020-05-15 | 2020-05-20 | honk |
4949
| X.Y.YYY | 2020-04-13 | 2020-04-16 | |
@@ -91,20 +91,20 @@ The X.Y release cycle is proposed as follows:
9191
9292
## Timeline
9393
94-
| **WHAT** | **WHO** | **WHEN** | **WEEK** | **CI SIGNAL** | |
95-
|-----------|---------|------------|----------|---------------|--|
96-
| Testing-A | tester | 2020-06-17 | week 1 | green | |
97-
| Testing-B | tester | 2020-06-19 | week 1 | green | |
98-
| Testing-C | tester | 2020-06-20 | week 1 | green | |
99-
| Testing-D | tester | 2020-06-21 | week 1 | green | |
100-
| Testing-E | tester | 2020-06-22 | week 1 | green | |
101-
| Testing-F | tester | 2020-06-25 | week 2 | green | |
102-
| Testing-G | tester | 2020-06-26 | week 2 | green | |
103-
| Testing-H | tester | 2020-06-27 | week 2 | green | |
104-
| Testing-I | tester | 2020-06-27 | week 2 | green | |
105-
| Testing-J | tester | 2020-06-27 | week 2 | green | |
106-
| Testing-K | tester | 2020-06-28 | week 2 | green | |
107-
| Testing-L | tester | 2020-06-28 | week 2 | green | |
94+
| ** WHAT ** | ** WHO ** | ** WHEN ** | ** WEEK ** | ** CI SIGNAL ** | |
95+
|:----------:|:---------:|:----------:|:----------:|:---------------:|:-:|
96+
| Testing-A | tester | 2020-06-17 | week 1 | green | |
97+
| Testing-B | tester | 2020-06-19 | week 1 | green | |
98+
| Testing-C | tester | 2020-06-20 | week 1 | green | |
99+
| Testing-D | tester | 2020-06-21 | week 1 | green | |
100+
| Testing-E | tester | 2020-06-22 | week 1 | green | |
101+
| Testing-F | tester | 2020-06-25 | week 2 | green | |
102+
| Testing-G | tester | 2020-06-26 | week 2 | green | |
103+
| Testing-H | tester | 2020-06-27 | week 2 | green | |
104+
| Testing-I | tester | 2020-06-27 | week 2 | green | |
105+
| Testing-J | tester | 2020-06-27 | week 2 | green | |
106+
| Testing-K | tester | 2020-06-28 | week 2 | green | |
107+
| Testing-L | tester | 2020-06-28 | week 2 | green | |
108108
109109
## Phases
110110

0 commit comments

Comments
 (0)