GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 2e7cbb...9fc785 )
by Fedir
02:21
created

main.main   C

Complexity

Conditions 10

Size

Total Lines 54
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 11.7759

Importance

Changes 0
Metric Value
cc 10
eloc 44
nop 0
dl 0
loc 54
rs 5.9999
c 0
b 0
f 0
ccs 17
cts 23
cp 0.7391
crap 11.7759

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like main.main often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

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
13
	"github.com/fedir/ghstat/github"
14
)
15
16
func main() {
17 1
	var (
18
		clearHTTPCache         = flag.Bool("cc", false, "Clear HTTP cache")
19
		clearHTTPCacheDryRun   = flag.Bool("ccdr", false, "Clear HTTP cache (dry run)")
20
		debug                  = flag.Bool("d", false, "Debug mode")
21
		resultFileSavePath     = flag.String("f", "", "File path where result CSV file will be saved")
22
		rateLimitCheck         = flag.Bool("l", false, "Rate limit check")
23
		repositoriesKeysManual = flag.String("r", "", "Repositories keys")
24
		tmpFolder              = flag.String("t", "test_data", "Clear HTTP cache (dry run)")
25
		repositoriesKeys       = []string{}
26
	)
27 1
	flag.Parse()
28 1
	if *clearHTTPCache || *clearHTTPCacheDryRun {
29
		clearHTTPCacheFolder(*tmpFolder, *clearHTTPCacheDryRun)
30
		os.Exit(0)
31
	}
32 1
	if *rateLimitCheck {
33
		github.CheckAndPrintRateLimit()
34
		os.Exit(0)
35
	}
36 1
	if *repositoriesKeysManual != "" {
37
		repositoriesKeys = uniqSlice(strings.Split(*repositoriesKeysManual, ","))
38
	} else {
39 1
		repositoriesKeys = uniqSlice([]string{
40
			"astaxie/beego",
41
			"gohugoio/hugo",
42
			"gin-gonic/gin",
43
			"labstack/echo",
44
			"revel/revel",
45
			"gobuffalo/buffalo",
46
			"go-chi/chi",
47
			"kataras/iris",
48
			"zenazn/goji",
49
			"go-macaron/macaron",
50
		})
51
	}
52
53 1
	csvFilePath := ""
54 1
	if *resultFileSavePath != "" {
55
		csvFilePath = *resultFileSavePath
56
	} else {
57 1
		csvFilePath = "result.csv"
58
	}
59 1
	var ghData = []Repository{}
60
61 1
	dataChan := make(chan Repository, len(repositoriesKeys))
62 1
	for _, rKey := range repositoriesKeys {
63 1
		go repositoryData(rKey, *tmpFolder, *debug, dataChan)
64
	}
65 1
	for range repositoriesKeys {
66 1
		ghData = append(ghData, <-dataChan)
67
	}
68 1
	rateAndPrintGreetings(ghData)
69 1
	writeCSVStatistics(ghData, csvFilePath)
70
}
71
72
func uniqSlice(s []string) []string {
73 1
	unique := make(map[string]bool, len(s))
74 1
	us := make([]string, len(unique))
75 1
	for _, elem := range s {
76 1
		if len(elem) != 0 {
77 1
			if !unique[elem] {
78 1
				us = append(us, elem)
79 1
				unique[elem] = true
80
			}
81
		}
82
	}
83 1
	return us
84
}
85