releaser-pleaser/updater.go

29 lines
662 B
Go
Raw Normal View History

2024-08-01 23:00:56 +02:00
package rp
import (
"regexp"
"strings"
)
2024-08-01 23:00:56 +02:00
var (
GenericUpdaterSemVerRegex = regexp.MustCompile(`\d+\.\d+\.\d+(-[\w.]+)?(.*x-releaser-pleaser-version)`)
2024-08-01 23:00:56 +02:00
)
type ReleaseInfo struct {
Version string
ChangelogEntry string
}
type Updater interface {
UpdateContent(content string, info ReleaseInfo) (string, error)
}
type GenericUpdater struct{}
func (u *GenericUpdater) UpdateContent(content string, info ReleaseInfo) (string, error) {
// We strip the "v" prefix to avoid adding/removing it from the users input.
version := strings.TrimPrefix(info.Version, "v")
return GenericUpdaterSemVerRegex.ReplaceAllString(content, version+"${2}"), nil
2024-08-01 23:00:56 +02:00
}