From 7d04c80d6ea31fc02f38083ec424fbb3e148dc61 Mon Sep 17 00:00:00 2001 From: Nguyen Tran Hau Date: Thu, 15 Apr 2021 11:59:01 +0700 Subject: [PATCH] fix: correct time layout (#13) * fix: use correct date layout * chore: wrap date layout inside parenthesis Co-authored-by: Tran Hau --- go.mod | 1 + go.sum | 2 ++ pkg/changelog/markdown.go | 9 +++------ .../testdata/TestGenerateMarkdown/empty_old_data.golden | 2 +- .../ignore_commits_outside_scope.golden | 2 +- .../testdata/TestGenerateMarkdown/many_commits.golden | 2 +- pkg/convention/option.go | 4 ++-- .../TestNewCommit/Commit_message_with_no_body.golden | 2 +- ...character_to_draw_attention_to_breaking_change.golden | 2 +- .../TestNewCommit/Commit_message_with_scope.golden | 2 +- pkg/convention/testdata/TestNewCommit/Misc.golden | 2 +- .../testdata/TestNewCommit/Misc_with_author_date.golden | 2 +- pkg/convention/testdata/TestNewCommit/Mixedcase.golden | 2 +- pkg/convention/testdata/TestNewCommit/Uppercase.golden | 2 +- 14 files changed, 18 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 7d3abf6..da8d80a 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/go-git/go-git/v5 v5.3.0 github.com/google/go-cmp v0.5.5 // indirect + github.com/haunt98/clock v0.1.0 github.com/haunt98/color v0.1.0 github.com/kevinburke/ssh_config v1.1.0 // indirect github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e diff --git a/go.sum b/go.sum index 367d886..fbcbcbe 100644 --- a/go.sum +++ b/go.sum @@ -35,6 +35,8 @@ github.com/go-git/go-git/v5 v5.3.0/go.mod h1:xdX4bWJ48aOrdhnl2XqHYstHbbp6+LFS4r4 github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/haunt98/clock v0.1.0 h1:iRaGSoQ21Z+gD9J4mVoYqL4liAg5eGwPkkPGknmfV6A= +github.com/haunt98/clock v0.1.0/go.mod h1:Sq2/R7IgMjxnqgCF3f69ROb8ZeF9PO0YaQW1p3wXGiE= github.com/haunt98/color v0.1.0 h1:qfP5oNI3aoUC8T+bH/JNVAg79ljyhTGpgfqSKWhkiQQ= github.com/haunt98/color v0.1.0/go.mod h1:V4BPVUSuiOItuVZHRHUTkpxO7OYQiP0DSgIWMpC/2qs= github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= diff --git a/pkg/changelog/markdown.go b/pkg/changelog/markdown.go index a1e786e..204745d 100644 --- a/pkg/changelog/markdown.go +++ b/pkg/changelog/markdown.go @@ -7,6 +7,7 @@ import ( "github.com/haunt98/changeloguru/pkg/convention" "github.com/haunt98/changeloguru/pkg/markdown" + "github.com/haunt98/clock" ) const ( @@ -70,9 +71,10 @@ func GenerateMarkdown(commits []convention.Commit, scopes map[string]struct{}, v } // Adding title, version to nodes + versionHeader := fmt.Sprintf("%s (%s)", version, clock.FormatDate(when)) nodes = append([]markdown.Node{ markdown.NewHeader(firstLevel, title), - markdown.NewHeader(secondLevel, getVersionHeader(version, when)), + markdown.NewHeader(secondLevel, versionHeader), }, nodes...) return nodes @@ -89,8 +91,3 @@ func ParseMarkdown(data string) []markdown.Node { return nodes } - -func getVersionHeader(version string, when time.Time) string { - year, month, day := when.Date() - return fmt.Sprintf("%s (%d-%d-%d)", version, year, month, day) -} diff --git a/pkg/changelog/testdata/TestGenerateMarkdown/empty_old_data.golden b/pkg/changelog/testdata/TestGenerateMarkdown/empty_old_data.golden index 585b880..f17d1be 100644 --- a/pkg/changelog/testdata/TestGenerateMarkdown/empty_old_data.golden +++ b/pkg/changelog/testdata/TestGenerateMarkdown/empty_old_data.golden @@ -1,6 +1,6 @@ # CHANGELOG -## v1.0.0 (2020-1-18) +## v1.0.0 (2020-01-18) ### Added diff --git a/pkg/changelog/testdata/TestGenerateMarkdown/ignore_commits_outside_scope.golden b/pkg/changelog/testdata/TestGenerateMarkdown/ignore_commits_outside_scope.golden index d9f267f..47ef3ed 100644 --- a/pkg/changelog/testdata/TestGenerateMarkdown/ignore_commits_outside_scope.golden +++ b/pkg/changelog/testdata/TestGenerateMarkdown/ignore_commits_outside_scope.golden @@ -1,6 +1,6 @@ # CHANGELOG -## v1.0.0 (2020-3-22) +## v1.0.0 (2020-03-22) ### Added diff --git a/pkg/changelog/testdata/TestGenerateMarkdown/many_commits.golden b/pkg/changelog/testdata/TestGenerateMarkdown/many_commits.golden index c445694..a67f76d 100644 --- a/pkg/changelog/testdata/TestGenerateMarkdown/many_commits.golden +++ b/pkg/changelog/testdata/TestGenerateMarkdown/many_commits.golden @@ -1,6 +1,6 @@ # CHANGELOG -## v1.0.0 (2020-1-18) +## v1.0.0 (2020-01-18) ### Added diff --git a/pkg/convention/option.go b/pkg/convention/option.go index 9ec9cd6..ae14fb0 100644 --- a/pkg/convention/option.go +++ b/pkg/convention/option.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/haunt98/changeloguru/pkg/git" + "github.com/haunt98/clock" ) var ( @@ -51,8 +52,7 @@ func GetTypeAndScope(gitCommit git.Commit) OptionFn { func AddAuthorDate(gitCommit git.Commit) OptionFn { return func(c *Commit) error { - year, month, day := gitCommit.Author.When.Date() - c.RawHeader = fmt.Sprintf("%s (%d-%d-%d)", c.RawHeader, year, month, day) + c.RawHeader = fmt.Sprintf("%s (%s)", c.RawHeader, clock.FormatDate(gitCommit.Author.When)) return nil } diff --git a/pkg/convention/testdata/TestNewCommit/Commit_message_with_no_body.golden b/pkg/convention/testdata/TestNewCommit/Commit_message_with_no_body.golden index f35f53d..57386ec 100644 --- a/pkg/convention/testdata/TestNewCommit/Commit_message_with_no_body.golden +++ b/pkg/convention/testdata/TestNewCommit/Commit_message_with_no_body.golden @@ -1,5 +1,5 @@ { - "RawHeader": "docs: correct spelling of CHANGELOG (1-1-1)", + "RawHeader": "docs: correct spelling of CHANGELOG (0001-01-01)", "Type": "docs", "Scope": "" } \ No newline at end of file diff --git a/pkg/convention/testdata/TestNewCommit/Commit_message_with_not_character_to_draw_attention_to_breaking_change.golden b/pkg/convention/testdata/TestNewCommit/Commit_message_with_not_character_to_draw_attention_to_breaking_change.golden index e6e9938..a3f784b 100644 --- a/pkg/convention/testdata/TestNewCommit/Commit_message_with_not_character_to_draw_attention_to_breaking_change.golden +++ b/pkg/convention/testdata/TestNewCommit/Commit_message_with_not_character_to_draw_attention_to_breaking_change.golden @@ -1,5 +1,5 @@ { - "RawHeader": "refactor!: drop support for Node 6 (1-1-1)", + "RawHeader": "refactor!: drop support for Node 6 (0001-01-01)", "Type": "refactor", "Scope": "" } \ No newline at end of file diff --git a/pkg/convention/testdata/TestNewCommit/Commit_message_with_scope.golden b/pkg/convention/testdata/TestNewCommit/Commit_message_with_scope.golden index f6dd9c0..42ccd30 100644 --- a/pkg/convention/testdata/TestNewCommit/Commit_message_with_scope.golden +++ b/pkg/convention/testdata/TestNewCommit/Commit_message_with_scope.golden @@ -1,5 +1,5 @@ { - "RawHeader": "feat(lang): add polish language (1-1-1)", + "RawHeader": "feat(lang): add polish language (0001-01-01)", "Type": "feat", "Scope": "lang" } \ No newline at end of file diff --git a/pkg/convention/testdata/TestNewCommit/Misc.golden b/pkg/convention/testdata/TestNewCommit/Misc.golden index a9ff8b0..1465d0b 100644 --- a/pkg/convention/testdata/TestNewCommit/Misc.golden +++ b/pkg/convention/testdata/TestNewCommit/Misc.golden @@ -1,5 +1,5 @@ { - "RawHeader": "random git message (1-1-1)", + "RawHeader": "random git message (0001-01-01)", "Type": "misc", "Scope": "" } \ No newline at end of file diff --git a/pkg/convention/testdata/TestNewCommit/Misc_with_author_date.golden b/pkg/convention/testdata/TestNewCommit/Misc_with_author_date.golden index 47df7e2..6a1b271 100644 --- a/pkg/convention/testdata/TestNewCommit/Misc_with_author_date.golden +++ b/pkg/convention/testdata/TestNewCommit/Misc_with_author_date.golden @@ -1,5 +1,5 @@ { - "RawHeader": "random git message (2020-4-1)", + "RawHeader": "random git message (2020-04-01)", "Type": "misc", "Scope": "" } \ No newline at end of file diff --git a/pkg/convention/testdata/TestNewCommit/Mixedcase.golden b/pkg/convention/testdata/TestNewCommit/Mixedcase.golden index bd7de8b..70cab9f 100644 --- a/pkg/convention/testdata/TestNewCommit/Mixedcase.golden +++ b/pkg/convention/testdata/TestNewCommit/Mixedcase.golden @@ -1,5 +1,5 @@ { - "RawHeader": "Docs: correct spelling of CHANGELOG (1-1-1)", + "RawHeader": "Docs: correct spelling of CHANGELOG (0001-01-01)", "Type": "docs", "Scope": "" } \ No newline at end of file diff --git a/pkg/convention/testdata/TestNewCommit/Uppercase.golden b/pkg/convention/testdata/TestNewCommit/Uppercase.golden index 544dc10..316d7ea 100644 --- a/pkg/convention/testdata/TestNewCommit/Uppercase.golden +++ b/pkg/convention/testdata/TestNewCommit/Uppercase.golden @@ -1,5 +1,5 @@ { - "RawHeader": "REFACTOR!: drop support for Node 6 (1-1-1)", + "RawHeader": "REFACTOR!: drop support for Node 6 (0001-01-01)", "Type": "refactor", "Scope": "" } \ No newline at end of file