Skip to content

Commit bcf33c3

Browse files
authored
Merge pull request #1190 from saschagrunert/changelog-verbosity
Increase verbosity of krel changelog
2 parents f50d11a + d0be361 commit bcf33c3

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

cmd/krel/cmd/changelog.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func init() {
110110
changelogCmd.PersistentFlags().StringVar(&changelogOpts.replayDir, "replay", "", "Replay a previously recorded API from a directory")
111111

112112
if err := changelogCmd.MarkPersistentFlagRequired("tag"); err != nil {
113-
logrus.Fatal(err)
113+
logrus.Fatalf("unable to %v", err)
114114
}
115115

116116
rootCmd.AddCommand(changelogCmd)
@@ -119,7 +119,7 @@ func init() {
119119
func runChangelog(opts *changelogOptions, rootOpts *rootOptions) error {
120120
tag, err := util.TagStringToSemver(opts.tag)
121121
if err != nil {
122-
return errors.Wrapf(err, "unable to parse tag %s", opts.tag)
122+
return errors.Wrapf(err, "parse tag %s", opts.tag)
123123
}
124124

125125
// Automatically set the branch to a release branch if not provided
@@ -133,7 +133,7 @@ func runChangelog(opts *changelogOptions, rootOpts *rootOptions) error {
133133
repo, err := git.OpenRepo(rootOpts.repoPath)
134134
if err != nil {
135135
return errors.Wrapf(err,
136-
"unable to open expected k/k repository %q", rootOpts.repoPath,
136+
"open expected k/k repository %q", rootOpts.repoPath,
137137
)
138138
}
139139
if currentBranch, err := repo.CurrentBranch(); err == nil {
@@ -143,7 +143,7 @@ func runChangelog(opts *changelogOptions, rootOpts *rootOptions) error {
143143
remoteBranch := git.Remotify(branch)
144144
head, err := repo.RevParse(remoteBranch)
145145
if err != nil {
146-
return errors.Wrapf(err, "unable to get latest branch commit")
146+
return errors.Wrapf(err, "get latest branch commit")
147147
}
148148
logrus.Infof("Found latest %s commit %s", remoteBranch, head)
149149

@@ -158,7 +158,7 @@ func runChangelog(opts *changelogOptions, rootOpts *rootOptions) error {
158158
if err := document.CreateDownloadsTable(
159159
downloadsTable, opts.bucket, opts.tars, previousTag, opts.tag,
160160
); err != nil {
161-
return errors.Wrapf(err, "unable to create downloads table")
161+
return errors.Wrapf(err, "create downloads table")
162162
}
163163

164164
// New final minor versions should have remote release notes
@@ -168,7 +168,7 @@ func runChangelog(opts *changelogOptions, rootOpts *rootOptions) error {
168168
// New minor alphas, betas and rc get generated notes
169169
latestTags, tErr := github.New().LatestGitHubTagsPerBranch()
170170
if tErr != nil {
171-
return errors.Wrap(tErr, "unable to get latest GitHub tags")
171+
return errors.Wrap(tErr, "get latest GitHub tags")
172172
}
173173

174174
if startTag, ok := latestTags[branch]; ok {
@@ -205,22 +205,26 @@ func runChangelog(opts *changelogOptions, rootOpts *rootOptions) error {
205205
}
206206
defer func() {
207207
if err := repo.Checkout(currentBranch); err != nil {
208-
logrus.Errorf("unable to restore branch %s: %v", currentBranch, err)
208+
logrus.Errorf("restore branch %s: %v", currentBranch, err)
209209
}
210210
}()
211211

212+
logrus.Infof("Checking out %s branch", git.Master)
212213
if err := repo.Checkout(git.Master); err != nil {
213214
return errors.Wrap(err, "checking out master branch")
214215
}
215216

217+
logrus.Info("Writing markdown")
216218
if err := writeMarkdown(repo, toc, markdown, tag); err != nil {
217219
return err
218220
}
219221

222+
logrus.Info("Writing HTML")
220223
if err := writeHTML(opts, tag, markdown); err != nil {
221224
return err
222225
}
223226

227+
logrus.Info("Committing changes")
224228
return commitChanges(repo, branch, tag)
225229
}
226230

@@ -302,7 +306,7 @@ func writeMarkdown(repo *git.Repo, toc, markdown string, tag semver.Version) err
302306
tocEndIndex := bytes.Index(content, []byte(tocEnd))
303307
if tocEndIndex < 0 {
304308
return errors.Errorf(
305-
"unable to find table of contents end marker `%s` in %q",
309+
"find table of contents end marker `%s` in %q",
306310
tocEnd, changelogPath,
307311
)
308312
}
@@ -366,7 +370,7 @@ func writeHTML(opts *changelogOptions, tag semver.Version, markdown string) erro
366370
md := goldmark.New(goldmark.WithExtensions(extension.GFM))
367371
content := &bytes.Buffer{}
368372
if err := md.Convert([]byte(markdown), content); err != nil {
369-
return errors.Wrap(err, "unable to render HTML from markdown")
373+
return errors.Wrap(err, "render HTML from markdown")
370374
}
371375

372376
t, err := template.New("html").Parse(htmlTemplate)
@@ -385,7 +389,7 @@ func writeHTML(opts *changelogOptions, tag semver.Version, markdown string) erro
385389
if err != nil {
386390
return err
387391
}
388-
logrus.Infof("Writing single HTML to %s", absOutputPath)
392+
logrus.Infof("Writing HTML file to %s", absOutputPath)
389393
return ioutil.WriteFile(absOutputPath, output.Bytes(), os.FileMode(0644))
390394
}
391395

@@ -431,21 +435,24 @@ func commitChanges(repo *git.Repo, branch string, tag semver.Version) error {
431435
}
432436

433437
if branch != git.Master {
438+
logrus.Infof("Checking out %s branch", branch)
434439
// Release branch modifications
435440
if err := repo.Checkout(branch); err != nil {
436441
return errors.Wrapf(err, "checking out release branch %s", branch)
437442
}
438443

439444
// Remove all other changelog files if we’re on the first RC
440445
if len(tag.Pre) > 1 && tag.Pre[0].String() == "rc" && tag.Pre[1].String() == "1" {
441-
if err := repo.Rm(true, repoChangelogDir+"/CHANGELOG-*.md"); err != nil {
442-
return errors.Wrap(err, "unable to remove CHANGELOG-*.md files")
446+
pattern := filepath.Join(repoChangelogDir, "CHANGELOG-*.md")
447+
logrus.Infof("Removing unnecessary %s files", pattern)
448+
if err := repo.Rm(true, pattern); err != nil {
449+
return errors.Wrapf(err, "removing %s files", pattern)
443450
}
444451
}
445452

446453
logrus.Info("Checking out changelog from master branch")
447454
if err := repo.Checkout(git.Master, releaseChangelog); err != nil {
448-
return errors.Wrap(err, "unable to check out master branch changelog")
455+
return errors.Wrap(err, "check out master branch changelog")
449456
}
450457

451458
logrus.Info("Committing changes to release branch in repository")
@@ -463,7 +470,7 @@ func adaptChangelogReadmeFile(repo *git.Repo, tag semver.Version) error {
463470
targetFile := filepath.Join(repo.Dir(), repoChangelogDir, "README.md")
464471
readme, err := ioutil.ReadFile(targetFile)
465472
if err != nil {
466-
return errors.Wrap(err, "unable to read changelog README.md")
473+
return errors.Wrap(err, "read changelog README.md")
467474
}
468475

469476
cf := filepath.Base(markdownChangelogFilename(tag))
@@ -487,7 +494,7 @@ func adaptChangelogReadmeFile(repo *git.Repo, tag semver.Version) error {
487494
const nl = "\n"
488495
if err := ioutil.WriteFile(
489496
targetFile, []byte(strings.Join(res, nl)+nl), os.FileMode(0644)); err != nil {
490-
return errors.Wrap(err, "unable to write changelog README.md")
497+
return errors.Wrap(err, "write changelog README.md")
491498
}
492499
return nil
493500
}

0 commit comments

Comments
 (0)