Add support for version/release based fetching

This commit is contained in:
Mustafa Gezen 2022-05-05 04:25:07 +02:00
parent f7017a9eac
commit 8199a79889
4 changed files with 28 additions and 1 deletions

View File

@ -54,6 +54,8 @@ var (
strictBranchMode bool
basicUsername string
basicPassword string
packageVersion string
packageRelease string
)
var root = &cobra.Command{
@ -88,6 +90,8 @@ func mn(_ *cobra.Command, _ []string) {
CdnUrl: cdnUrl,
HttpUsername: basicUsername,
HttpPassword: basicPassword,
PackageVersion: packageVersion,
PackageRelease: packageRelease,
})
if err != nil {
log.Fatal(err)
@ -136,6 +140,8 @@ func main() {
root.Flags().BoolVar(&strictBranchMode, "strict-branch-mode", false, "If enabled, only branches with the calculated name are imported and not prefix only")
root.Flags().StringVar(&basicUsername, "basic-username", "", "Basic auth username")
root.Flags().StringVar(&basicPassword, "basic-password", "", "Basic auth password")
root.Flags().StringVar(&packageVersion, "package-version", "", "Package version to fetch")
root.Flags().StringVar(&packageRelease, "package-release", "", "Package release to fetch")
if err := root.Execute(); err != nil {
log.Fatal(err)

View File

@ -55,4 +55,6 @@ type ProcessData struct {
FsCreator FsCreatorFunc
CdnUrl string
Log *log.Logger
PackageVersion string
PackageRelease string
}

View File

@ -3,6 +3,7 @@ package misc
import (
"fmt"
"github.com/rocky-linux/srpmproc/pkg/data"
"path/filepath"
"regexp"
)
@ -13,7 +14,20 @@ func GetTagImportRegex(pd *data.ProcessData) *regexp.Regexp {
} else {
branchRegex += "(?:-stream-.+|)"
}
regex := fmt.Sprintf("refs/tags/(imports/(%s)/(.*))", branchRegex)
initialVerRegex := filepath.Base(pd.RpmLocation) + "-"
if pd.PackageVersion != "" {
initialVerRegex += pd.PackageVersion + "-"
} else {
initialVerRegex += ".+-"
}
if pd.PackageRelease != "" {
initialVerRegex += pd.PackageRelease
} else {
initialVerRegex += ".+"
}
regex := fmt.Sprintf("refs/tags/(imports/(%s)/(%s))", branchRegex, initialVerRegex)
return regexp.MustCompile(regex)
}

View File

@ -93,6 +93,9 @@ type ProcessDataRequest struct {
SingleTag string
CdnUrl string
LogWriter io.Writer
PackageVersion string
PackageRelease string
}
func gitlabify(str string) string {
@ -258,6 +261,8 @@ func NewProcessData(req *ProcessDataRequest) (*data.ProcessData, error) {
FsCreator: fsCreator,
CdnUrl: req.CdnUrl,
Log: logger,
PackageVersion: req.PackageVersion,
PackageRelease: req.PackageRelease,
}, nil
}