Skip to content

Commit

Permalink
feat(changelog): added the feature to automatically fix incorrect sec…
Browse files Browse the repository at this point in the history
…tion heading levels

Signed-off-by: k4yt3x <[email protected]>
  • Loading branch information
k4yt3x committed Feb 27, 2024
1 parent f8a4f8c commit 1be133b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions cmd/autobump/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
}

0 comments on commit 1be133b

Please sign in to comment.