Skip to content

Commit

Permalink
[#116] (fork,create) retry API calls for known race cases (fork->clon…
Browse files Browse the repository at this point in the history
…e,create->clone)
  • Loading branch information
zaquestion committed Apr 11, 2018
1 parent 1b944c0 commit c877f5d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
50 changes: 43 additions & 7 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion cmd/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package cmd
import (
"log"
"strings"
"time"

retry "github.com/avast/retry-go"
"github.com/spf13/cobra"
"github.com/zaquestion/lab/internal/git"
"github.com/zaquestion/lab/internal/gitlab"
Expand All @@ -29,7 +31,11 @@ var cloneCmd = &cobra.Command{
log.Fatal(err)
}
path := project.SSHURLToRepo
err = git.New(append([]string{"clone", path}, args[1:]...)...).Run()
// #116 retry on the cases where we found a project but clone
// failed over ssh
err = retry.Do(func() error {
return git.New(append([]string{"clone", path}, args[1:]...)...).Run()
}, retry.Attempts(3), retry.Delay(time.Second), retry.Units(time.Nanosecond))
if err != nil {
log.Fatal(err)
}
Expand Down
12 changes: 9 additions & 3 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"os/exec"
"path/filepath"
"strings"
"time"

retry "github.com/avast/retry-go"
"github.com/pkg/errors"
"github.com/tcnksm/go-gitconfig"
)
Expand Down Expand Up @@ -183,9 +185,13 @@ func RemoteAdd(name, url, dir string) error {
return err
}
fmt.Println("Updating", name)
cmd = New("fetch", name)
cmd.Dir = dir
if err := cmd.Run(); err != nil {

err := retry.Do(func() error {
cmd = New("fetch", name)
cmd.Dir = dir
return cmd.Run()
}, retry.Attempts(3), retry.Delay(time.Second), retry.Units(time.Nanosecond))
if err != nil {
return err
}
fmt.Println("new remote:", name)
Expand Down

0 comments on commit c877f5d

Please sign in to comment.