|
1
|
|
|
// Copyright 2018 Fedir RYKHTIK. All rights reserved. |
|
2
|
|
|
// Use of this source code is governed by the GNU GPL 3.0 |
|
3
|
|
|
// license that can be found in the LICENSE file. |
|
4
|
|
|
|
|
5
|
|
|
// ghstat - statistical multi-criteria decision-making comparator for Github's projects. |
|
6
|
|
|
package main |
|
7
|
|
|
|
|
8
|
|
|
import ( |
|
9
|
|
|
"flag" |
|
10
|
|
|
"os" |
|
11
|
|
|
"strings" |
|
12
|
|
|
"sync" |
|
13
|
|
|
|
|
14
|
|
|
"github.com/fedir/ghstat/github" |
|
15
|
|
|
) |
|
16
|
|
|
|
|
17
|
|
|
func main() { |
|
18
|
1 |
|
var ( |
|
19
|
|
|
clearHTTPCache = flag.Bool("cc", false, "Clear HTTP cache") |
|
20
|
|
|
clearHTTPCacheDryRun = flag.Bool("ccdr", false, "Clear HTTP cache (dry run)") |
|
21
|
|
|
debug = flag.Bool("d", false, "Debug mode") |
|
22
|
|
|
resultFileSavePath = flag.String("f", "", "File path where result CSV file will be saved") |
|
23
|
|
|
rateLimitCheck = flag.Bool("l", false, "Rate limit check") |
|
24
|
|
|
repositoriesKeysManual = flag.String("r", "", "Repositories keys") |
|
25
|
|
|
tmpFolder = flag.String("t", "test_data", "Temporary folder path") |
|
26
|
|
|
repositoriesKeys = []string{} |
|
27
|
|
|
) |
|
28
|
1 |
|
flag.Parse() |
|
29
|
1 |
|
if *clearHTTPCache || *clearHTTPCacheDryRun { |
|
30
|
|
|
clearHTTPCacheFolder(*tmpFolder, *clearHTTPCacheDryRun) |
|
31
|
|
|
os.Exit(0) |
|
32
|
|
|
} |
|
33
|
1 |
|
if *rateLimitCheck { |
|
34
|
|
|
github.CheckAndPrintRateLimit() |
|
35
|
|
|
os.Exit(0) |
|
36
|
|
|
} |
|
37
|
1 |
|
if *repositoriesKeysManual != "" { |
|
38
|
|
|
repositoriesKeys = uniqSlice(strings.Split(*repositoriesKeysManual, ",")) |
|
39
|
|
|
} else { |
|
40
|
1 |
|
repositoriesKeys = uniqSlice([]string{ |
|
41
|
|
|
"astaxie/beego", |
|
42
|
|
|
"gohugoio/hugo", |
|
43
|
|
|
"gin-gonic/gin", |
|
44
|
|
|
"labstack/echo", |
|
45
|
|
|
"revel/revel", |
|
46
|
|
|
"gobuffalo/buffalo", |
|
47
|
|
|
"go-chi/chi", |
|
48
|
|
|
"kataras/iris", |
|
49
|
|
|
"zenazn/goji", |
|
50
|
|
|
"go-macaron/macaron", |
|
51
|
|
|
"go-aah/aah", |
|
52
|
|
|
}) |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
1 |
|
csvFilePath := "" |
|
56
|
1 |
|
if *resultFileSavePath != "" { |
|
57
|
|
|
csvFilePath = *resultFileSavePath |
|
58
|
|
|
} else { |
|
59
|
1 |
|
csvFilePath = "result.csv" |
|
60
|
|
|
} |
|
61
|
1 |
|
var ghData = []Repository{} |
|
62
|
1 |
|
var wg sync.WaitGroup |
|
63
|
1 |
|
wg.Add(len(repositoriesKeys)) |
|
64
|
|
|
|
|
65
|
1 |
|
dataChan := make(chan Repository, len(repositoriesKeys)) |
|
66
|
1 |
|
for _, rKey := range repositoriesKeys { |
|
67
|
1 |
|
go repositoryData(rKey, *tmpFolder, *debug, dataChan, &wg) |
|
68
|
|
|
} |
|
69
|
1 |
|
for range repositoriesKeys { |
|
70
|
1 |
|
ghData = append(ghData, <-dataChan) |
|
71
|
|
|
} |
|
72
|
1 |
|
wg.Wait() |
|
73
|
1 |
|
rateAndPrintGreetings(ghData) |
|
74
|
1 |
|
writeCSVStatistics(ghData, csvFilePath) |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
func uniqSlice(s []string) []string { |
|
78
|
1 |
|
unique := make(map[string]bool, len(s)) |
|
79
|
1 |
|
us := make([]string, len(unique)) |
|
80
|
1 |
|
for _, elem := range s { |
|
81
|
1 |
|
if len(elem) != 0 { |
|
82
|
1 |
|
if !unique[elem] { |
|
83
|
1 |
|
us = append(us, elem) |
|
84
|
1 |
|
unique[elem] = true |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
1 |
|
return us |
|
89
|
|
|
} |
|
90
|
|
|
|