Skip to content

Commit

Permalink
feat: warn if loaded changelog is whitespace-only
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Feb 6, 2022
1 parent c42a2fd commit bb62b23
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
20 changes: 20 additions & 0 deletions internal/pipe/changelog/CHANGELOG.md
@@ -0,0 +1,20 @@
## Changelog
* 6880f3b8 fixed tag and shit
* b99db9dd more tests
* 5d087173 fixes
* e0300e5d wtfff
* e4449c6c fix
* 703d3020 fix tag
* a409577e config
* 8b90e175 tests
* b060e9ff moving
* a6932a08 glide and travis
* 580ee4ca release to github
* eea28786 readme, license and shit
* d5d9a4cc zip
* 44b15f78 main script
* fe42f1b4 tests
* 2aa160ff git tags and diff
* d8bb50f7 fixes
* efff5d5e wip
* 8b63e655 config wip
16 changes: 12 additions & 4 deletions internal/pipe/changelog/changelog.go
Expand Up @@ -316,17 +316,25 @@ func newSCMChangeloger(ctx *context.Context) (changeloger, error) {

func loadContent(ctx *context.Context, fileName, tmplName string) (string, error) {
if tmplName != "" {
log.Debugf("loading template %s", tmplName)
log.Debugf("loading template %q", tmplName)
content, err := loadFromFile(tmplName)
if err != nil {
return "", err
}
return tmpl.New(ctx).Apply(content)
content, err = tmpl.New(ctx).Apply(content)
if strings.TrimSpace(content) == "" && err == nil {
log.Warnf("loaded %q, but it evaluates to an empty string", tmplName)
}
return content, err
}

if fileName != "" {
log.Debugf("loading file %s", fileName)
return loadFromFile(fileName)
log.Debugf("loading file %q", fileName)
content, err := loadFromFile(fileName)
if strings.TrimSpace(content) == "" && err == nil {
log.Warnf("loaded %q, but it is empty", fileName)
}
return content, err
}

return "", nil
Expand Down
15 changes: 15 additions & 0 deletions internal/pipe/changelog/changelog_test.go
Expand Up @@ -25,6 +25,13 @@ func TestChangelogProvidedViaFlag(t *testing.T) {
require.Equal(t, "c0ff33 coffeee\n", ctx.ReleaseNotes)
}

func TestChangelogProvidedViaFlagIsAnWhitespaceOnlyFile(t *testing.T) {
ctx := context.New(config.Project{})
ctx.ReleaseNotesFile = "testdata/changes-empty.md"
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, "\n", ctx.ReleaseNotes)
}

func TestTemplatedChangelogProvidedViaFlag(t *testing.T) {
ctx := context.New(config.Project{})
ctx.ReleaseNotesFile = "testdata/changes.md"
Expand All @@ -34,6 +41,14 @@ func TestTemplatedChangelogProvidedViaFlag(t *testing.T) {
require.Equal(t, "c0ff33 coffeee v0.0.1\n", ctx.ReleaseNotes)
}

func TestTemplatedChangelogProvidedViaFlagResultIsEmpty(t *testing.T) {
ctx := context.New(config.Project{})
ctx.ReleaseNotesTmpl = "testdata/changes-templated-empty.md"
ctx.Git.CurrentTag = "v0.0.1"
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, "\n\n", ctx.ReleaseNotes)
}

func TestChangelogProvidedViaFlagDoesntExist(t *testing.T) {
ctx := context.New(config.Project{})
ctx.ReleaseNotesFile = "testdata/changes.nope"
Expand Down
1 change: 1 addition & 0 deletions internal/pipe/changelog/testdata/changes-empty.md
@@ -0,0 +1 @@

@@ -0,0 +1 @@
{{ print "\n" }}

0 comments on commit bb62b23

Please sign in to comment.