Make destination branch prefix and import branch prefix configurable

This commit is contained in:
Mustafa Gezen 2021-02-14 18:25:00 +01:00
parent b699ae6dac
commit dc1067cc38
4 changed files with 55 additions and 46 deletions

View File

@ -26,6 +26,8 @@ var (
gitCommitterEmail string
modulePrefix string
rpmPrefix string
importBranchPrefix string
branchPrefix string
noDupMode bool
moduleMode bool
)
@ -92,6 +94,8 @@ func mn(_ *cobra.Command, _ []string) {
GitCommitterName: gitCommitterName,
GitCommitterEmail: gitCommitterEmail,
ModulePrefix: modulePrefix,
ImportBranchPrefix: importBranchPrefix,
BranchPrefix: branchPrefix,
Authenticator: authenticator,
NoDupMode: noDupMode,
ModuleMode: moduleMode,
@ -114,6 +118,8 @@ func main() {
root.Flags().StringVar(&gitCommitterEmail, "git-committer-email", "mustafa+distrobuild@bycrates.com", "Email of committer")
root.Flags().StringVar(&modulePrefix, "module-prefix", "https://git.centos.org/modules", "Where to retrieve modules if exists. Only used when source-rpm is a git repo")
root.Flags().StringVar(&rpmPrefix, "rpm-prefix", "https://git.centos.org/rpms", "Where to retrieve SRPM content. Only used when source-rpm is not a local file")
root.Flags().StringVar(&importBranchPrefix, "import-branch-prefix", "c", "Import branch prefix")
root.Flags().StringVar(&branchPrefix, "branch-prefix", "r", "Branch prefix (replaces import-branch-prefix)")
root.Flags().BoolVar(&noDupMode, "no-dup-mode", false, "If enabled, skips already imported tags")
root.Flags().BoolVar(&moduleMode, "module-mode", false, "If enabled, imports a module instead of a package")

View File

@ -298,13 +298,13 @@ func patchModuleYaml(pd *ProcessData, md *modeData) {
// we're bootstrapping a new distro for latest RHEL8 anyways. So earlier
// versions are not that important
if strings.HasPrefix(rpm.Ref, "stream-rhel-") {
repString := fmt.Sprintf("rocky%ss-", string(split[4][0]))
newString := fmt.Sprintf("rocky%s-", string(split[4][0]))
repString := fmt.Sprintf("%s%ss-", pd.BranchPrefix, string(split[4][0]))
newString := fmt.Sprintf("%s%s-", pd.BranchPrefix, string(split[4][0]))
pushBranch = strings.Replace(md.pushBranch, repString, newString, 1)
} else if strings.HasPrefix(rpm.Ref, "stream-") && len(split) == 2 {
pushBranch = md.pushBranch
} else if strings.HasPrefix(rpm.Ref, "stream-") {
pushBranch = fmt.Sprintf("rocky%s-stream-%s", string(split[3][0]), split[1])
pushBranch = fmt.Sprintf("%s%s-stream-%s", pd.BranchPrefix, string(split[3][0]), split[1])
} else if strings.HasPrefix(rpm.Ref, "rhel-") {
pushBranch = md.pushBranch
} else {

View File

@ -21,7 +21,7 @@ import (
"time"
)
var tagImportRegex = regexp.MustCompile("refs/tags/(imports/(.*)/(.*))")
var tagImportRegex *regexp.Regexp
type ProcessData struct {
RpmLocation string
@ -33,6 +33,8 @@ type ProcessData struct {
GitCommitterEmail string
Mode int
ModulePrefix string
ImportBranchPrefix string
BranchPrefix string
Authenticator *ssh.PublicKeys
Importer ImportMode
BlobStorage blob.Storage
@ -65,6 +67,7 @@ type modeData struct {
// all files that are remote goes into .gitignore
// all ignored files' hash goes into .{name}.metadata
func ProcessRPM(pd *ProcessData) {
tagImportRegex = regexp.MustCompile(fmt.Sprintf("refs/tags/(imports/(%s.|%s.-.+)/(.*))", pd.ImportBranchPrefix, pd.ImportBranchPrefix))
md := pd.Importer.RetrieveSource(pd)
remotePrefix := "dist"
@ -146,8 +149,8 @@ func ProcessRPM(pd *ProcessData) {
}
match := tagImportRegex.FindStringSubmatch(matchString)
md.pushBranch = "rocky" + strings.TrimPrefix(match[2], "c")
newTag := "imports/rocky" + strings.TrimPrefix(match[1], "imports/c")
md.pushBranch = pd.BranchPrefix + strings.TrimPrefix(match[2], "c")
newTag := "imports/" + pd.BranchPrefix + strings.TrimPrefix(match[1], "imports/c")
shouldContinue := true
for _, ignoredTag := range tagIgnoreList {

View File

@ -88,7 +88,7 @@ func (s *SrpmMode) RetrieveSource(pd *ProcessData) *modeData {
}
}
branch := fmt.Sprintf("rocky%d", pd.Version)
branch := fmt.Sprintf("%s%d", pd.BranchPrefix, pd.Version)
return &modeData{
repo: repo,
worktree: w,