aboutsummaryrefslogtreecommitdiff
path: root/cmd/priorworkgen
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2019-04-01 10:05:03 -0700
committerChristine Dodrill <me@christine.website>2019-04-01 10:05:28 -0700
commitf06f021f402270951f849dde7bee3f3340b8a1d5 (patch)
treebaee337aab524f162b349d254d21c2d8f2716d44 /cmd/priorworkgen
parentba91a17859267201b1d1f0e71da465b1464d940f (diff)
downloadx-f06f021f402270951f849dde7bee3f3340b8a1d5.tar.xz
x-f06f021f402270951f849dde7bee3f3340b8a1d5.zip
reorg
Diffstat (limited to 'cmd/priorworkgen')
-rw-r--r--cmd/priorworkgen/.gitignore1
-rw-r--r--cmd/priorworkgen/main.go105
2 files changed, 106 insertions, 0 deletions
diff --git a/cmd/priorworkgen/.gitignore b/cmd/priorworkgen/.gitignore
new file mode 100644
index 0000000..4c49bd7
--- /dev/null
+++ b/cmd/priorworkgen/.gitignore
@@ -0,0 +1 @@
+.env
diff --git a/cmd/priorworkgen/main.go b/cmd/priorworkgen/main.go
new file mode 100644
index 0000000..f484c27
--- /dev/null
+++ b/cmd/priorworkgen/main.go
@@ -0,0 +1,105 @@
+package main
+
+import (
+ "context"
+ "flag"
+ "fmt"
+ "log"
+ "os"
+
+ "github.com/Xe/x/internal"
+ "github.com/google/go-github/github"
+ _ "github.com/joho/godotenv/autoload"
+ "golang.org/x/oauth2"
+)
+
+var (
+ ghToken = flag.String("gh-token", "", "github personal access token")
+)
+
+func main() {
+ internal.HandleStartup()
+ ctx := context.Background()
+ ts := oauth2.StaticTokenSource(
+ &oauth2.Token{AccessToken: *ghToken},
+ )
+ 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))
+ }
+}