mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-08 10:47:02 +00:00
refactor: move things to packages (#39)
This commit is contained in:
parent
44184a77f9
commit
a0a064d387
32 changed files with 923 additions and 892 deletions
32
internal/updater/changelog.go
Normal file
32
internal/updater/changelog.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package updater
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
const (
|
||||
ChangelogHeader = "# Changelog"
|
||||
ChangelogFile = "CHANGELOG.md"
|
||||
)
|
||||
|
||||
var (
|
||||
ChangelogUpdaterHeaderRegex = regexp.MustCompile(`^# Changelog\n`)
|
||||
)
|
||||
|
||||
func Changelog(info ReleaseInfo) Updater {
|
||||
return func(content string) (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