From 1be133b4fda78a239838b40bd6404400e80c02e9 Mon Sep 17 00:00:00 2001 From: k4yt3x Date: Tue, 27 Feb 2024 18:02:39 +0000 Subject: [PATCH] feat(changelog): added the feature to automatically fix incorrect section heading levels Signed-off-by: k4yt3x --- CHANGELOG.md | 1 + cmd/autobump/changelog.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dd9522..e33626c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Exceptions are acceptable depending on the circumstances (critical bug fixes tha ### Added +- added the feature to automatically fix incorrect section heading levels - added the workflow to have a complete pipeline with security and quality checks ### Changed diff --git a/cmd/autobump/changelog.go b/cmd/autobump/changelog.go index 5c88582..bf471f1 100644 --- a/cmd/autobump/changelog.go +++ b/cmd/autobump/changelog.go @@ -182,6 +182,15 @@ func updateSection( unreleasedSection []string, nextVersion semver.Version, ) ([]string, *semver.Version, error) { + // Fix incorrect section heading levels + re := regexp.MustCompile(`(?i)^\s*#+\s*(Added|Changed|Deprecated|Removed|Fixed|Security)`) + for i, line := range unreleasedSection { + if re.MatchString(line) { + correctedLine := "### " + strings.TrimSpace(strings.Replace(line, "#", "", -1)) + unreleasedSection[i] = correctedLine + } + } + var newSection []string var currentSection *[]string sections := map[string]*[]string{ @@ -264,5 +273,9 @@ func updateSection( } } + if majorChanges == 0 && minorChanges == 0 && patchChanges == 0 { + return nil, nil, fmt.Errorf("no changes found in the unreleased section") + } + return newSection, &nextVersion, nil }