-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathghstat.go
89 lines (82 loc) · 2.27 KB
/
ghstat.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
// Copyright 2018 Fedir RYKHTIK. All rights reserved.
// Use of this source code is governed by the GNU GPL 3.0
// license that can be found in the LICENSE file.
// ghstat - statistical multi-criteria decision-making comparator for Github's projects.
package main
import (
"flag"
"os"
"strings"
"sync"
"github.com/fedir/ghstat/github"
)
func main() {
var (
clearHTTPCache = flag.Bool("cc", false, "Clear HTTP cache")
clearHTTPCacheDryRun = flag.Bool("ccdr", false, "Clear HTTP cache (dry run)")
debug = flag.Bool("d", false, "Debug mode")
resultFileSavePath = flag.String("f", "", "File path where result CSV file will be saved")
rateLimitCheck = flag.Bool("l", false, "Rate limit check")
repositoriesKeysManual = flag.String("r", "", "Repositories keys")
tmpFolder = flag.String("t", "test_data", "Temporary folder path")
repositoriesKeys = []string{}
)
flag.Parse()
if *clearHTTPCache || *clearHTTPCacheDryRun {
clearHTTPCacheFolder(*tmpFolder, *clearHTTPCacheDryRun)
os.Exit(0)
}
if *rateLimitCheck {
github.CheckAndPrintRateLimit()
os.Exit(0)
}
if *repositoriesKeysManual != "" {
repositoriesKeys = uniqSlice(strings.Split(*repositoriesKeysManual, ","))
} else {
repositoriesKeys = uniqSlice([]string{
"astaxie/beego",
"gohugoio/hugo",
"gin-gonic/gin",
"labstack/echo",
"revel/revel",
"gobuffalo/buffalo",
"go-chi/chi",
"kataras/iris",
"zenazn/goji",
"go-macaron/macaron",
"go-aah/aah",
})
}
csvFilePath := ""
if *resultFileSavePath != "" {
csvFilePath = *resultFileSavePath
} else {
csvFilePath = "result.csv"
}
var ghData = []Repository{}
var wg sync.WaitGroup
wg.Add(len(repositoriesKeys))
dataChan := make(chan Repository, len(repositoriesKeys))
for _, rKey := range repositoriesKeys {
go repositoryData(rKey, *tmpFolder, *debug, dataChan, &wg)
}
for range repositoriesKeys {
ghData = append(ghData, <-dataChan)
}
wg.Wait()
rateAndPrintGreetings(ghData)
writeCSVStatistics(ghData, csvFilePath)
}
func uniqSlice(s []string) []string {
unique := make(map[string]bool, len(s))
us := make([]string, len(unique))
for _, elem := range s {
if len(elem) != 0 {
if !unique[elem] {
us = append(us, elem)
unique[elem] = true
}
}
}
return us
}