-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
52 lines (39 loc) · 1.01 KB
/
main.go
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
package main
import (
"fmt"
"log"
"os"
"golang.org/x/net/context"
"golang.org/x/oauth2"
"github.com/google/go-github/github"
)
func main() {
options := &github.ActivityListStarredOptions{Sort: "created"}
if len(os.Args) <= 1 {
log.Fatalf("Usage: %s <GitHub username>", os.Args[0])
}
user := os.Args[1]
client := newClient()
for page := 1; ; page++ {
options.Page = page
starredRepos, res, err := client.Activity.ListStarred(context.Background(), user, options)
if err != nil {
log.Fatalf("ListStarred: %s", err)
}
log.Printf("page: %d/%d", page, res.LastPage)
for _, starredRepo := range starredRepos {
fmt.Println(*starredRepo.Repository.HTMLURL)
}
if page >= res.LastPage {
break
}
}
}
func newClient() *github.Client {
githubToken := os.Getenv("GITHUB_TOKEN")
if githubToken != "" {
source := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: githubToken})
return github.NewClient(oauth2.NewClient(context.Background(), source))
}
return github.NewClient(nil)
}