From 8e4eefdf42e632da00ef89173eb6130d86755f0a Mon Sep 17 00:00:00 2001 From: Jay Gabriels Date: Thu, 29 Mar 2018 21:07:01 -0700 Subject: [PATCH] add clone --- .gitignore | 1 + cmd/clone.go | 31 +++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 8374200..1d76bd6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ ghorg .env +debug diff --git a/cmd/clone.go b/cmd/clone.go index f7390f2..66f5101 100644 --- a/cmd/clone.go +++ b/cmd/clone.go @@ -2,8 +2,10 @@ package cmd import ( "context" + "errors" "fmt" "os" + "os/exec" "github.com/google/go-github/github" "golang.org/x/oauth2" @@ -20,7 +22,7 @@ func getAllOrgCloneUrls() ([]string, error) { opt := &github.RepositoryListByOrgOptions{ Type: "all", - ListOptions: github.ListOptions{PerPage: 100}, + ListOptions: github.ListOptions{PerPage: 100, Page: 0}, } // get all pages of results @@ -38,15 +40,36 @@ func getAllOrgCloneUrls() ([]string, error) { } cloneUrls := []string{} for _, repo := range allRepos { - fmt.Println(*repo.CloneURL) + cloneUrls = append(cloneUrls, *repo.CloneURL) } return cloneUrls, nil } // CloneAllReposByOrg clones all repos for a given org -func CloneAllReposByOrg() { - getAllOrgCloneUrls() +func CloneAllReposByOrg() error { + cloneTargets, err := getAllOrgCloneUrls() + + if err != nil { + return errors.New("Problem fetching org repo urls to clone") + } + + for _, target := range cloneTargets { + go func(repoUrl string) (string, error) { + fmt.Println("Cloning!!!!!!", repoUrl) + cmd := exec.Command("git", "clone", repoUrl) + err := cmd.Run() + if err != nil { + fmt.Print("ERROR DETECTEDs") + return repoUrl, err + } + + return "Done", nil + }(target) + } + + fmt.Scanln("Press any key when things look done") + return nil } // TODO: Clone via http or ssh flag