mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-08 02:37:04 +00:00
refactor: move changelog file to updater interface
This commit is contained in:
parent
47de2f97bc
commit
e88dbcaf85
5 changed files with 79 additions and 151 deletions
19
updater.go
19
updater.go
|
|
@ -1,12 +1,14 @@
|
|||
package rp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
GenericUpdaterSemVerRegex = regexp.MustCompile(`\d+\.\d+\.\d+(-[\w.]+)?(.*x-releaser-pleaser-version)`)
|
||||
ChangelogUpdaterHeaderRegex = regexp.MustCompile(`^# Changelog\n`)
|
||||
)
|
||||
|
||||
type ReleaseInfo struct {
|
||||
|
|
@ -26,3 +28,20 @@ func (u *GenericUpdater) UpdateContent(content string, info ReleaseInfo) (string
|
|||
|
||||
return GenericUpdaterSemVerRegex.ReplaceAllString(content, version+"${2}"), nil
|
||||
}
|
||||
|
||||
type ChangelogUpdater struct{}
|
||||
|
||||
func (u *ChangelogUpdater) UpdateContent(content string, info ReleaseInfo) (string, error) {
|
||||
headerIndex := ChangelogUpdaterHeaderRegex.FindStringIndex(content)
|
||||
if headerIndex == nil && len(content) != 0 {
|
||||
return "", fmt.Errorf("unexpected format of CHANGELOG.md, header does not match")
|
||||
}
|
||||
if headerIndex != nil {
|
||||
// Remove the header from the content
|
||||
content = content[headerIndex[1]:]
|
||||
}
|
||||
|
||||
content = ChangelogHeader + "\n\n" + info.ChangelogEntry + content
|
||||
|
||||
return content, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue