Skip to content

Instantly share code, notes, and snippets.

@Kubuxu
Created September 22, 2016 16:42
Show Gist options
  • Save Kubuxu/2e9c327348a631ac579f7aacde4b14db to your computer and use it in GitHub Desktop.
Save Kubuxu/2e9c327348a631ac579f7aacde4b14db to your computer and use it in GitHub Desktop.
Clone all Github repos in an org
package main
import (
"fmt"
"os"
"os/exec"
"strings"
"github.com/google/go-github/github"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("You have to pass an organization name")
}
client := github.NewClient(nil)
opt := &github.RepositoryListByOrgOptions{
ListOptions: github.ListOptions{PerPage: 10},
}
// get all pages of results
var allRepos []*github.Repository
for {
repos, resp, _ := client.Repositories.ListByOrg(os.Args[1], opt)
allRepos = append(allRepos, repos...)
if resp.NextPage == 0 {
break
}
opt.ListOptions.Page = resp.NextPage
}
for _, repo := range allRepos {
if len(os.Args) > 2 {
if !strings.HasPrefix(*repo.Name, os.Args[2]) {
continue
}
}
exec.Command("git", "clone", "--recursive", *repo.SSHURL).Run()
exec.Command("mr", "register", *repo.Name).Run()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment