Skip to content

Instantly share code, notes, and snippets.

@gedex
Created December 11, 2017 02:46
Show Gist options
  • Save gedex/c3179852eb25b7b426c4b36e979dac24 to your computer and use it in GitHub Desktop.
Save gedex/c3179852eb25b7b426c4b36e979dac24 to your computer and use it in GitHub Desktop.
list of my repos for gembel config.
package main
import (
"context"
"fmt"
"os"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
var (
ghClient *github.Client
ghCtx context.Context
)
func main() {
ghCtx = context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")},
)
tc := oauth2.NewClient(ghCtx, ts)
ghClient = github.NewClient(tc)
repos, err := getRepos()
if err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
for _, repo := range repos {
if repo.GetFork() {
continue
}
fmt.Printf("\"%v\",\n", repo.GetFullName())
}
}
func getRepos() (allRepos []*github.Repository, err error) {
opt := &github.RepositoryListOptions{
Affiliation: "owner",
Type: "owner",
}
opt.PerPage = 100
for {
repos, resp, err := ghClient.Repositories.List(ghCtx, "gedex", opt)
if err != nil {
return allRepos, err
}
allRepos = append(allRepos, repos...)
if resp.NextPage == 0 {
break
}
opt.Page = resp.NextPage
}
return allRepos, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment