Skip to content

Commit

Permalink
Able to fetch all refs for the git repos
Browse files Browse the repository at this point in the history
fix the wrong release checking
  • Loading branch information
LinuxSuRen committed Nov 6, 2021
1 parent 8edf741 commit e25f1a0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ spec:
periodSeconds: 10
resources:
limits:
cpu: 100m
memory: 60Mi
cpu: 500m
memory: 600Mi
requests:
cpu: 100m
memory: 20Mi
Expand Down
16 changes: 15 additions & 1 deletion controllers/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions controllers/internal_scm/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e25f1a0

Please sign in to comment.