-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
50 lines (44 loc) · 1.79 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
package main
import (
"flag"
"fmt"
"os"
"github.com/google/go-github/v61/github"
)
type ArgOpts struct {
DAYS int
TOPXACTIVITIES int
GITHUB_ORGANIZATION string
GITHUB_USER string
GITHUB_PERSONAL_ACCESS_TOKEN string
}
func main() {
// Parse arguments
opts := ArgOpts{}
flag.IntVar(&opts.DAYS, "days", 7, "How many days back to analyze")
flag.IntVar(&opts.TOPXACTIVITIES, "top", 5, "How many top PRs/Issues to show")
flag.StringVar(&opts.GITHUB_ORGANIZATION, "org", "", "GitHub organization to analyze")
flag.StringVar(&opts.GITHUB_USER, "usr", "", "GitHub user to analyze")
flag.StringVar(&opts.GITHUB_PERSONAL_ACCESS_TOKEN, "token", "", "Optional. Passing a GitHub Personal Access Token allows you to view private repositories and make more API requests per hour. You can also set this token as an environment variable GITHUB_PERSONAL_ACCESS_TOKEN.")
flag.Parse()
// Prioritize any Github PAT which was passed as a flag, then check env vars
var client *github.Client
if opts.GITHUB_PERSONAL_ACCESS_TOKEN != "" {
client = github.NewClient(nil).WithAuthToken(opts.GITHUB_PERSONAL_ACCESS_TOKEN)
} else if os.Getenv("GITHUB_PERSONAL_ACCESS_TOKEN") != "" {
client = github.NewClient(nil).WithAuthToken(os.Getenv("GITHUB_PERSONAL_ACCESS_TOKEN"))
} else {
client = github.NewClient(nil)
}
if opts.GITHUB_ORGANIZATION == "" && opts.GITHUB_USER == "" {
fmt.Println("Either -org or -usr must be set. Use -h to view all options.")
return
} else if opts.GITHUB_ORGANIZATION != "" && opts.GITHUB_USER != "" {
fmt.Println("Cannot analyze both -org and -user. Only set one.")
return
} else if opts.GITHUB_ORGANIZATION != "" {
AnalyzeOrgActivity(client, opts)
} else if opts.GITHUB_USER != "" {
AnalyzeUserActivity(client, opts)
}
}