2021-09-03 21:07:02 +00:00
|
|
|
package misc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-05-05 02:25:07 +00:00
|
|
|
"path/filepath"
|
2021-09-03 21:07:02 +00:00
|
|
|
"regexp"
|
2022-09-28 03:32:50 +00:00
|
|
|
"strings"
|
2022-11-06 03:53:02 +00:00
|
|
|
|
|
|
|
"github.com/rocky-linux/srpmproc/pkg/data"
|
2021-09-03 21:07:02 +00:00
|
|
|
)
|
|
|
|
|
2022-04-21 04:30:33 +00:00
|
|
|
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 += "(?:.+|)"
|
2022-04-23 20:56:39 +00:00
|
|
|
} else {
|
|
|
|
branchRegex += "(?:-stream-.+|)"
|
2021-09-03 21:07:02 +00:00
|
|
|
}
|
2022-05-05 02:25:07 +00:00
|
|
|
|
2022-05-10 10:02:37 +00:00
|
|
|
initialVerRegex := regexp.QuoteMeta(filepath.Base(pd.RpmLocation)) + "-"
|
2022-05-05 02:25:07 +00:00
|
|
|
if pd.PackageVersion != "" {
|
2022-05-10 10:02:37 +00:00
|
|
|
initialVerRegex += regexp.QuoteMeta(pd.PackageVersion) + "-"
|
2022-05-05 02:25:07 +00:00
|
|
|
} else {
|
|
|
|
initialVerRegex += ".+-"
|
|
|
|
}
|
|
|
|
if pd.PackageRelease != "" {
|
2022-05-10 10:02:37 +00:00
|
|
|
initialVerRegex += regexp.QuoteMeta(pd.PackageRelease)
|
2022-05-05 02:25:07 +00:00
|
|
|
} else {
|
|
|
|
initialVerRegex += ".+"
|
|
|
|
}
|
|
|
|
|
2022-05-09 17:57:43 +00:00
|
|
|
regex := fmt.Sprintf("(?i)refs/tags/(imports/(%s)/(%s))", branchRegex, initialVerRegex)
|
2022-04-21 04:30:33 +00:00
|
|
|
|
|
|
|
return regexp.MustCompile(regex)
|
2021-09-03 21:07:02 +00:00
|
|
|
}
|
2022-09-28 03:32:50 +00:00
|
|
|
|
|
|
|
// Given a git reference in tagless mode (like "refs/heads/c9s", or "refs/heads/stream-httpd-2.4-rhel-9.1.0"), determine
|
|
|
|
// if we are ok with importing that reference. We are looking for the traditional <prefix><version><suffix> pattern, like "c9s", and also the
|
|
|
|
// modular "stream-<NAME>-<VERSION>-rhel-<VERSION> branch pattern as well
|
|
|
|
func TaglessRefOk(tag string, pd *data.ProcessData) bool {
|
2023-03-06 03:04:20 +00:00
|
|
|
// First case is very easy: if we are exactly "refs/heads/<prefix><version><suffix>" , then this is def. a branch we should import
|
|
|
|
if tag == fmt.Sprintf("refs/heads/%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix) {
|
2022-09-28 03:32:50 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Less easy: if a modular branch is present (starts w/ "stream-"), we need to check if it's part of our major version, and return true if it is
|
|
|
|
// (major version means we look for the text "rhel-X." in the branch name, like "rhel-9.1.0")
|
|
|
|
if strings.HasPrefix(tag, "refs/heads/stream-") && strings.Contains(tag, fmt.Sprintf("rhel-%d.", pd.Version)) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|