Skip to content

Commit 1c00fec

Browse files
authored
Merge pull request #4085 from kubernetes/dependabot/go_modules/sigs.k8s.io/release-utils-0.12.1
Bump sigs.k8s.io/release-utils from 0.11.1 to 0.12.1
2 parents 80a37c7 + 83daae1 commit 1c00fec

33 files changed

+381
-396
lines changed

cmd/ci-reporter/cmd/root.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ import (
2424
"strings"
2525
"time"
2626

27-
"github.com/olekukonko/tablewriter"
2827
"github.com/shurcooL/githubv4"
2928
"github.com/spf13/cobra"
3029
"github.com/tj/go-spin"
3130
"golang.org/x/net/context"
31+
32+
"sigs.k8s.io/release-utils/helpers"
3233
)
3334

3435
var rootCmd = &cobra.Command{
@@ -245,18 +246,18 @@ func PrintReporterData(cfg *Config, reports *CIReportDataFields) error {
245246
return fmt.Errorf("could not write to output stream: %w", err)
246247
}
247248

248-
table := tablewriter.NewWriter(out)
249+
table := helpers.NewTableWriter(out)
249250
data := [][]string{}
250251

251252
// table in short version differs from regular table
252253
if cfg.ShortReport {
253-
table.SetHeader([]string{"TESTGRID BOARD", "TITLE", "STATUS", "STATUS DETAILS"})
254+
table.Header([]string{"TESTGRID BOARD", "TITLE", "STATUS", "STATUS DETAILS"})
254255

255256
for _, record := range r.Records {
256257
data = append(data, []string{record.TestgridBoard, record.Title, record.Status, record.StatusDetails})
257258
}
258259
} else {
259-
table.SetHeader([]string{"TESTGRID BOARD", "TITLE", "STATUS", "STATUS DETAILS", "URL", "UPDATED AT"})
260+
table.Header([]string{"TESTGRID BOARD", "TITLE", "STATUS", "STATUS DETAILS", "URL", "UPDATED AT"})
260261

261262
for _, record := range r.Records {
262263
data = append(data, []string{
@@ -269,10 +270,8 @@ func PrintReporterData(cfg *Config, reports *CIReportDataFields) error {
269270
}
270271
}
271272

272-
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
273-
table.AppendBulk(data)
274-
table.SetCenterSeparator("|")
275-
table.Render()
273+
_ = table.Bulk(data)
274+
_ = table.Render()
276275

277276
// write a summary
278277
countCategories := map[string]int{}

cmd/krel/cmd/announce_send.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
"github.com/spf13/cobra"
2525

2626
"sigs.k8s.io/release-utils/env"
27+
"sigs.k8s.io/release-utils/helpers"
2728
"sigs.k8s.io/release-utils/http"
28-
"sigs.k8s.io/release-utils/util"
2929

3030
"k8s.io/release/pkg/mail"
3131
"k8s.io/release/pkg/release"
@@ -116,7 +116,7 @@ func runAnnounce(opts *sendAnnounceOptions, announceRootOpts *announceOptions, r
116116

117117
logrus.Info("Retrieving release announcement from Google Cloud Bucket")
118118

119-
tag := util.AddTagPrefix(announceRootOpts.tag)
119+
tag := helpers.AddTagPrefix(announceRootOpts.tag)
120120
u := fmt.Sprintf(
121121
"%s/release/%s/announcement.html",
122122
release.URLPrefixForBucket(release.ProductionBucket), tag,
@@ -180,7 +180,7 @@ func runAnnounce(opts *sendAnnounceOptions, announceRootOpts *announceOptions, r
180180
yes := true
181181

182182
if rootOpts.nomock {
183-
_, yes, err = util.Ask("Send email? (y/N)", "y:Y:yes|n:N:no|N", 10)
183+
_, yes, err = helpers.Ask("Send email? (y/N)", "y:Y:yes|n:N:no|N", 10)
184184
if err != nil {
185185
return err
186186
}

cmd/krel/cmd/release_notes.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
"sigs.k8s.io/release-sdk/github"
4141
"sigs.k8s.io/release-utils/command"
4242
"sigs.k8s.io/release-utils/editor"
43-
"sigs.k8s.io/release-utils/util"
43+
"sigs.k8s.io/release-utils/helpers"
4444

4545
"k8s.io/release/pkg/notes"
4646
"k8s.io/release/pkg/notes/document"
@@ -323,14 +323,14 @@ func runReleaseNotes() (err error) {
323323

324324
// createDraftPR pushes the release notes draft to the users fork.
325325
func createDraftPR(repoPath, tag string) (err error) {
326-
tagVersion, err := util.TagStringToSemver(tag)
326+
tagVersion, err := helpers.TagStringToSemver(tag)
327327
if err != nil {
328328
return fmt.Errorf("reading tag: %s: %w", tag, err)
329329
}
330330

331331
// From v1.20.0 on we use the previous minor as a starting tag
332332
// for the Release Notes draft because the branch is fast-rowarded now:
333-
start := util.SemverToTagString(semver.Version{
333+
start := helpers.SemverToTagString(semver.Version{
334334
Major: tagVersion.Major,
335335
Minor: tagVersion.Minor - 1,
336336
Patch: 0,
@@ -389,13 +389,13 @@ func createDraftPR(repoPath, tag string) (err error) {
389389

390390
// Check if the directory exists
391391
releaseDir := filepath.Join(sigReleaseRepo.Dir(), releasePath)
392-
if !util.Exists(releaseDir) {
392+
if !helpers.Exists(releaseDir) {
393393
return fmt.Errorf("could not find release directory %s", releaseDir)
394394
}
395395

396396
// If we got the --fix flag, start the fix flow
397397
if releaseNotesOpts.fixNotes {
398-
_, _, err = util.Ask("Press enter to start", "y:yes|n:no|y", 10)
398+
_, _, err = helpers.Ask("Press enter to start", "y:yes|n:no|y", 10)
399399
// In interactive mode, we will ask the user before sending the PR
400400
autoCreatePullRequest = false
401401

@@ -461,7 +461,7 @@ func createDraftPR(repoPath, tag string) (err error) {
461461

462462
// If we are in interactive mode, ask before continuing
463463
if !autoCreatePullRequest {
464-
_, autoCreatePullRequest, err = util.Ask("Create pull request with your changes? (y/n)", "y:Y:yes|n:N:no|y", 10)
464+
_, autoCreatePullRequest, err = helpers.Ask("Create pull request with your changes? (y/n)", "y:Y:yes|n:N:no|y", 10)
465465
if err != nil {
466466
return fmt.Errorf("while asking to create pull request: %w", err)
467467
}
@@ -578,7 +578,7 @@ func createDraftCommit(repo *git.Repo, releasePath, commitMessage string) error
578578
// Add to the PR all files that exist
579579
for _, dirData := range releaseDirectories {
580580
// add the updated maps
581-
if util.Exists(filepath.Join(repo.Dir(), dirData.Path)) {
581+
if helpers.Exists(filepath.Join(repo.Dir(), dirData.Path)) {
582582
// Check if there are any files to commit
583583
matches, err := filepath.Glob(filepath.Join(repo.Dir(), dirData.Path, "*"+dirData.Ext))
584584
logrus.Debugf("Adding %d %s from %s to commit", len(matches), dirData.Name, dirData.Path)
@@ -690,7 +690,7 @@ func processJSONOutput(repoPath string) error {
690690

691691
// createWebsitePR creates the JSON version of the release notes and pushes them to a user fork.
692692
func createWebsitePR(repoPath, tag string) (err error) {
693-
_, err = util.TagStringToSemver(tag)
693+
_, err = helpers.TagStringToSemver(tag)
694694
if err != nil {
695695
return fmt.Errorf("reading tag: %s: %w", tag, err)
696696
}
@@ -819,7 +819,7 @@ func tryToFindLatestMinorTag() (string, error) {
819819
func releaseNotesJSON(repoPath, tag string) (jsonString string, err error) {
820820
logrus.Infof("Generating release notes for tag %s", tag)
821821

822-
tagVersion, err := util.TagStringToSemver(tag)
822+
tagVersion, err := helpers.TagStringToSemver(tag)
823823
if err != nil {
824824
return "", fmt.Errorf("parsing semver from tag string: %w", err)
825825
}
@@ -876,14 +876,14 @@ func releaseNotesJSON(repoPath, tag string) (jsonString string, err error) {
876876
if len(tagVersion.Pre) == 2 && //nolint:gocritic // a switch case would not make it better
877877
tagVersion.Pre[0].String() == "alpha" &&
878878
tagVersion.Pre[1].VersionNum == 1 {
879-
startTag = util.SemverToTagString(semver.Version{
879+
startTag = helpers.SemverToTagString(semver.Version{
880880
Major: tagVersion.Major, Minor: tagVersion.Minor - 1, Patch: 0,
881881
})
882882
tagChoice = "previous minor version"
883883
} else if len(tagVersion.Pre) == 0 && tagVersion.Patch == 0 {
884884
// If we are writing the notes for the first minor version (eg 1.20.0)
885885
// we choose as the start tag also the previous minor
886-
startTag = util.SemverToTagString(semver.Version{
886+
startTag = helpers.SemverToTagString(semver.Version{
887887
Major: tagVersion.Major, Minor: tagVersion.Minor - 1, Patch: 0,
888888
})
889889
tagChoice = "previous minor version because we are in a new minor version"
@@ -917,7 +917,7 @@ func releaseNotesJSON(repoPath, tag string) (jsonString string, err error) {
917917
fmt.Sprintf("release-%d.%d", tagVersion.Major, tagVersion.Minor),
918918
releaseNotesWorkDir, mapsMainDirectory,
919919
)
920-
if util.Exists(mapsDir) {
920+
if helpers.Exists(mapsDir) {
921921
logrus.Infof("Notes gatherer will read maps from %s", mapsDir)
922922
notesOptions.MapProviderStrings = append(notesOptions.MapProviderStrings, mapsDir)
923923
}
@@ -1020,7 +1020,7 @@ func (o *releaseNotesOptions) Validate() error {
10201020
}
10211021

10221022
// If a tag is defined, see if it is a valid semver tag
1023-
_, err := util.TagStringToSemver(releaseNotesOpts.tag)
1023+
_, err := helpers.TagStringToSemver(releaseNotesOpts.tag)
10241024
if err != nil {
10251025
return fmt.Errorf("reading tag: %s: %w", releaseNotesOpts.tag, err)
10261026
}
@@ -1116,7 +1116,7 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error {
11161116
}
11171117

11181118
// Check the workDir before going further
1119-
if !util.Exists(workDir) {
1119+
if !helpers.Exists(workDir) {
11201120
return errors.New("map directory does not exist")
11211121
}
11221122

@@ -1151,9 +1151,9 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error {
11511151
// Ask the user if they want to continue the last session o fix all notes
11521152
continueFromLastSession := true
11531153
if len(pullRequestChecklist) > 0 {
1154-
_, continueFromLastSession, err = util.Ask("Would you like to continue from the last session? (Y/n)", "y:Y:yes|n:N:no|y", 10)
1154+
_, continueFromLastSession, err = helpers.Ask("Would you like to continue from the last session? (Y/n)", "y:Y:yes|n:N:no|y", 10)
11551155
} else {
1156-
_, _, err = util.Ask("Press enter to start editing", "y:Y:yes|n:N:no|y", 10)
1156+
_, _, err = helpers.Ask("Press enter to start editing", "y:Y:yes|n:N:no|y", 10)
11571157
}
11581158

11591159
if err != nil {
@@ -1232,13 +1232,13 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error {
12321232

12331233
// Wrap the note for better readability on the terminal
12341234
fmt.Println(pointIfChanged("Text", note.Text, originalNote.Text))
1235-
text := util.WrapText(note.Text, 80)
1235+
text := helpers.WrapText(note.Text, 80)
12361236
fmt.Println(spacer + strings.ReplaceAll(text, nl, nl+spacer))
12371237

1238-
_, choice, err := util.Ask(fmt.Sprintf("\n- Fix note for PR #%d? (y/N)", note.PrNumber), "y:Y:yes|n:N:no|n", 10)
1238+
_, choice, err := helpers.Ask(fmt.Sprintf("\n- Fix note for PR #%d? (y/N)", note.PrNumber), "y:Y:yes|n:N:no|n", 10)
12391239
if err != nil {
12401240
// If the user cancelled with ctr+c exit and continue the PR flow
1241-
var userInputErr util.UserInputError
1241+
var userInputErr helpers.UserInputError
12421242
if errors.As(err, &userInputErr) && userInputErr.IsCtrlC() {
12431243
logrus.Info("Input cancelled, exiting edit flow")
12441244

@@ -1260,7 +1260,7 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error {
12601260
if retry {
12611261
logrus.Error(err)
12621262

1263-
_, retryEditingChoice, err := util.Ask(
1263+
_, retryEditingChoice, err := helpers.Ask(
12641264
fmt.Sprintf("\n- An error occurred while editing PR #%d. Try again?", note.PrNumber),
12651265
"y:yes|n:no", 10,
12661266
)
@@ -1521,7 +1521,7 @@ func createNotesWorkDir(releaseDir string) error {
15211521
filepath.Join(releaseDir, releaseNotesWorkDir, mapsSessionDirectory), // Editing session files
15221522
filepath.Join(releaseDir, releaseNotesWorkDir, mapsThemesDirectory), // Major themes directory
15231523
} {
1524-
if !util.Exists(dirPath) {
1524+
if !helpers.Exists(dirPath) {
15251525
if err := os.Mkdir(dirPath, os.FileMode(0o755)); err != nil {
15261526
return fmt.Errorf("creating working directory: %w", err)
15271527
}
@@ -1537,11 +1537,11 @@ func confirmWithUser(opts *releaseNotesOptions, question string) bool {
15371537
return true
15381538
}
15391539

1540-
_, success, err := util.Ask(question+" (Y/n)", "y:Y:yes|n:N:no|y", 10)
1540+
_, success, err := helpers.Ask(question+" (Y/n)", "y:Y:yes|n:N:no|y", 10)
15411541
if err != nil {
15421542
logrus.Error(err)
15431543

1544-
var userInputErr util.UserInputError
1544+
var userInputErr helpers.UserInputError
15451545
if errors.As(err, &userInputErr) && userInputErr.IsCtrlC() {
15461546
os.Exit(1)
15471547
}

cmd/schedule-builder/cmd/markdown.go

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ import (
2525
"text/template" // NOLINT // Mark text/template as not to be checked for producing yaml.
2626
"time"
2727

28-
"github.com/olekukonko/tablewriter"
2928
"github.com/sirupsen/logrus"
3029

31-
"sigs.k8s.io/release-utils/util"
30+
"sigs.k8s.io/release-utils/helpers"
3231
"sigs.k8s.io/yaml"
3332
)
3433

@@ -42,9 +41,7 @@ func parsePatchSchedule(patchSchedule PatchSchedule) string {
4241
if len(patchSchedule.UpcomingReleases) > 0 {
4342
output = append(output, "### Upcoming Monthly Releases\n")
4443
tableString := &strings.Builder{}
45-
table := tablewriter.NewWriter(tableString)
46-
table.SetAutoWrapText(false)
47-
table.SetHeader([]string{"Monthly Patch Release", "Cherry Pick Deadline", "Target Date"})
44+
table := helpers.NewTableWriterWithDefaultsAndHeader(tableString, []string{"Monthly Patch Release", "Cherry Pick Deadline", "Target Date"})
4845

4946
for _, upcoming := range patchSchedule.UpcomingReleases {
5047
targetDate, err := time.Parse(refDate, upcoming.TargetDate)
@@ -54,16 +51,14 @@ func parsePatchSchedule(patchSchedule PatchSchedule) string {
5451
continue
5552
}
5653

57-
table.Append([]string{
54+
_ = table.Append([]string{
5855
targetDate.Format(refDateMonthly),
5956
strings.TrimSpace(upcoming.CherryPickDeadline),
6057
strings.TrimSpace(upcoming.TargetDate),
6158
})
6259
}
6360

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

6863
output = append(output, tableString.String())
6964
}
@@ -79,22 +74,18 @@ func parsePatchSchedule(patchSchedule PatchSchedule) string {
7974
)
8075

8176
tableString := &strings.Builder{}
82-
table := tablewriter.NewWriter(tableString)
83-
table.SetAutoWrapText(false)
84-
table.SetHeader([]string{"Patch Release", "Cherry Pick Deadline", "Target Date", "Note"})
77+
table := helpers.NewTableWriterWithDefaultsAndHeader(tableString, []string{"Patch Release", "Cherry Pick Deadline", "Target Date", "Note"})
8578

8679
// Check if the next patch release is in the Previous Patch list, if yes dont read in the output
8780
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), ""})
81+
_ = table.Append([]string{strings.TrimSpace(releaseSchedule.Next.Release), strings.TrimSpace(releaseSchedule.Next.CherryPickDeadline), strings.TrimSpace(releaseSchedule.Next.TargetDate), ""})
8982
}
9083

9184
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)})
85+
_ = table.Append([]string{strings.TrimSpace(previous.Release), strings.TrimSpace(previous.CherryPickDeadline), strings.TrimSpace(previous.TargetDate), strings.TrimSpace(previous.Note)})
9386
}
9487

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

9990
output = append(output, tableString.String())
10091
}
@@ -131,17 +122,13 @@ func parseReleaseSchedule(releaseSchedule ReleaseSchedule) string {
131122

132123
for _, releaseSchedule := range releaseSchedule.Releases {
133124
tableString := &strings.Builder{}
134-
table := tablewriter.NewWriter(tableString)
135-
table.SetAutoWrapText(false)
136-
table.SetHeader([]string{"**What**", "**Who**", "**When**", "**WEEK**", "**CI Signal**"})
125+
table := helpers.NewTableWriterWithDefaultsAndHeader(tableString, []string{"**What**", "**Who**", "**When**", "**WEEK**", "**CI Signal**"})
137126

138127
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), ""})
128+
_ = table.Append([]string{strings.TrimSpace(timeline.What), strings.TrimSpace(timeline.Who), strings.TrimSpace(timeline.When), strings.TrimSpace(timeline.Week), strings.TrimSpace(timeline.CISignal), ""})
140129
}
141130

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

146133
relSched.TimelineOutput = tableString.String()
147134
}
@@ -248,7 +235,7 @@ func updatePatchSchedule(refTime time.Time, schedule PatchSchedule, eolBranches
248235
sched.PreviousPatches = append([]*PatchRelease{sched.Next}, sched.PreviousPatches...)
249236

250237
// Create a new next release
251-
nextReleaseVersion, err := util.TagStringToSemver(sched.Next.Release)
238+
nextReleaseVersion, err := helpers.TagStringToSemver(sched.Next.Release)
252239
if err != nil {
253240
return fmt.Errorf("parse semver version: %w", err)
254241
}

0 commit comments

Comments
 (0)