renderCalendarTable renders the calendar rows as a markdown table.
(rows []calendarRow)
| 118 | // renderCalendarTable renders the calendar rows as a markdown |
| 119 | // table. |
| 120 | func renderCalendarTable(rows []calendarRow) string { |
| 121 | // Compute column widths. |
| 122 | nameW, dateW, statusW, latestW := 12, 12, 6, 14 |
| 123 | for _, r := range rows { |
| 124 | if len(r.ReleaseName) > nameW { |
| 125 | nameW = len(r.ReleaseName) |
| 126 | } |
| 127 | if len(r.ReleaseDate) > dateW { |
| 128 | dateW = len(r.ReleaseDate) |
| 129 | } |
| 130 | if len(r.Status) > statusW { |
| 131 | statusW = len(r.Status) |
| 132 | } |
| 133 | if len(r.LatestRelease) > latestW { |
| 134 | latestW = len(r.LatestRelease) |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | var b strings.Builder |
| 139 | // Header. |
| 140 | _, _ = fmt.Fprintf(&b, "| %-*s | %-*s | %-*s | %-*s |\n", |
| 141 | nameW, "Release name", |
| 142 | dateW, "Release Date", |
| 143 | statusW, "Status", |
| 144 | latestW, "Latest Release") |
| 145 | // Separator. |
| 146 | _, _ = fmt.Fprintf(&b, "|%s|%s|%s|%s|\n", |
| 147 | strings.Repeat("-", nameW+1), |
| 148 | strings.Repeat("-", dateW+2), |
| 149 | strings.Repeat("-", statusW+2), |
| 150 | strings.Repeat("-", latestW+2)) |
| 151 | // Data rows. |
| 152 | for _, r := range rows { |
| 153 | _, _ = fmt.Fprintf(&b, "| %-*s | %-*s | %-*s | %-*s |\n", |
| 154 | nameW, r.ReleaseName, |
| 155 | dateW, r.ReleaseDate, |
| 156 | statusW, r.Status, |
| 157 | latestW, r.LatestRelease) |
| 158 | } |
| 159 | return b.String() |
| 160 | } |
| 161 | |
| 162 | // updateCalendar modifies the calendar rows based on the new |
| 163 | // release version and channel. |
no test coverage detected