From 11a847fe2203a0bb7a660c51b16b2efb8d248d02 Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Mon, 15 Feb 2021 01:47:20 -0300 Subject: [PATCH] feat: add support to rename or disable breaking changes section from release notes --- sv/formatter.go | 8 ++++---- sv/helpers_test.go | 10 +++++++--- sv/releasenotes.go | 14 ++++++++++++-- sv/releasenotes_test.go | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/sv/formatter.go b/sv/formatter.go index 4ce87ec..45d32c9 100644 --- a/sv/formatter.go +++ b/sv/formatter.go @@ -10,7 +10,7 @@ type releaseNoteTemplateVariables struct { Version string Date string Sections map[string]ReleaseNoteSection - BreakingChanges []string + BreakingChanges BreakingChangeSection } const ( @@ -32,10 +32,10 @@ const ( {{- end}} {{- end}}` - rnSectionBreakingChanges = `{{- if .}} + rnSectionBreakingChanges = `{{- if ne .Name ""}} -### Breaking Changes -{{range $k,$v := .}} +### {{.Name}} +{{range $k,$v := .Messages}} - {{$v}} {{- end}} {{- end}}` diff --git a/sv/helpers_test.go b/sv/helpers_test.go index b95c4f0..e4fa880 100644 --- a/sv/helpers_test.go +++ b/sv/helpers_test.go @@ -11,14 +11,14 @@ func version(v string) semver.Version { return *r } -func commitlog(t string, metadata map[string]string) GitCommitLog { +func commitlog(ctype string, metadata map[string]string) GitCommitLog { breaking := false if _, found := metadata[breakingChangeMetadataKey]; found { breaking = true } return GitCommitLog{ Message: CommitMessage{ - Type: t, + Type: ctype, Description: "subject text", IsBreakingChange: breaking, Metadata: metadata, @@ -27,11 +27,15 @@ func commitlog(t string, metadata map[string]string) GitCommitLog { } func releaseNote(version *semver.Version, date time.Time, sections map[string]ReleaseNoteSection, breakingChanges []string) ReleaseNote { + var bchanges BreakingChangeSection + if len(breakingChanges) > 0 { + bchanges = BreakingChangeSection{Name: "Breaking Changes", Messages: breakingChanges} + } return ReleaseNote{ Version: version, Date: date.Truncate(time.Minute), Sections: sections, - BreakingChanges: breakingChanges, + BreakingChanges: bchanges, } } diff --git a/sv/releasenotes.go b/sv/releasenotes.go index 86b196d..e02c291 100644 --- a/sv/releasenotes.go +++ b/sv/releasenotes.go @@ -40,7 +40,11 @@ func (p ReleaseNoteProcessorImpl) Create(version *semver.Version, date time.Time } } - return ReleaseNote{Version: version, Date: date.Truncate(time.Minute), Sections: sections, BreakingChanges: breakingChanges} + var breakingChangeSection BreakingChangeSection + if name, exists := p.cfg.Headers[breakingChangeMetadataKey]; exists && len(breakingChanges) > 0 { + breakingChangeSection = BreakingChangeSection{Name: name, Messages: breakingChanges} + } + return ReleaseNote{Version: version, Date: date.Truncate(time.Minute), Sections: sections, BreakingChanges: breakingChangeSection} } // ReleaseNote release note. @@ -48,7 +52,13 @@ type ReleaseNote struct { Version *semver.Version Date time.Time Sections map[string]ReleaseNoteSection - BreakingChanges []string + BreakingChanges BreakingChangeSection +} + +// BreakingChangeSection breaking change section +type BreakingChangeSection struct { + Name string + Messages []string } // ReleaseNoteSection release note section. diff --git a/sv/releasenotes_test.go b/sv/releasenotes_test.go index aa09df0..9bf51f9 100644 --- a/sv/releasenotes_test.go +++ b/sv/releasenotes_test.go @@ -42,7 +42,7 @@ func TestReleaseNoteProcessorImpl_Create(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - p := NewReleaseNoteProcessor(ReleaseNotesConfig{Headers: map[string]string{"t1": "Tag 1", "t2": "Tag 2"}}) + p := NewReleaseNoteProcessor(ReleaseNotesConfig{Headers: map[string]string{"t1": "Tag 1", "t2": "Tag 2", "breaking-change": "Breaking Changes"}}) if got := p.Create(tt.version, tt.date, tt.commits); !reflect.DeepEqual(got, tt.want) { t.Errorf("ReleaseNoteProcessorImpl.Create() = %v, want %v", got, tt.want) }