From e25f1a0108a6cf07d9de0a2fa4c17ee573de3f6c Mon Sep 17 00:00:00 2001 From: rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Sat, 6 Nov 2021 23:44:33 +0800 Subject: [PATCH] Able to fetch all refs for the git repos fix the wrong release checking --- config/manager/manager.yaml | 4 ++-- controllers/git.go | 16 +++++++++++++++- controllers/internal_scm/factory.go | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 9202e48..e07ebc7 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -43,8 +43,8 @@ spec: periodSeconds: 10 resources: limits: - cpu: 100m - memory: 60Mi + cpu: 500m + memory: 600Mi requests: cpu: 100m memory: 20Mi diff --git a/controllers/git.go b/controllers/git.go index 91526b7..6f17783 100644 --- a/controllers/git.go +++ b/controllers/git.go @@ -137,13 +137,27 @@ func clone(gitRepo, branch string, auth transport.AuthMethod, cacheDir string) ( if repo, err = git.PlainOpen(dir); err == nil { var wd *git.Worktree + if err = repo.Fetch(&git.FetchOptions{ + RefSpecs: []config.RefSpec{ + "+refs/heads/*:refs/remotes/origin/*", + }, + Progress: os.Stdout, + Force: true, // in case of the force pushing + Auth: auth, + }); err != nil && err != git.NoErrAlreadyUpToDate { + err = fmt.Errorf("unable to fetch %s, error: %v", gitRepo, err) + return + } else { + err = nil + } + if wd, err = repo.Worktree(); err == nil { if err = wd.Checkout(&git.CheckoutOptions{ Branch: plumbing.NewBranchReferenceName(branch), Create: false, Force: true, }); err != nil { - err = fmt.Errorf("unable to checkout git branch: %s", branch) + err = fmt.Errorf("unable to checkout git branch: %s, error: %v", branch, err) return } diff --git a/controllers/internal_scm/factory.go b/controllers/internal_scm/factory.go index 21ecd9d..a0c83ae 100644 --- a/controllers/internal_scm/factory.go +++ b/controllers/internal_scm/factory.go @@ -36,6 +36,8 @@ func findRelease(client *scm.Client, repo, version string) (release *scm.Release var err error cxt := context.TODO() if release, _, err = client.Releases.FindByTag(cxt, repo, version); err == scm.ErrNotFound { + release = nil + var list []*scm.Release if list, _, err = client.Releases.List(cxt, repo, scm.ReleaseListOptions{Page: 1, Size: 200}); err != nil { release = nil