1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
// Command priorworkgen generates the list of prior work (read: GitHub repositories) for contractual stuff.
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"github.com/google/go-github/github"
_ "github.com/joho/godotenv/autoload"
"golang.org/x/oauth2"
"within.website/x/internal"
)
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))
}
}
|