From dc1067cc38e40f65f61e3e23735cec5fb2430c7d Mon Sep 17 00:00:00 2001 From: Mustafa Gezen Date: Sun, 14 Feb 2021 18:25:00 +0100 Subject: [PATCH] Make destination branch prefix and import branch prefix configurable --- cmd/srpmproc/main.go | 56 ++++++++++++++++++++++++-------------------- internal/patch.go | 6 ++--- internal/process.go | 37 +++++++++++++++-------------- internal/srpm.go | 2 +- 4 files changed, 55 insertions(+), 46 deletions(-) diff --git a/cmd/srpmproc/main.go b/cmd/srpmproc/main.go index be940cf..483711e 100644 --- a/cmd/srpmproc/main.go +++ b/cmd/srpmproc/main.go @@ -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") diff --git a/internal/patch.go b/internal/patch.go index 8c74af6..f73e9cd 100644 --- a/internal/patch.go +++ b/internal/patch.go @@ -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 { diff --git a/internal/process.go b/internal/process.go index 30314d9..850206b 100644 --- a/internal/process.go +++ b/internal/process.go @@ -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 { diff --git a/internal/srpm.go b/internal/srpm.go index 1e35565..06cd300 100644 --- a/internal/srpm.go +++ b/internal/srpm.go @@ -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,