Skip to content

upgrade tablewriter #4026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions cmd/ci-reporter/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"time"

"github.com/olekukonko/tablewriter"
"github.com/olekukonko/tablewriter/renderer"
"github.com/olekukonko/tablewriter/tw"
"github.com/shurcooL/githubv4"
"github.com/spf13/cobra"
"github.com/tj/go-spin"
Expand Down Expand Up @@ -245,18 +247,39 @@ func PrintReporterData(cfg *Config, reports *CIReportDataFields) error {
return fmt.Errorf("could not write to output stream: %w", err)
}

table := tablewriter.NewWriter(out)
data := [][]string{}
table := tablewriter.NewTable(out,
tablewriter.WithConfig(tablewriter.Config{
Header: tw.CellConfig{
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
},
}),
tablewriter.WithHeader([]string{"TESTGRID BOARD", "TITLE", "STATUS", "STATUS DETAILS"}),
tablewriter.WithRenderer(renderer.NewMarkdown()),
tablewriter.WithRendition(tw.Rendition{
Symbols: tw.NewSymbols(tw.StyleMarkdown),
Borders: tw.Border{
Left: tw.On,
Top: tw.Off,
Right: tw.On,
Bottom: tw.Off,
},
Settings: tw.Settings{
Separators: tw.Separators{
BetweenRows: tw.On,
},
},
}),
tablewriter.WithRowAutoWrap(tw.WrapNone),
)

