srpmproc/pkg/misc/regex.go

34 lines
837 B
Go
Raw Normal View History

package misc
import (
"fmt"
"github.com/rocky-linux/srpmproc/pkg/data"
"path/filepath"
"regexp"
)
func GetTagImportRegex(pd *data.ProcessData) *regexp.Regexp {
2022-05-10 10:02:37 +00:00
branchRegex := regexp.QuoteMeta(fmt.Sprintf("%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix))
2022-04-21 05:25:44 +00:00
if !pd.StrictBranchMode {
2022-04-21 23:44:18 +00:00
branchRegex += "(?:.+|)"
} else {
branchRegex += "(?:-stream-.+|)"
}
2022-05-10 10:02:37 +00:00
initialVerRegex := regexp.QuoteMeta(filepath.Base(pd.RpmLocation)) + "-"
if pd.PackageVersion != "" {
2022-05-10 10:02:37 +00:00
initialVerRegex += regexp.QuoteMeta(pd.PackageVersion) + "-"
} else {
initialVerRegex += ".+-"
}
if pd.PackageRelease != "" {
2022-05-10 10:02:37 +00:00
initialVerRegex += regexp.QuoteMeta(pd.PackageRelease)
} else {
initialVerRegex += ".+"
}
regex := fmt.Sprintf("(?i)refs/tags/(imports/(%s)/(%s))", branchRegex, initialVerRegex)
return regexp.MustCompile(regex)
}