-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
105 lines (85 loc) · 2.02 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
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
package main
import (
"flag"
"log"
"os"
"sync"
"sync/atomic"
)
var options struct {
csvPath string
htmlPath string
githubtoken string
help bool
}
func init() {
flag.StringVar(&options.csvPath, "csv", "", "the file into which the size data is written in CSV format (or - for stdout)")
flag.StringVar(&options.htmlPath, "html", "", "the file into which the size data is written in HTML format (or - for stdout)")
flag.BoolVar(&options.help, "h", false, "prints this help text")
flag.StringVar(&options.githubtoken, "ghtoken", "", "optional GitHub personal API access token")
flag.Parse()
if options.help {
flag.PrintDefaults()
os.Exit(1)
}
}
func main() {
logger := log.New(os.Stderr, "", 0)
logger.Println("Downloading list of releases...")
releases, err := listReleases(options.githubtoken)
if err != nil {
panic(err)
}
logger.Println("Downloading releases for analysis...")
var releaseWaitGroup sync.WaitGroup
releaseWaitGroup.Add(len(releases))
var progress int32
for _, release := range releases {
go func(release *Release) {
defer releaseWaitGroup.Done()
err := populateReleaseStats(release)
if err != nil {
panic(err)
}
logger.Printf("✔ (%2d/%d) %s\n",
atomic.AddInt32(&progress, 1),
len(releases),
release)
}(release)
}
releaseWaitGroup.Wait()
statsList := make([]*SizeInfo, 0, len(releases))
for _, release := range releases {
statsList = append(statsList, release.Stats)
}
// Write CSV
if options.csvPath != "" {
csvOut := os.Stdout
if options.csvPath != "-" {
csvOut, err = os.Create(options.csvPath)
if err != nil {
panic(err)
}
defer csvOut.Close()
}
err := outputCSV(csvOut, statsList)
if err != nil {
panic(err)
}
}
// Write HTML
if options.htmlPath != "" {
htmlOut := os.Stdout
if options.htmlPath != "-" {
htmlOut, err = os.Create(options.htmlPath)
if err != nil {
panic(err)
}
defer htmlOut.Close()
}
err := outputHTML(htmlOut, statsList)
if err != nil {
panic(err)
}
}
}