// table in short version differs from regular table
if cfg.ShortReport {
table.SetHeader([]string{"TESTGRID BOARD", "TITLE", "STATUS", "STATUS DETAILS"})

for _, record := range r.Records {
data = append(data, []string{record.TestgridBoard, record.Title, record.Status, record.StatusDetails})
}
} else {
table.SetHeader([]string{"TESTGRID BOARD", "TITLE", "STATUS", "STATUS DETAILS", "URL", "UPDATED AT"})
table.Options(tablewriter.WithHeader([]string{"TESTGRID BOARD", "TITLE", "STATUS", "STATUS DETAILS", "URL", "UPDATED AT"}))

for _, record := range r.Records {
data = append(data, []string{
Expand All @@ -269,10 +292,13 @@ func PrintReporterData(cfg *Config, reports *CIReportDataFields) error {
}
}

table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.AppendBulk(data)
table.SetCenterSeparator("|")
table.Render()
if err := table.Bulk(data); err != nil {
return err
}

if err := table.Render(); err != nil {
return err
}

// write a summary
countCategories := map[string]int{}
Expand Down
110 changes: 88 additions & 22 deletions cmd/schedule-builder/cmd/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"time"

"github.com/olekukonko/tablewriter"
"github.com/olekukonko/tablewriter/renderer"
"github.com/olekukonko/tablewriter/tw"
"github.com/sirupsen/logrus"

"sigs.k8s.io/release-utils/util"
Expand All @@ -42,9 +44,30 @@ func parsePatchSchedule(patchSchedule PatchSchedule) string {
if len(patchSchedule.UpcomingReleases) > 0 {
output = append(output, "### Upcoming Monthly Releases\n")
tableString := &strings.Builder{}
table := tablewriter.NewWriter(tableString)
table.SetAutoWrapText(false)
table.SetHeader([]string{"Monthly Patch Release", "Cherry Pick Deadline", "Target Date"})
table := tablewriter.NewTable(tableString,
tablewriter.WithConfig(tablewriter.Config{
Header: tw.CellConfig{
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
},
}),
tablewriter.WithHeader([]string{"Monthly Patch Release", "Cherry Pick Deadline", "Target Date"}),
tablewriter.WithRenderer(renderer.NewMarkdown()),
tablewriter.WithRendition(tw.Rendition{
Symbols: tw.NewSymbols(tw.StyleMarkdown),
Borders: tw.Border{
Left: tw.On,
Top: tw.Off,
Right: tw.On,
Bottom: tw.Off,
},
Settings: tw.Settings{
Separators: tw.Separators{
BetweenRows: tw.On,
},
},
}),
tablewriter.WithRowAutoWrap(tw.WrapNone),
)

for _, upcoming := range patchSchedule.UpcomingReleases {
targetDate, err := time.Parse(refDate, upcoming.TargetDate)
Expand All @@ -54,16 +77,14 @@ func parsePatchSchedule(patchSchedule PatchSchedule) string {
continue
}

table.Append([]string{
_ = table.Append([]string{
targetDate.Format(refDateMonthly),
strings.TrimSpace(upcoming.CherryPickDeadline),
strings.TrimSpace(upcoming.TargetDate),
})
}

table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.SetCenterSeparator("|")
table.Render()
_ = table.Render()

output = append(output, tableString.String())
}
Expand All @@ -79,22 +100,44 @@ func parsePatchSchedule(patchSchedule PatchSchedule) string {
)

tableString := &strings.Builder{}
table := tablewriter.NewWriter(tableString)
table.SetAutoWrapText(false)
table.SetHeader([]string{"Patch Release", "Cherry Pick Deadline", "Target Date", "Note"})
table := tablewriter.NewTable(tableString,
tablewriter.WithConfig(tablewriter.Config{
Header: tw.CellConfig{
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
},
Row: tw.CellConfig{
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
},
}),
tablewriter.WithHeader([]string{"Patch Release", "Cherry Pick Deadline", "Target Date", "Note"}),
tablewriter.WithRenderer(renderer.NewMarkdown()),
tablewriter.WithRendition(tw.Rendition{
Symbols: tw.NewSymbols(tw.StyleMarkdown),
Borders: tw.Border{
Left: tw.On,
Top: tw.Off,
Right: tw.On,
Bottom: tw.Off,
},
Settings: tw.Settings{
Separators: tw.Separators{
BetweenRows: tw.On,
},
},
}),
tablewriter.WithRowAutoWrap(tw.WrapNone),
)

// Check if the next patch release is in the Previous Patch list, if yes dont read in the output
if !patchReleaseInPreviousList(releaseSchedule.Next.Release, releaseSchedule.PreviousPatches) {
table.Append([]string{strings.TrimSpace(releaseSchedule.Next.Release), strings.TrimSpace(releaseSchedule.Next.CherryPickDeadline), strings.TrimSpace(releaseSchedule.Next.TargetDate), ""})
_ = table.Append([]string{strings.TrimSpace(releaseSchedule.Next.Release), strings.TrimSpace(releaseSchedule.Next.CherryPickDeadline), strings.TrimSpace(releaseSchedule.Next.TargetDate), ""})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we completely ignore the error? We should at least log it so we know that there's something wrong going on, otherwise we might just not notice that we're missing some data.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same in other places where this is present

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was already ignoring the error, but will add a log on that

}

for _, previous := range releaseSchedule.PreviousPatches {
table.Append([]string{strings.TrimSpace(previous.Release), strings.TrimSpace(previous.CherryPickDeadline), strings.TrimSpace(previous.TargetDate), strings.TrimSpace(previous.Note)})
_ = table.Append([]string{strings.TrimSpace(previous.Release), strings.TrimSpace(previous.CherryPickDeadline), strings.TrimSpace(previous.TargetDate), strings.TrimSpace(previous.Note)})
}

table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.SetCenterSeparator("|")
table.Render()
_ = table.Render()

output = append(output, tableString.String())
}
Expand Down Expand Up @@ -131,17 +174,40 @@ func parseReleaseSchedule(releaseSchedule ReleaseSchedule) string {

for _, releaseSchedule := range releaseSchedule.Releases {
tableString := &strings.Builder{}
table := tablewriter.NewWriter(tableString)
table.SetAutoWrapText(false)
table.SetHeader([]string{"**What**", "**Who**", "**When**", "**WEEK**", "**CI Signal**"})
table := tablewriter.NewTable(tableString,
tablewriter.WithConfig(tablewriter.Config{
Header: tw.CellConfig{
Alignment: tw.CellAlignment{Global: tw.AlignCenter},
},
Row: tw.CellConfig{
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
},
}),
tablewriter.WithHeader([]string{"**What**", "**Who**", "**When**", "**WEEK**", "**CI Signal**"}),
tablewriter.WithRenderer(renderer.NewMarkdown()),
tablewriter.WithRendition(tw.Rendition{
Symbols: tw.NewSymbols(tw.StyleMarkdown),
Borders: tw.Border{
Left: tw.On,
Top: tw.Off,
Right: tw.On,
Bottom: tw.Off,
},
Settings: tw.Settings{
Separators: tw.Separators{
BetweenRows: tw.On,
BetweenColumns: tw.Off,
},
},
}),
tablewriter.WithRowAutoWrap(tw.WrapNone),
)

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

table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.SetCenterSeparator("|")
table.Render()
_ = table.Render()

relSched.TimelineOutput = tableString.String()
}
Expand Down
32 changes: 16 additions & 16 deletions cmd/schedule-builder/cmd/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
const expectedPatchSchedule = `### Upcoming Monthly Releases

| MONTHLY PATCH RELEASE | CHERRY PICK DEADLINE | TARGET DATE |
|-----------------------|----------------------|-------------|
|:----------------------|:---------------------|:------------|
| June 2020 | 2020-06-12 | 2020-06-17 |

### Timeline
Expand All @@ -43,7 +43,7 @@ Next patch release is **X.Y.ZZZ**
**X.Y** enters maintenance mode on **THEN** and End of Life is on **NOW**.

| PATCH RELEASE | CHERRY PICK DEADLINE | TARGET DATE | NOTE |
|---------------|----------------------|-------------|------|
|:--------------|:---------------------|:------------|:-----|
| X.Y.ZZZ | 2020-06-12 | 2020-06-17 | |
| X.Y.XXX | 2020-05-15 | 2020-05-20 | honk |
| X.Y.YYY | 2020-04-13 | 2020-04-16 | |
Expand Down Expand Up @@ -91,20 +91,20 @@ The X.Y release cycle is proposed as follows:

## Timeline

| **WHAT** | **WHO** | **WHEN** | **WEEK** | **CI SIGNAL** | |
|-----------|---------|------------|----------|---------------|--|
| Testing-A | tester | 2020-06-17 | week 1 | green | |
| Testing-B | tester | 2020-06-19 | week 1 | green | |
| Testing-C | tester | 2020-06-20 | week 1 | green | |
| Testing-D | tester | 2020-06-21 | week 1 | green | |
| Testing-E | tester | 2020-06-22 | week 1 | green | |
| Testing-F | tester | 2020-06-25 | week 2 | green | |
| Testing-G | tester | 2020-06-26 | week 2 | green | |
| Testing-H | tester | 2020-06-27 | week 2 | green | |
| Testing-I | tester | 2020-06-27 | week 2 | green | |
| Testing-J | tester | 2020-06-27 | week 2 | green | |
| Testing-K | tester | 2020-06-28 | week 2 | green | |
| Testing-L | tester | 2020-06-28 | week 2 | green | |
| ** WHAT ** | ** WHO ** | ** WHEN ** | ** WEEK ** | ** CI SIGNAL ** | |
|:----------:|:---------:|:----------:|:----------:|:---------------:|:-:|
| Testing-A | tester | 2020-06-17 | week 1 | green | |
| Testing-B | tester | 2020-06-19 | week 1 | green | |
| Testing-C | tester | 2020-06-20 | week 1 | green | |
| Testing-D | tester | 2020-06-21 | week 1 | green | |
| Testing-E | tester | 2020-06-22 | week 1 | green | |
| Testing-F | tester | 2020-06-25 | week 2 | green | |
| Testing-G | tester | 2020-06-26 | week 2 | green | |
| Testing-H | tester | 2020-06-27 | week 2 | green | |
| Testing-I | tester | 2020-06-27 | week 2 | green | |
| Testing-J | tester | 2020-06-27 | week 2 | green | |
| Testing-K | tester | 2020-06-28 | week 2 | green | |
| Testing-L | tester | 2020-06-28 | week 2 | green | |

## Phases

Expand Down
Loading