Cleaned up formatting w/ gofmt
(no functional changes) -Skip G.
This commit is contained in:
parent
f339965767
commit
ca54976b8a
|
@ -56,8 +56,8 @@ var (
|
|||
basicPassword string
|
||||
packageVersion string
|
||||
packageRelease string
|
||||
taglessMode bool
|
||||
altLookAside bool
|
||||
taglessMode bool
|
||||
altLookAside bool
|
||||
)
|
||||
|
||||
var root = &cobra.Command{
|
||||
|
@ -97,7 +97,7 @@ func mn(_ *cobra.Command, _ []string) {
|
|||
TaglessMode: taglessMode,
|
||||
AltLookAside: altLookAside,
|
||||
})
|
||||
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -147,9 +147,8 @@ func main() {
|
|||
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")
|
||||
root.Flags().BoolVar(&taglessMode, "taglessmode", false, "Tagless mode: If set, pull the latest commit from a branch, and determine version info from spec file (aka upstream versions aren't tagged)")
|
||||
root.Flags().BoolVar(&altLookAside, "altlookaside", false, "If set, uses the new CentOS Stream lookaside pattern (https://<SITE_PREFIX>/<RPM_NAME>/<FILE_NAME>/<SHA_VERSION>/<SHA_SUM>/<FILE_NAME>)")
|
||||
|
||||
root.Flags().BoolVar(&taglessMode, "taglessmode", false, "Tagless mode: If set, pull the latest commit from a branch, and determine version info from spec file (aka upstream versions aren't tagged)")
|
||||
root.Flags().BoolVar(&altLookAside, "altlookaside", false, "If set, uses the new CentOS Stream lookaside pattern (https://<SITE_PREFIX>/<RPM_NAME>/<FILE_NAME>/<SHA_VERSION>/<SHA_SUM>/<FILE_NAME>)")
|
||||
|
||||
if err := root.Execute(); err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
226
pkg/modes/git.go
226
pkg/modes/git.go
|
@ -125,52 +125,46 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) (*data.ModeData, error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
|
||||
// In case of "tagless mode", we need to get the head ref of the branch instead
|
||||
// This is a kind of alternative implementation of the above tagAdd assignment
|
||||
refAdd := func(tag *object.Tag) error {
|
||||
// In case of "tagless mode", we need to get the head ref of the branch instead
|
||||
// This is a kind of alternative implementation of the above tagAdd assignment
|
||||
refAdd := func(tag *object.Tag) error {
|
||||
if strings.HasPrefix(tag.Name, fmt.Sprintf("refs/heads/%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix)) {
|
||||
pd.Log.Printf("Tagless mode: Identified tagless commit for import: %s\n", tag.Name)
|
||||
refSpec := fmt.Sprintf(tag.Name)
|
||||
|
||||
|
||||
|
||||
// We split the string by "/", the branch name we're looking for to pass to latestTags is always last
|
||||
// (ex: "refs/heads/c9s" ---> we want latestTags[c9s]
|
||||
_tmpRef := strings.Split(refSpec, "/")
|
||||
_branchName := _tmpRef[(len(_tmpRef) - 1)]
|
||||
|
||||
|
||||
// In the case of "strict branch mode" on, the branch name must match *exactly* with our prefix-version-suffix (like "c8" cannot also match "c8-beta")
|
||||
// If it doesn't, bail out without adding this branch
|
||||
if pd.StrictBranchMode == true && _branchName != fmt.Sprintf("%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix) {
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
latestTags[_branchName] = &remoteTarget{
|
||||
remote: refSpec,
|
||||
when: tag.Tagger.When,
|
||||
}
|
||||
|
||||
|
||||
latestTags[_branchName] = &remoteTarget{
|
||||
remote: refSpec,
|
||||
when: tag.Tagger.When,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
tagIter, err := repo.TagObjects()
|
||||
tagIter, err := repo.TagObjects()
|
||||
|
||||
if err != nil {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get tag objects: %v", err)
|
||||
}
|
||||
|
||||
|
||||
// tagless mode means we use "refAdd" (add commit by reference)
|
||||
// normal mode means we can rely on "tagAdd" (the tag should be present for us in the source repo)
|
||||
// tagless mode means we use "refAdd" (add commit by reference)
|
||||
// normal mode means we can rely on "tagAdd" (the tag should be present for us in the source repo)
|
||||
if pd.TaglessMode == true {
|
||||
_ = tagIter.ForEach(refAdd)
|
||||
} else {
|
||||
_ = tagIter.ForEach(tagAdd)
|
||||
}
|
||||
|
||||
|
||||
_ = tagIter.ForEach(refAdd)
|
||||
} else {
|
||||
_ = tagIter.ForEach(tagAdd)
|
||||
}
|
||||
|
||||
listOpts := &git.ListOptions{
|
||||
Auth: pd.Authenticator,
|
||||
}
|
||||
|
@ -196,21 +190,20 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) (*data.ModeData, error) {
|
|||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Call refAdd instead of tagAdd in the case of TaglessMode enabled
|
||||
if pd.TaglessMode == true {
|
||||
_ = refAdd(&object.Tag{
|
||||
Name: string(ref.Name()),
|
||||
Tagger: commit.Committer,
|
||||
})
|
||||
_ = refAdd(&object.Tag{
|
||||
Name: string(ref.Name()),
|
||||
Tagger: commit.Committer,
|
||||
})
|
||||
} else {
|
||||
_ = tagAdd(&object.Tag{
|
||||
Name: strings.TrimPrefix(string(ref.Name()), "refs/tags/"),
|
||||
Tagger: commit.Committer,
|
||||
})
|
||||
_ = tagAdd(&object.Tag{
|
||||
Name: strings.TrimPrefix(string(ref.Name()), "refs/tags/"),
|
||||
Tagger: commit.Committer,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
for _, branch := range latestTags {
|
||||
|
@ -223,7 +216,7 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) (*data.ModeData, error) {
|
|||
for _, branch := range branches {
|
||||
sortedBranches = append(sortedBranches, branch.remote)
|
||||
}
|
||||
|
||||
|
||||
return &data.ModeData{
|
||||
Name: filepath.Base(pd.RpmLocation),
|
||||
Repo: repo,
|
||||
|
@ -234,73 +227,68 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) (*data.ModeData, error) {
|
|||
}
|
||||
|
||||
func (g *GitMode) WriteSource(pd *data.ProcessData, md *data.ModeData) error {
|
||||
|
||||
|
||||
remote, err := md.Repo.Remote("upstream")
|
||||
|
||||
|
||||
if err != nil && pd.TaglessMode == false {
|
||||
return fmt.Errorf("could not get upstream remote: %v", err)
|
||||
return fmt.Errorf("could not get upstream remote: %v", err)
|
||||
}
|
||||
|
||||
|
||||
var refspec config.RefSpec
|
||||
var branchName string
|
||||
|
||||
fmt.Printf("pd.AltLookaside == %v , pd.CdnUrl == %s \n", pd.AltLookAside, pd.CdnUrl)
|
||||
|
||||
// In the case of tagless mode, we already have the transformed repo sitting in the worktree,
|
||||
// and don't need to perform any checkout or fetch operations
|
||||
if pd.TaglessMode == false {
|
||||
if strings.HasPrefix(md.TagBranch, "refs/heads") {
|
||||
refspec = config.RefSpec(fmt.Sprintf("+%s:%s", md.TagBranch, md.TagBranch))
|
||||
branchName = strings.TrimPrefix(md.TagBranch, "refs/heads/")
|
||||
} else {
|
||||
match := misc.GetTagImportRegex(pd).FindStringSubmatch(md.TagBranch)
|
||||
branchName = match[2]
|
||||
refspec = config.RefSpec(fmt.Sprintf("+refs/heads/%s:%s", branchName, md.TagBranch))
|
||||
fmt.Println("Found branchname that does not start w/ refs/heads :: ", branchName)
|
||||
}
|
||||
pd.Log.Printf("checking out upstream refspec %s", refspec)
|
||||
|
||||
// In the case of tagless mode, we already have the transformed repo sitting in the worktree,
|
||||
// and don't need to perform any checkout or fetch operations
|
||||
if pd.TaglessMode == false {
|
||||
if strings.HasPrefix(md.TagBranch, "refs/heads") {
|
||||
refspec = config.RefSpec(fmt.Sprintf("+%s:%s", md.TagBranch, md.TagBranch))
|
||||
branchName = strings.TrimPrefix(md.TagBranch, "refs/heads/")
|
||||
} else {
|
||||
match := misc.GetTagImportRegex(pd).FindStringSubmatch(md.TagBranch)
|
||||
branchName = match[2]
|
||||
refspec = config.RefSpec(fmt.Sprintf("+refs/heads/%s:%s", branchName, md.TagBranch))
|
||||
fmt.Println("Found branchname that does not start w/ refs/heads :: ", branchName)
|
||||
}
|
||||
pd.Log.Printf("checking out upstream refspec %s", refspec)
|
||||
|
||||
|
||||
fetchOpts := &git.FetchOptions{
|
||||
Auth: pd.Authenticator,
|
||||
RemoteName: "upstream",
|
||||
RefSpecs: []config.RefSpec{refspec},
|
||||
Tags: git.AllTags,
|
||||
Force: true,
|
||||
}
|
||||
err = remote.Fetch(fetchOpts)
|
||||
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||
if err == transport.ErrInvalidAuthMethod || err == transport.ErrAuthenticationRequired {
|
||||
fetchOpts.Auth = nil
|
||||
err = remote.Fetch(fetchOpts)
|
||||
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||
return fmt.Errorf("could not fetch upstream: %v", err)
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("could not fetch upstream: %v", err)
|
||||
}
|
||||
}
|
||||
fetchOpts := &git.FetchOptions{
|
||||
Auth: pd.Authenticator,
|
||||
RemoteName: "upstream",
|
||||
RefSpecs: []config.RefSpec{refspec},
|
||||
Tags: git.AllTags,
|
||||
Force: true,
|
||||
}
|
||||
err = remote.Fetch(fetchOpts)
|
||||
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||
if err == transport.ErrInvalidAuthMethod || err == transport.ErrAuthenticationRequired {
|
||||
fetchOpts.Auth = nil
|
||||
err = remote.Fetch(fetchOpts)
|
||||
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||
return fmt.Errorf("could not fetch upstream: %v", err)
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("could not fetch upstream: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
err = md.Worktree.Checkout(&git.CheckoutOptions{
|
||||
Branch: plumbing.ReferenceName(md.TagBranch),
|
||||
Force: true,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not checkout source from git: %v", err)
|
||||
}
|
||||
err = md.Worktree.Checkout(&git.CheckoutOptions{
|
||||
Branch: plumbing.ReferenceName(md.TagBranch),
|
||||
Force: true,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not checkout source from git: %v", err)
|
||||
}
|
||||
|
||||
_, err = md.Worktree.Add(".")
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not add Worktree: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if pd.TaglessMode == true {
|
||||
branchName = fmt.Sprintf("%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix)
|
||||
}
|
||||
|
||||
_, err = md.Worktree.Add(".")
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not add Worktree: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if pd.TaglessMode == true {
|
||||
branchName = fmt.Sprintf("%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix)
|
||||
}
|
||||
|
||||
metadataPath := ""
|
||||
ls, err := md.Worktree.Filesystem.ReadDir(".")
|
||||
if err != nil {
|
||||
|
@ -358,32 +346,32 @@ func (g *GitMode) WriteSource(pd *data.ProcessData, md *data.ModeData) error {
|
|||
body = fromBlobStorage
|
||||
pd.Log.Printf("downloading %s from blob storage", hash)
|
||||
} else {
|
||||
|
||||
url := ""
|
||||
// Alternate lookaside logic: if enabled, we pull from a new URL pattern
|
||||
if pd.AltLookAside == false {
|
||||
url = fmt.Sprintf("%s/%s/%s/%s", pd.CdnUrl, md.Name, branchName, hash)
|
||||
|
||||
url := ""
|
||||
// Alternate lookaside logic: if enabled, we pull from a new URL pattern
|
||||
if pd.AltLookAside == false {
|
||||
url = fmt.Sprintf("%s/%s/%s/%s", pd.CdnUrl, md.Name, branchName, hash)
|
||||
} else {
|
||||
// We first need the hash algorithm based on length of hash:
|
||||
hashType := "sha512"
|
||||
switch len(hash) {
|
||||
case 128:
|
||||
hashType = "sha512"
|
||||
case 64:
|
||||
hashType = "sha256"
|
||||
case 40:
|
||||
hashType = "sha1"
|
||||
case 32:
|
||||
hashType = "md5"
|
||||
}
|
||||
|
||||
// need the name of the file without "SOURCES/":
|
||||
fileName := strings.Split(path, "/")[1]
|
||||
|
||||
// Alt. lookaside url is of the form: <cdn> / <name> / <filename> / <hashtype> / <hash> / <filename>
|
||||
url = fmt.Sprintf("%s/%s/%s/%s/%s/%s", pd.CdnUrl, md.Name, fileName, hashType, hash, fileName)
|
||||
// We first need the hash algorithm based on length of hash:
|
||||
hashType := "sha512"
|
||||
switch len(hash) {
|
||||
case 128:
|
||||
hashType = "sha512"
|
||||
case 64:
|
||||
hashType = "sha256"
|
||||
case 40:
|
||||
hashType = "sha1"
|
||||
case 32:
|
||||
hashType = "md5"
|
||||
}
|
||||
|
||||
// need the name of the file without "SOURCES/":
|
||||
fileName := strings.Split(path, "/")[1]
|
||||
|
||||
// Alt. lookaside url is of the form: <cdn> / <name> / <filename> / <hashtype> / <hash> / <filename>
|
||||
url = fmt.Sprintf("%s/%s/%s/%s/%s/%s", pd.CdnUrl, md.Name, fileName, hashType, hash, fileName)
|
||||
}
|
||||
|
||||
|
||||
pd.Log.Printf("downloading %s", url)
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue