retry fetching patch repo if the error is invalid auth method

This commit is contained in:
Mustafa Gezen 2022-04-24 15:53:36 +02:00
parent bc9d81bd8e
commit dd7fd31ebb
2 changed files with 41 additions and 27 deletions

View File

@ -12,8 +12,11 @@ Available Commands:
help Help about any command
Flags:
--allow-stream-branches Allow import from stream branches
--basic-password string Basic auth password
--basic-username string Basic auth username
--branch-prefix string Branch prefix (replaces import-branch-prefix) (default "r")
--branch-suffix string Branch suffix to use for imported branches
--cdn-url string CDN URL to download blobs from (default "https://git.centos.org/sources")
--git-committer-email string Email of committer (default "rockyautomation@rockylinux.org")
--git-committer-name string Name of committer (default "rockyautomation")
-h, --help help for srpmproc
@ -31,9 +34,9 @@ Flags:
--ssh-key-location string Location of the SSH key to use to authenticate against upstream
--ssh-user string SSH User (default "git")
--storage-addr string Bucket to use as blob storage
--strict-branch-mode If enabled, only branches with the calculated name are imported and not prefix only
--tmpfs-mode string If set, packages are imported to path and patched but not pushed
--upstream-prefix string Upstream git repository prefix
--upstream-prefix-https string Web version of upstream prefix. Required if module-mode
--version int Upstream version
Use "srpmproc [command] --help" for more information about a command.

View File

@ -23,6 +23,7 @@ package srpmproc
import (
"encoding/json"
"fmt"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/rocky-linux/srpmproc/pkg/misc"
"io/ioutil"
"log"
@ -141,37 +142,47 @@ func executePatchesRpm(pd *data.ProcessData, md *data.ModeData) error {
pd.Log.Printf("set reference to ref: %s", refName)
if err != nil {
// no patches active
log.Println("info: patch repo not found")
return nil
} else {
err = w.Checkout(&git.CheckoutOptions{
Branch: plumbing.NewRemoteReferenceName("origin", "main"),
Force: true,
})
// common patches found, apply them
if err == nil {
err := applyPatches(pd, md, w, md.Worktree)
if err == transport.ErrInvalidAuthMethod || err == transport.ErrAuthenticationRequired {
fetchOptions.Auth = nil
err = repo.Fetch(fetchOptions)
if err != nil {
return err
// no patches active
log.Println("info: patch repo not found")
return nil
}
} else {
log.Println("info: no common patches found")
// no patches active
log.Println("info: patch repo not found")
return nil
}
}
err = w.Checkout(&git.CheckoutOptions{
Branch: plumbing.NewRemoteReferenceName("origin", md.PushBranch),
Force: true,
})
// branch specific patches found, apply them
if err == nil {
err := applyPatches(pd, md, w, md.Worktree)
if err != nil {
return err
}
} else {
log.Println("info: no branch specific patches found")
err = w.Checkout(&git.CheckoutOptions{
Branch: plumbing.NewRemoteReferenceName("origin", "main"),
Force: true,
})
// common patches found, apply them
if err == nil {
err := applyPatches(pd, md, w, md.Worktree)
if err != nil {
return err
}
} else {
log.Println("info: no common patches found")
}
err = w.Checkout(&git.CheckoutOptions{
Branch: plumbing.NewRemoteReferenceName("origin", md.PushBranch),
Force: true,
})
// branch specific patches found, apply them
if err == nil {
err := applyPatches(pd, md, w, md.Worktree)
if err != nil {
return err
}
} else {
log.Println("info: no branch specific patches found")
}
return nil