diff options
| author | Christine Dodrill <me@christine.website> | 2017-11-01 12:58:52 -0700 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2017-11-01 12:59:12 -0700 |
| commit | d0ebe3970f361daa31a135f1e0c7304eb1442f61 (patch) | |
| tree | f6af12c146a5278283471c734b590d457f52c5dd | |
| parent | 5cd9bb891ae236e0c5e99364b365c9cd8bf1ba57 (diff) | |
| download | x-d0ebe3970f361daa31a135f1e0c7304eb1442f61.tar.xz x-d0ebe3970f361daa31a135f1e0c7304eb1442f61.zip | |
priorworkgen: new tool for generating list of prior work from github repos
| -rw-r--r-- | tools/priorworkgen/.gitignore | 1 | ||||
| -rw-r--r-- | tools/priorworkgen/main.go | 98 |
2 files changed, 99 insertions, 0 deletions
diff --git a/tools/priorworkgen/.gitignore b/tools/priorworkgen/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/tools/priorworkgen/.gitignore @@ -0,0 +1 @@ +.env diff --git a/tools/priorworkgen/main.go b/tools/priorworkgen/main.go new file mode 100644 index 0000000..d4f1291 --- /dev/null +++ b/tools/priorworkgen/main.go @@ -0,0 +1,98 @@ +package main + +import ( + "context" + "fmt" + "log" + "os" + + "github.com/google/go-github/github" + _ "github.com/joho/godotenv/autoload" + "golang.org/x/oauth2" +) + +func main() { + ctx := context.Background() + ts := oauth2.StaticTokenSource( + &oauth2.Token{AccessToken: os.Getenv("GH_TOKEN")}, + ) + tc := oauth2.NewClient(ctx, ts) + + client := github.NewClient(tc) + + var repos []*github.Repository + var np int + + for { + // list all repositories for the authenticated user + + options := &github.RepositoryListOptions{ + ListOptions: github.ListOptions{Page: np}, + Type: "owner", + } + mrepos, resp, err := client.Repositories.List(ctx, "", options) + if err != nil { + log.Printf("can't get next page: %v", err) + break + } + np = resp.NextPage + + repos = append(repos, mrepos...) + + log.Printf("got info on %d repos", len(repos)) + + if len(repos) > 150 { + break + } + } + + for _, repo := range repos { + if repo.GetFork() { + continue + } + if repo.GetPrivate() { + continue + } + + name := repo.GetName() + desc := repo.GetDescription() + refn := repo.GetGitURL() + creat := repo.GetCreatedAt() + lastm := repo.GetUpdatedAt() + + if name == "ircbot" { + continue + } + + const blurb = `Name: ${NAME} +Description: ${DESC} +Reference Number: ${REFN} +Date of creation: ${CREAT} +Date of last modification: ${LASTM} +Other owners: none +` + + mapping := func(inp string) string { + switch inp { + case "NAME": + return name + case "DESC": + if desc == "" { + panic("no description for " + refn) + } + + return desc + case "REFN": + return refn + case "CREAT": + return creat.String() + case "LASTM": + return lastm.String() + } + + return "<unknown input " + inp + ">" + } + + fmt.Println(os.Expand(blurb, mapping)) + } +} |
