From fc89ecbedb463ce2c70ae7334dbbd2c6fc0ed89e Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Tue, 12 Sep 2023 15:56:52 -0400 Subject: [PATCH 1/3] cleanup markdown format Signed-off-by: Alex Goodman --- .../__snapshots__/presenter_test.snap | 34 +++++ .../release/format/markdown/presenter.go | 33 +++-- .../release/format/markdown/presenter_test.go | 122 ++++++++++++++---- .../TestMarkdownPresenter_Present.golden | 20 --- .../release/releasers/github/summarizer.go | 10 +- .../releasers/github/summarizer_test.go | 34 ++--- go.mod | 20 ++- go.sum | 36 +++++- 8 files changed, 223 insertions(+), 86 deletions(-) create mode 100755 chronicle/release/format/markdown/__snapshots__/presenter_test.snap delete mode 100644 chronicle/release/format/markdown/test-fixtures/snapshot/TestMarkdownPresenter_Present.golden diff --git a/chronicle/release/format/markdown/__snapshots__/presenter_test.snap b/chronicle/release/format/markdown/__snapshots__/presenter_test.snap new file mode 100755 index 0000000..998f239 --- /dev/null +++ b/chronicle/release/format/markdown/__snapshots__/presenter_test.snap @@ -0,0 +1,34 @@ + +[TestMarkdownPresenter_Present - 1] +# Changelog + +### Bug Fixes + +- Redirect cursor hide/show to stderr. [#456](https://github.com/anchore/syft/pull/456) + +### Added Features + +- added feature. [#457](https://github.com/anchore/syft/pull/457) [@wagoodman](https://github.com/wagoodman) +- another added feature. + +### Breaking Changes + +- breaking change. [#458](https://github.com/anchore/syft/pull/458) [#450](https://github.com/anchore/syft/issues/450) [@wagoodman](https://github.com/wagoodman) + +**[(Full Changelog)](https://github.com/anchore/syft/compare/v0.19.0...v0.19.1)** + +--- + +[TestMarkdownPresenter_Present_NoTitle - 1] +### Bug Fixes + +- Redirect cursor hide/show to stderr. [#456](https://github.com/anchore/syft/pull/456) + +**[(Full Changelog)](https://github.com/anchore/syft/compare/v0.19.0...v0.19.1)** + +--- + +[TestMarkdownPresenter_Present_NoChanges - 1] +**[(Full Changelog)](https://github.com/anchore/syft/compare/v0.19.0...v0.19.1)** + +--- diff --git a/chronicle/release/format/markdown/presenter.go b/chronicle/release/format/markdown/presenter.go index 7981d88..9f0d550 100644 --- a/chronicle/release/format/markdown/presenter.go +++ b/chronicle/release/format/markdown/presenter.go @@ -3,6 +3,7 @@ package markdown import ( "fmt" "io" + "strings" "text/template" "github.com/wagoodman/go-presenter" @@ -12,13 +13,11 @@ import ( ) const ( - markdownHeaderTemplate = `# {{.Title}} + markdownHeaderTemplate = `{{if .Title }}# {{.Title}} -## [{{.Version}}]({{.VCSReferenceURL}}) ({{ .Date.Format "2006-01-02" }}) +{{ end }}{{if .Changes }}{{ formatChangeSections .Changes }} -[Full Changelog]({{.VCSChangesURL}}) - -{{ formatChangeSections .Changes }} +{{ end }}**[(Full Changelog)]({{.VCSChangesURL}})** ` ) @@ -71,7 +70,7 @@ func (m Presenter) formatChangeSections(changes change.Changes) string { result += formatChangeSection(section.Title, summaries) + "\n" } } - return result + return strings.TrimRight(result, "\n") } func formatChangeSection(title string, summaries []change.Change) string { @@ -83,14 +82,30 @@ func formatChangeSection(title string, summaries []change.Change) string { } func formatSummary(summary change.Change) string { - result := fmt.Sprintf("- %s", summary.Text) + result := fmt.Sprintf("- %s", strings.TrimSpace(summary.Text)) + if !endsWithPunctuation(result) { + switch result[len(result)-1:] { + case "!", ".", "?": + // pass + default: + result += "." + } + } + for _, ref := range summary.References { if ref.URL == "" { - result += fmt.Sprintf(" [%s]", ref.Text) + result += fmt.Sprintf(" %s", ref.Text) } else { - result += fmt.Sprintf(" [[%s](%s)]", ref.Text, ref.URL) + result += fmt.Sprintf(" [%s](%s)", ref.Text, ref.URL) } } return result + "\n" } + +func endsWithPunctuation(s string) bool { + if len(s) == 0 { + return false + } + return strings.Contains("!.?", s[len(s)-1:]) //nolint:gocritic +} diff --git a/chronicle/release/format/markdown/presenter_test.go b/chronicle/release/format/markdown/presenter_test.go index d4c5ad6..9ee5f77 100644 --- a/chronicle/release/format/markdown/presenter_test.go +++ b/chronicle/release/format/markdown/presenter_test.go @@ -2,26 +2,21 @@ package markdown import ( "bytes" - "flag" "testing" "time" - "github.com/sergi/go-diff/diffmatchpatch" + "github.com/gkampitakis/go-snaps/snaps" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/wagoodman/go-presenter" "github.com/anchore/chronicle/chronicle/release" "github.com/anchore/chronicle/chronicle/release/change" - "github.com/anchore/go-testutils" ) -var updateMarkdownPresenterGoldenFiles = flag.Bool("update-markdown", false, "update the *.golden files for markdown presenters") - func TestMarkdownPresenter_Present(t *testing.T) { must := func(m *Presenter, err error) *Presenter { - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) return m } assertPresenterAgainstGoldenSnapshot( @@ -60,7 +55,7 @@ func TestMarkdownPresenter_Present(t *testing.T) { Text: "Redirect cursor hide/show to stderr", References: []change.Reference{ { - Text: "456", + Text: "#456", URL: "https://github.com/anchore/syft/pull/456", }, }, @@ -68,6 +63,16 @@ func TestMarkdownPresenter_Present(t *testing.T) { { ChangeTypes: []change.Type{change.NewType("added", change.SemVerMinor)}, Text: "added feature", + References: []change.Reference{ + { + Text: "#457", + URL: "https://github.com/anchore/syft/pull/457", + }, + { + Text: "@wagoodman", + URL: "https://github.com/wagoodman", + }, + }, }, { ChangeTypes: []change.Type{change.NewType("added", change.SemVerMinor)}, @@ -76,19 +81,100 @@ func TestMarkdownPresenter_Present(t *testing.T) { { ChangeTypes: []change.Type{change.NewType("breaking", change.SemVerMajor)}, Text: "breaking change", + References: []change.Reference{ + { + Text: "#458", + URL: "https://github.com/anchore/syft/pull/458", + }, + { + Text: "#450", + URL: "https://github.com/anchore/syft/issues/450", + }, + { + Text: "@wagoodman", + URL: "https://github.com/wagoodman", + }, + }, }, }, Notice: "notice!", }, }), ), - *updateMarkdownPresenterGoldenFiles, + ) +} + +func TestMarkdownPresenter_Present_NoTitle(t *testing.T) { + must := func(m *Presenter, err error) *Presenter { + require.NoError(t, err) + return m + } + assertPresenterAgainstGoldenSnapshot( + t, + must( + NewMarkdownPresenter(Config{ + Title: "", + Description: release.Description{ + SupportedChanges: []change.TypeTitle{ + { + ChangeType: change.NewType("bug", change.SemVerPatch), + Title: "Bug Fixes", + }, + }, + Release: release.Release{ + Version: "v0.19.1", + Date: time.Date(2021, time.September, 16, 19, 34, 0, 0, time.UTC), + }, + VCSReferenceURL: "https://github.com/anchore/syft/tree/v0.19.1", + VCSChangesURL: "https://github.com/anchore/syft/compare/v0.19.0...v0.19.1", + Changes: []change.Change{ + { + ChangeTypes: []change.Type{change.NewType("bug", change.SemVerPatch)}, + Text: "Redirect cursor hide/show to stderr", + References: []change.Reference{ + { + Text: "#456", + URL: "https://github.com/anchore/syft/pull/456", + }, + }, + }, + }, + Notice: "notice!", + }, + }), + ), + ) +} + +func TestMarkdownPresenter_Present_NoChanges(t *testing.T) { + must := func(m *Presenter, err error) *Presenter { + require.NoError(t, err) + return m + } + assertPresenterAgainstGoldenSnapshot( + t, + must( + NewMarkdownPresenter(Config{ + Title: "", + Description: release.Description{ + SupportedChanges: []change.TypeTitle{}, + Release: release.Release{ + Version: "v0.19.1", + Date: time.Date(2021, time.September, 16, 19, 34, 0, 0, time.UTC), + }, + VCSReferenceURL: "https://github.com/anchore/syft/tree/v0.19.1", + VCSChangesURL: "https://github.com/anchore/syft/compare/v0.19.0...v0.19.1", + Changes: []change.Change{}, + Notice: "notice!", + }, + }), + ), ) } type redactor func(s []byte) []byte -func assertPresenterAgainstGoldenSnapshot(t *testing.T, pres presenter.Presenter, updateSnapshot bool, redactors ...redactor) { +func assertPresenterAgainstGoldenSnapshot(t *testing.T, pres presenter.Presenter, redactors ...redactor) { t.Helper() var buffer bytes.Buffer @@ -96,22 +182,10 @@ func assertPresenterAgainstGoldenSnapshot(t *testing.T, pres presenter.Presenter assert.NoError(t, err) actual := buffer.Bytes() - // replace the expected snapshot contents with the current presenter contents - if updateSnapshot { - testutils.UpdateGoldenFileContents(t, actual) - } - - var expected = testutils.GetGoldenFileContents(t) - // remove dynamic values, which should be tested independently for _, r := range redactors { actual = r(actual) - expected = r(expected) } - if !bytes.Equal(expected, actual) { - dmp := diffmatchpatch.New() - diffs := dmp.DiffMain(string(expected), string(actual), true) - t.Errorf("mismatched output:\n%s", dmp.DiffPrettyText(diffs)) - } + snaps.MatchSnapshot(t, string(actual)) } diff --git a/chronicle/release/format/markdown/test-fixtures/snapshot/TestMarkdownPresenter_Present.golden b/chronicle/release/format/markdown/test-fixtures/snapshot/TestMarkdownPresenter_Present.golden deleted file mode 100644 index 57af4d1..0000000 --- a/chronicle/release/format/markdown/test-fixtures/snapshot/TestMarkdownPresenter_Present.golden +++ /dev/null @@ -1,20 +0,0 @@ -# Changelog - -## [v0.19.1](https://github.com/anchore/syft/tree/v0.19.1) (2021-09-16) - -[Full Changelog](https://github.com/anchore/syft/compare/v0.19.0...v0.19.1) - -### Bug Fixes - -- Redirect cursor hide/show to stderr [[456](https://github.com/anchore/syft/pull/456)] - -### Added Features - -- added feature -- another added feature - -### Breaking Changes - -- breaking change - - diff --git a/chronicle/release/releasers/github/summarizer.go b/chronicle/release/releasers/github/summarizer.go index c3f2406..663c6cc 100644 --- a/chronicle/release/releasers/github/summarizer.go +++ b/chronicle/release/releasers/github/summarizer.go @@ -282,11 +282,11 @@ func createChangesFromPRs(config Config, prs []ghPullRequest) []change.Change { Timestamp: pr.MergedAt, References: []change.Reference{ { - Text: fmt.Sprintf("PR #%d", pr.Number), + Text: fmt.Sprintf("#%d", pr.Number), URL: pr.URL, }, { - Text: pr.Author, + Text: fmt.Sprintf("@%s", pr.Author), URL: fmt.Sprintf("https://%s/%s", config.Host, pr.Author), }, }, @@ -380,7 +380,7 @@ func createChangesFromIssues(config Config, allMergedPRs []ghPullRequest, issues references := []change.Reference{ { - Text: fmt.Sprintf("Issue #%d", issue.Number), + Text: fmt.Sprintf("#%d", issue.Number), URL: issue.URL, }, } @@ -389,13 +389,13 @@ func createChangesFromIssues(config Config, allMergedPRs []ghPullRequest, issues for _, pr := range getLinkedPRs(allMergedPRs, issue) { if config.IncludeIssuePRs { references = append(references, change.Reference{ - Text: fmt.Sprintf("PR #%d", pr.Number), + Text: fmt.Sprintf("#%d", pr.Number), URL: pr.URL, }) } if config.IncludeIssuePRAuthors && pr.Author != "" { references = append(references, change.Reference{ - Text: pr.Author, + Text: fmt.Sprintf("@%s", pr.Author), URL: fmt.Sprintf("https://%s/%s", config.Host, pr.Author), }) } diff --git a/chronicle/release/releasers/github/summarizer_test.go b/chronicle/release/releasers/github/summarizer_test.go index c13292d..340b458 100644 --- a/chronicle/release/releasers/github/summarizer_test.go +++ b/chronicle/release/releasers/github/summarizer_test.go @@ -870,23 +870,23 @@ func Test_createChangesFromIssues(t *testing.T) { Timestamp: timeStart, References: []change.Reference{ { - Text: "Issue #1", + Text: "#1", URL: "issue-1-url", }, { - Text: "PR #1", + Text: "#1", URL: "pr-1-url", }, { - Text: "some-author-1", + Text: "@some-author-1", URL: "https://some-host/some-author-1", }, { - Text: "PR #2", + Text: "#2", URL: "pr-2-url", }, { - Text: "some-author-2", + Text: "@some-author-2", URL: "https://some-host/some-author-2", }, }, @@ -899,15 +899,15 @@ func Test_createChangesFromIssues(t *testing.T) { Timestamp: timeStart, References: []change.Reference{ { - Text: "Issue #2", + Text: "#2", URL: "issue-2-url", }, { - Text: "PR #2", + Text: "#2", URL: "pr-2-url", }, { - Text: "some-author-2", + Text: "@some-author-2", URL: "https://some-host/some-author-2", }, }, @@ -920,7 +920,7 @@ func Test_createChangesFromIssues(t *testing.T) { Timestamp: timeStart, References: []change.Reference{ { - Text: "Issue #3", + Text: "#3", URL: "issue-3-url", }, }, @@ -1010,11 +1010,11 @@ func Test_changesFromUnlabeledPRs(t *testing.T) { Timestamp: timeStart, References: []change.Reference{ { - Text: "PR #6", + Text: "#6", URL: "some-url", }, { - Text: "some-author", + Text: "@some-author", URL: "https://some-host/some-author", }, }, @@ -1027,11 +1027,11 @@ func Test_changesFromUnlabeledPRs(t *testing.T) { Timestamp: timeStart, References: []change.Reference{ { - Text: "PR #7", + Text: "#7", URL: "some-url-2", }, { - Text: "some-author-2", + Text: "@some-author-2", URL: "https://some-host/some-author-2", }, }, @@ -1140,15 +1140,15 @@ func Test_changesFromUnlabeledIssues(t *testing.T) { Timestamp: timeStart, References: []change.Reference{ { - Text: "Issue #6", + Text: "#6", URL: "some-url", }, { - Text: "PR #1", + Text: "#1", URL: "pr-1-url", }, { - Text: "pr-1-author", + Text: "@pr-1-author", URL: "https://some-host/pr-1-author", }, }, @@ -1161,7 +1161,7 @@ func Test_changesFromUnlabeledIssues(t *testing.T) { Timestamp: timeStart, References: []change.Reference{ { - Text: "Issue #7", + Text: "#7", URL: "some-url-2", }, }, diff --git a/go.mod b/go.mod index 32e92b5..f78d691 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,17 @@ module github.com/anchore/chronicle -go 1.18 +go 1.21.0 + +toolchain go1.21.1 require ( github.com/anchore/clio v0.0.0-20230802135737-4778c80552e5 github.com/anchore/fangs v0.0.0-20230725134830-329a9a4d20e7 github.com/anchore/go-logger v0.0.0-20230725134548-c21dafa1ec5a - github.com/anchore/go-testutils v0.0.0-20200925183923-d5f45b0d3c04 github.com/coreos/go-semver v0.3.1 + github.com/gkampitakis/go-snaps v0.4.10 github.com/go-git/go-git/v5 v5.8.1 github.com/scylladb/go-set v1.0.2 - github.com/sergi/go-diff v1.3.1 github.com/shurcooL/githubv4 v0.0.0-20201206200315-234843c633fa github.com/spf13/cobra v1.7.0 github.com/stretchr/testify v1.8.4 @@ -30,6 +31,8 @@ require ( github.com/emirpasic/gods v1.18.1 // indirect github.com/felixge/fgprof v0.9.3 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/gkampitakis/ciinfo v0.2.5 // indirect + github.com/gkampitakis/go-diff v1.3.2 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.4.1 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect @@ -43,7 +46,8 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect - github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381 // indirect + github.com/kr/pretty v0.3.1 // indirect + github.com/kr/text v0.2.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-isatty v0.0.14 // indirect @@ -55,6 +59,8 @@ require ( github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pkg/profile v1.7.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/rogpeppe/go-internal v1.11.0 // indirect + github.com/sergi/go-diff v1.3.1 // indirect github.com/shurcooL/graphql v0.0.0-20200928012149-18c5c3165e3a // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/skeema/knownhosts v1.2.0 // indirect @@ -64,10 +70,14 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.16.0 // indirect github.com/subosito/gotenv v1.4.2 // indirect + github.com/tidwall/gjson v1.16.0 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.1 // indirect + github.com/tidwall/sjson v1.2.5 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect golang.org/x/crypto v0.11.0 // indirect - golang.org/x/mod v0.8.0 // indirect + golang.org/x/mod v0.9.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/sys v0.10.0 // indirect golang.org/x/term v0.10.0 // indirect diff --git a/go.sum b/go.sum index 5852cc3..26004f9 100644 --- a/go.sum +++ b/go.sum @@ -55,10 +55,10 @@ github.com/anchore/fangs v0.0.0-20230725134830-329a9a4d20e7 h1:DiG9qj+JNfjodKQN5 github.com/anchore/fangs v0.0.0-20230725134830-329a9a4d20e7/go.mod h1:82EGoxZTfBXSW0/zollEP+Qs3wkiKmip5yBT5j+eZpY= github.com/anchore/go-logger v0.0.0-20230725134548-c21dafa1ec5a h1:nJ2G8zWKASyVClGVgG7sfM5mwoZlZ2zYpIzN2OhjWkw= github.com/anchore/go-logger v0.0.0-20230725134548-c21dafa1ec5a/go.mod h1:ubLFmlsv8/DFUQrZwY5syT5/8Er3ugSr4rDFwHsE3hg= -github.com/anchore/go-testutils v0.0.0-20200925183923-d5f45b0d3c04 h1:VzprUTpc0vW0nnNKJfJieyH/TZ9UYAnTZs5/gHTdAe8= -github.com/anchore/go-testutils v0.0.0-20200925183923-d5f45b0d3c04/go.mod h1:6dK64g27Qi1qGQZ67gFmBFvEHScy0/C8qhQhNe5B5pQ= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= @@ -78,6 +78,7 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 h1:RIB4cRk+lBqKK3Oy0r2gRX4ui7tuhiZq2SuTtTCi0/0= +github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -91,14 +92,23 @@ github.com/fatih/set v0.2.1/go.mod h1:+RKtMCH+favT2+3YecHGxcc0b4KyVWA1QWWJUs4E0C github.com/felixge/fgprof v0.9.3 h1:VvyZxILNuCiUCSXtPtYmmtGvb65nqXh2QFWc0Wpf2/g= github.com/felixge/fgprof v0.9.3/go.mod h1:RdbpDgzqYVh/T9fPELJyV7EYJuHB55UTEULNun8eiPw= github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= +github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/gkampitakis/ciinfo v0.2.5 h1:K0mac90lGguc1conc46l0YEsB7/nioWCqSnJp/6z8Eo= +github.com/gkampitakis/ciinfo v0.2.5/go.mod h1:1NIwaOcFChN4fa/B0hEBdAb6npDlFL8Bwx4dfRLRqAo= +github.com/gkampitakis/go-diff v1.3.2 h1:Qyn0J9XJSDTgnsgHRdz9Zp24RaJeKMUHg2+PDZZdC4M= +github.com/gkampitakis/go-diff v1.3.2/go.mod h1:LLgOrpqleQe26cte8s36HTWcTmMEur6OPYerdAAS9tk= +github.com/gkampitakis/go-snaps v0.4.10 h1:rUcTH4k6+rzw6ylDALMifzw2c/f9cG3NZe/n+7Ygdr4= +github.com/gkampitakis/go-snaps v0.4.10/go.mod h1:N4TpqxI4CqKUfHzDFqrqZ5UP0I0ESz2g2NMslh7MiJw= github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= +github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4= github.com/go-git/go-billy/v5 v5.4.1/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20230305113008-0c11038e723f h1:Pz0DHeFij3XFhoBRGUDPzSJ+w2UcK5/0JvF8DRI58r8= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20230305113008-0c11038e723f/go.mod h1:8LHG1a3SRW71ettAD/jW13h8c6AqjVSeL11RAdgaqpo= github.com/go-git/go-git/v5 v5.8.1 h1:Zo79E4p7TRk0xoRgMq0RShiTHGKcKI4+DI6BfJc/Q+A= github.com/go-git/go-git/v5 v5.8.1/go.mod h1:FHFuoD6yGz5OSKEBK+aWN9Oah0q54Jxl0abmj6GnqAo= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= @@ -147,6 +157,7 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -195,12 +206,11 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381 h1:bqDmpDG49ZRnB5PcgP0RXtQvnMSgIF14M7CBd2shtXs= -github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A= @@ -222,6 +232,7 @@ github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZ github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/profile v1.7.0 h1:hnbDkaNWPCLMO9wGLdBFTIZvzDrDfBM2072E1S9gJkA= @@ -231,7 +242,9 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/scylladb/go-set v1.0.2 h1:SkvlMCKhP0wyyct6j+0IHJkBkSZL+TDzZ4E7f7BCcRE= github.com/scylladb/go-set v1.0.2/go.mod h1:DkpGd78rljTxKAnTDPFqXSGxvETQnJyuSOQwsHycqfs= @@ -273,6 +286,16 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= +github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.16.0 h1:SyXa+dsSPpUlcwEDuKuEBJEz5vzTvOea+9rjyYodQFg= +github.com/tidwall/gjson v1.16.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= +github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= +github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= github.com/wagoodman/go-partybus v0.0.0-20230516145632-8ccac152c651 h1:jIVmlAFIqV3d+DOxazTR9v+zgj8+VYuQBzPgBZvWBHA= github.com/wagoodman/go-partybus v0.0.0-20230516145632-8ccac152c651/go.mod h1:b26F2tHLqaoRQf8DywqzVaV1MQ9yvjb0OMcNl7Nxu20= github.com/wagoodman/go-presenter v0.0.0-20211015174752-f9c01afc824b h1:uWNQ0khA6RdFzODOMwKo9XXu7fuewnnkHykUtuKru8s= @@ -339,8 +362,9 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= +golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= From f922554505a24ad47dde4a47dfbec79544415af1 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Tue, 12 Sep 2023 16:55:37 -0400 Subject: [PATCH 2/3] allow for title templating and default to version value Signed-off-by: Alex Goodman --- .chronicle.yaml | 2 ++ .../__snapshots__/presenter_test.snap | 12 ++++--- .../release/format/markdown/presenter.go | 31 ++++++++++++++++--- .../release/format/markdown/presenter_test.go | 5 +-- cmd/chronicle/cli/commands/create_config.go | 2 +- 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/.chronicle.yaml b/.chronicle.yaml index 010b184..dc96de8 100644 --- a/.chronicle.yaml +++ b/.chronicle.yaml @@ -1,2 +1,4 @@ log: level: trace + +title: '' \ No newline at end of file diff --git a/chronicle/release/format/markdown/__snapshots__/presenter_test.snap b/chronicle/release/format/markdown/__snapshots__/presenter_test.snap index 998f239..79d0c11 100755 --- a/chronicle/release/format/markdown/__snapshots__/presenter_test.snap +++ b/chronicle/release/format/markdown/__snapshots__/presenter_test.snap @@ -1,19 +1,19 @@ [TestMarkdownPresenter_Present - 1] -# Changelog +# v0.19.1 ### Bug Fixes -- Redirect cursor hide/show to stderr. [#456](https://github.com/anchore/syft/pull/456) +- Redirect cursor hide/show to stderr. _([#456](https://github.com/anchore/syft/pull/456)) ### Added Features -- added feature. [#457](https://github.com/anchore/syft/pull/457) [@wagoodman](https://github.com/wagoodman) +- added feature. _([#457](https://github.com/anchore/syft/pull/457) @wagoodman) - another added feature. ### Breaking Changes -- breaking change. [#458](https://github.com/anchore/syft/pull/458) [#450](https://github.com/anchore/syft/issues/450) [@wagoodman](https://github.com/wagoodman) +- breaking change. _([#458](https://github.com/anchore/syft/pull/458) [#450](https://github.com/anchore/syft/issues/450) @wagoodman) **[(Full Changelog)](https://github.com/anchore/syft/compare/v0.19.0...v0.19.1)** @@ -22,13 +22,15 @@ [TestMarkdownPresenter_Present_NoTitle - 1] ### Bug Fixes -- Redirect cursor hide/show to stderr. [#456](https://github.com/anchore/syft/pull/456) +- Redirect cursor hide/show to stderr. _([#456](https://github.com/anchore/syft/pull/456)) **[(Full Changelog)](https://github.com/anchore/syft/compare/v0.19.0...v0.19.1)** --- [TestMarkdownPresenter_Present_NoChanges - 1] +# Changelog + **[(Full Changelog)](https://github.com/anchore/syft/compare/v0.19.0...v0.19.1)** --- diff --git a/chronicle/release/format/markdown/presenter.go b/chronicle/release/format/markdown/presenter.go index 9f0d550..d82dc0e 100644 --- a/chronicle/release/format/markdown/presenter.go +++ b/chronicle/release/format/markdown/presenter.go @@ -1,6 +1,7 @@ package markdown import ( + "bytes" "fmt" "io" "strings" @@ -53,6 +54,17 @@ func NewMarkdownPresenter(config Config) (*Presenter, error) { return nil, fmt.Errorf("unable to parse markdown presenter template: %w", err) } + titleTemplater, err := template.New("title").Funcs(funcMap).Parse(config.Title) + if err != nil { + return nil, fmt.Errorf("unable to parse markdown presenter title template: %w", err) + } + + buf := bytes.Buffer{} + if err := titleTemplater.Execute(&buf, config); err != nil { + return nil, fmt.Errorf("unable to template title: %w", err) + } + p.config.Title = buf.String() + p.templater = templater return &p, nil @@ -92,14 +104,25 @@ func formatSummary(summary change.Change) string { } } + var refs string for _, ref := range summary.References { - if ref.URL == "" { - result += fmt.Sprintf(" %s", ref.Text) - } else { - result += fmt.Sprintf(" [%s](%s)", ref.Text, ref.URL) + switch { + case ref.URL == "": + refs += fmt.Sprintf(" %s", ref.Text) + case strings.HasPrefix(ref.Text, "@") && strings.HasPrefix(ref.URL, "https://github.com/"): + // the github release page will automatically show all contributors as a footer. However, if you + // embed the contributor's github handle in a link, then this feature will not work. + refs += fmt.Sprintf(" %s", ref.Text) + default: + refs += fmt.Sprintf(" [%s](%s)", ref.Text, ref.URL) } } + refs = strings.TrimSpace(refs) + if refs != "" { + result += fmt.Sprintf(" _(%s)", refs) + } + return result + "\n" } diff --git a/chronicle/release/format/markdown/presenter_test.go b/chronicle/release/format/markdown/presenter_test.go index 9ee5f77..700e390 100644 --- a/chronicle/release/format/markdown/presenter_test.go +++ b/chronicle/release/format/markdown/presenter_test.go @@ -23,7 +23,8 @@ func TestMarkdownPresenter_Present(t *testing.T) { t, must( NewMarkdownPresenter(Config{ - Title: "Changelog", + // this is the default configuration from the CLI + Title: `{{ .Version }}`, Description: release.Description{ SupportedChanges: []change.TypeTitle{ { @@ -155,7 +156,7 @@ func TestMarkdownPresenter_Present_NoChanges(t *testing.T) { t, must( NewMarkdownPresenter(Config{ - Title: "", + Title: "Changelog", Description: release.Description{ SupportedChanges: []change.TypeTitle{}, Release: release.Release{ diff --git a/cmd/chronicle/cli/commands/create_config.go b/cmd/chronicle/cli/commands/create_config.go index 4e9957a..a67310d 100644 --- a/cmd/chronicle/cli/commands/create_config.go +++ b/cmd/chronicle/cli/commands/create_config.go @@ -66,7 +66,7 @@ func defaultCreateConfig() *createConfig { VersionFile: "", SinceTag: "", UntilTag: "", - Title: "", + Title: `{{ .Version }}`, RepoPath: "", SpeculateNextVersion: false, EnforceV0: false, From c18f9d429c4b518f181f9ed4d71056f2d268e956 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Thu, 14 Sep 2023 13:40:51 -0400 Subject: [PATCH 3/3] remove conventional commit prefixes from changelog lines Signed-off-by: Alex Goodman --- .../__snapshots__/presenter_test.snap | 10 +- .../release/format/markdown/presenter.go | 32 ++++-- .../release/format/markdown/presenter_test.go | 108 +++++++++++++++++- go.mod | 1 + go.sum | 8 ++ 5 files changed, 141 insertions(+), 18 deletions(-) diff --git a/chronicle/release/format/markdown/__snapshots__/presenter_test.snap b/chronicle/release/format/markdown/__snapshots__/presenter_test.snap index 79d0c11..97b6129 100755 --- a/chronicle/release/format/markdown/__snapshots__/presenter_test.snap +++ b/chronicle/release/format/markdown/__snapshots__/presenter_test.snap @@ -4,16 +4,16 @@ ### Bug Fixes -- Redirect cursor hide/show to stderr. _([#456](https://github.com/anchore/syft/pull/456)) +- Redirect cursor hide/show to stderr [[#456](https://github.com/anchore/syft/pull/456)] ### Added Features -- added feature. _([#457](https://github.com/anchore/syft/pull/457) @wagoodman) -- another added feature. +- added feature [[#457](https://github.com/anchore/syft/pull/457) @wagoodman] +- another added feature ### Breaking Changes -- breaking change. _([#458](https://github.com/anchore/syft/pull/458) [#450](https://github.com/anchore/syft/issues/450) @wagoodman) +- breaking change [[#458](https://github.com/anchore/syft/pull/458) [#450](https://github.com/anchore/syft/issues/450) @wagoodman] **[(Full Changelog)](https://github.com/anchore/syft/compare/v0.19.0...v0.19.1)** @@ -22,7 +22,7 @@ [TestMarkdownPresenter_Present_NoTitle - 1] ### Bug Fixes -- Redirect cursor hide/show to stderr. _([#456](https://github.com/anchore/syft/pull/456)) +- Redirect cursor hide/show to stderr [[#456](https://github.com/anchore/syft/pull/456)] **[(Full Changelog)](https://github.com/anchore/syft/compare/v0.19.0...v0.19.1)** diff --git a/chronicle/release/format/markdown/presenter.go b/chronicle/release/format/markdown/presenter.go index d82dc0e..447f291 100644 --- a/chronicle/release/format/markdown/presenter.go +++ b/chronicle/release/format/markdown/presenter.go @@ -7,6 +7,8 @@ import ( "strings" "text/template" + "github.com/leodido/go-conventionalcommits" + cc "github.com/leodido/go-conventionalcommits/parser" "github.com/wagoodman/go-presenter" "github.com/anchore/chronicle/chronicle/release" @@ -94,14 +96,10 @@ func formatChangeSection(title string, summaries []change.Change) string { } func formatSummary(summary change.Change) string { - result := fmt.Sprintf("- %s", strings.TrimSpace(summary.Text)) - if !endsWithPunctuation(result) { - switch result[len(result)-1:] { - case "!", ".", "?": - // pass - default: - result += "." - } + result := removeConventionalCommitPrefix(strings.TrimSpace(summary.Text)) + result = fmt.Sprintf("- %s", result) + if endsWithPunctuation(result) { + result = result[:len(result)-1] } var refs string @@ -120,7 +118,7 @@ func formatSummary(summary change.Change) string { refs = strings.TrimSpace(refs) if refs != "" { - result += fmt.Sprintf(" _(%s)", refs) + result += fmt.Sprintf(" [%s]", refs) } return result + "\n" @@ -132,3 +130,19 @@ func endsWithPunctuation(s string) bool { } return strings.Contains("!.?", s[len(s)-1:]) //nolint:gocritic } + +func removeConventionalCommitPrefix(s string) string { + res, err := cc.NewMachine(cc.WithTypes(conventionalcommits.TypesConventional)).Parse([]byte(s)) + if err != nil || res == nil || (res != nil && !res.Ok()) { + // probably not a conventional commit + return s + } + + // conventional commits always have a prefix and the message starts after the first ":" + fields := strings.SplitN(s, ":", 2) + if len(fields) == 2 { + return strings.TrimSpace(fields[1]) + } + + return s +} diff --git a/chronicle/release/format/markdown/presenter_test.go b/chronicle/release/format/markdown/presenter_test.go index 700e390..69e0fc3 100644 --- a/chronicle/release/format/markdown/presenter_test.go +++ b/chronicle/release/format/markdown/presenter_test.go @@ -53,7 +53,7 @@ func TestMarkdownPresenter_Present(t *testing.T) { Changes: []change.Change{ { ChangeTypes: []change.Type{change.NewType("bug", change.SemVerPatch)}, - Text: "Redirect cursor hide/show to stderr", + Text: "fix: Redirect cursor hide/show to stderr.", References: []change.Reference{ { Text: "#456", @@ -63,7 +63,7 @@ func TestMarkdownPresenter_Present(t *testing.T) { }, { ChangeTypes: []change.Type{change.NewType("added", change.SemVerMinor)}, - Text: "added feature", + Text: "added feature!", References: []change.Reference{ { Text: "#457", @@ -77,11 +77,11 @@ func TestMarkdownPresenter_Present(t *testing.T) { }, { ChangeTypes: []change.Type{change.NewType("added", change.SemVerMinor)}, - Text: "another added feature", + Text: "feat(api)!: another added feature", }, { ChangeTypes: []change.Type{change.NewType("breaking", change.SemVerMajor)}, - Text: "breaking change", + Text: "breaking change?", References: []change.Reference{ { Text: "#458", @@ -190,3 +190,103 @@ func assertPresenterAgainstGoldenSnapshot(t *testing.T, pres presenter.Presenter snaps.MatchSnapshot(t, string(actual)) } + +func Test_removeConventionalCommitPrefix(t *testing.T) { + + tests := []struct { + name string + want string + }{ + // positive cases + { + name: "feat: add user authentication", + want: "add user authentication", + }, + { + name: "fix: resolve null pointer exception", + want: "resolve null pointer exception", + }, + { + name: "docs: update README", + want: "update README", + }, + { + name: "style: format code according to style guide", + want: "format code according to style guide", + }, + { + name: "refactor: extract reusable function", + want: "extract reusable function", + }, + { + name: "perf: optimize database queries", + want: "optimize database queries", + }, + { + name: "test: add unit tests", + want: "add unit tests", + }, + { + name: "build: update build process", + want: "update build process", + }, + { + name: "ci: configure Travis CI", + want: "configure Travis CI", + }, + { + name: "chore: perform maintenance tasks", + want: "perform maintenance tasks", + }, + // positive case odd balls + { + name: "chore: can end with punctuation.", + want: "can end with punctuation.", + }, + { + name: "revert!: revert: previous: commit", + want: "revert: previous: commit", + }, + { + name: "feat(api)!: implement new: API endpoints", + want: "implement new: API endpoints", + }, + { + name: "feat!: add awesome new feature (closes #123)", + want: "add awesome new feature (closes #123)", + }, + { + name: "fix(ui): fix layout issue (fixes #456)", + want: "fix layout issue (fixes #456)", + }, + // negative cases + { + name: "reallycoolthing: is done!", + want: "reallycoolthing: is done!", + }, + { + name: "feature: is done!", + want: "feature: is done!", + }, + { + // missing description... just leave it alone + name: "feat(scope): ", + want: "feat(scope): ", + }, + { + // missing whitespace in description (yes, that's a cc requirement) + name: "feat(scope):something", + want: "feat(scope):something", + }, + { + // has a newline + name: "feat: something\n wicked this way comes", + want: "feat: something\n wicked this way comes", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equalf(t, tt.want, removeConventionalCommitPrefix(tt.name), "removeConventionalCommitPrefix(%v)", tt.name) + }) + } +} diff --git a/go.mod b/go.mod index 161ad97..d7adee0 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/coreos/go-semver v0.3.1 github.com/gkampitakis/go-snaps v0.4.10 github.com/go-git/go-git/v5 v5.9.0 + github.com/leodido/go-conventionalcommits v0.11.0 github.com/scylladb/go-set v1.0.2 github.com/shurcooL/githubv4 v0.0.0-20201206200315-234843c633fa github.com/spf13/cobra v1.7.0 diff --git a/go.sum b/go.sum index c27e1df..000707d 100644 --- a/go.sum +++ b/go.sum @@ -206,12 +206,16 @@ github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leodido/go-conventionalcommits v0.11.0 h1:b7KW1ZzGqouzP7Yi4uobLx/rDFnOD0fewX3t7XqYTCE= +github.com/leodido/go-conventionalcommits v0.11.0/go.mod h1:wVZdFNRHTN3Spla4r7GZkUDyQMDQtA/A+Vp2kRUMVJs= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A= @@ -244,10 +248,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/rwtodd/Go.Sed v0.0.0-20210816025313-55464686f9ef/go.mod h1:8AEUvGVi2uQ5b24BIhcr0GCcpd/RNAFWaN2CJFrWIIQ= github.com/scylladb/go-set v1.0.2 h1:SkvlMCKhP0wyyct6j+0IHJkBkSZL+TDzZ4E7f7BCcRE= github.com/scylladb/go-set v1.0.2/go.mod h1:DkpGd78rljTxKAnTDPFqXSGxvETQnJyuSOQwsHycqfs= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= @@ -257,6 +263,7 @@ github.com/shurcooL/githubv4 v0.0.0-20201206200315-234843c633fa/go.mod h1:hAF0iL github.com/shurcooL/graphql v0.0.0-20200928012149-18c5c3165e3a h1:KikTa6HtAK8cS1qjvUvvq4QO21QnwC+EfvB+OAuZ/ZU= github.com/shurcooL/graphql v0.0.0-20200928012149-18c5c3165e3a/go.mod h1:AuYgA5Kyo4c7HfUmvRGs/6rGlMMV/6B1bVnB9JxJEEg= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/skeema/knownhosts v1.2.0 h1:h9r9cf0+u7wSE+M183ZtMGgOJKiL96brpaz5ekfJCpM= @@ -472,6 +479,7 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=