Commit dc1067cc authored by Mustafa Gezen's avatar Mustafa Gezen
Browse files

Make destination branch prefix and import branch prefix configurable

parent b699ae6d
......@@ -16,18 +16,20 @@ import (
)
var (
sourceRpm string
sshKeyLocation string
sshUser string
upstreamPrefix string
version int
storageAddr string
gitCommitterName string
gitCommitterEmail string
modulePrefix string
rpmPrefix string
noDupMode bool
moduleMode bool
sourceRpm string
sshKeyLocation string
sshUser string
upstreamPrefix string
version int
storageAddr string
gitCommitterName string
gitCommitterEmail string
modulePrefix string
rpmPrefix string
importBranchPrefix string
branchPrefix string
noDupMode bool
moduleMode bool
)
var root = &cobra.Command{
......@@ -82,19 +84,21 @@ func mn(_ *cobra.Command, _ []string) {
}
internal.ProcessRPM(&internal.ProcessData{
Importer: importer,
RpmLocation: sourceRpmLocation,
UpstreamPrefix: upstreamPrefix,
SshKeyLocation: sshKeyLocation,
SshUser: sshUser,
Version: version,
BlobStorage: blobStorage,
GitCommitterName: gitCommitterName,
GitCommitterEmail: gitCommitterEmail,
ModulePrefix: modulePrefix,
Authenticator: authenticator,
NoDupMode: noDupMode,
ModuleMode: moduleMode,
Importer: importer,
RpmLocation: sourceRpmLocation,
UpstreamPrefix: upstreamPrefix,
SshKeyLocation: sshKeyLocation,
SshUser: sshUser,
Version: version,
BlobStorage: blobStorage,
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")
......
......@@ -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 {
......
......@@ -21,23 +21,25 @@ import (
"time"
)
var tagImportRegex = regexp.MustCompile("refs/tags/(imports/(.*)/(.*))")
var tagImportRegex *regexp.Regexp
type ProcessData struct {
RpmLocation string
UpstreamPrefix string
SshKeyLocation string
SshUser string
Version int
GitCommitterName string
GitCommitterEmail string
Mode int
ModulePrefix string
Authenticator *ssh.PublicKeys
Importer ImportMode
BlobStorage blob.Storage
NoDupMode bool
ModuleMode bool
RpmLocation string
UpstreamPrefix string
SshKeyLocation string
SshUser string
Version int
GitCommitterName string
GitCommitterEmail string
Mode int
ModulePrefix string
ImportBranchPrefix string
BranchPrefix string
Authenticator *ssh.PublicKeys
Importer ImportMode
BlobStorage blob.Storage
NoDupMode bool
ModuleMode bool
}
type ignoredSource struct {
......@@ -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 {
......
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment