| Conditions | 11 |
| Total Lines | 103 |
| Code Lines | 92 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 21 |
| CRAP Score | 13.5412 |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
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. |
||
| 24 | func main() { |
||
| 25 | 1 | var ( |
|
| 26 | clearHTTPCache = flag.Bool("cc", false, "Clear HTTP cache") |
||
| 27 | clearHTTPCacheDryRun = flag.Bool("ccdr", false, "Clear HTTP cache (dry run)") |
||
| 28 | debug = flag.Bool("d", false, "Debug mode") |
||
| 29 | resultFileSavePath = flag.String("f", "", "File path where result CSV file will be saved") |
||
| 30 | rateLimitCheck = flag.Bool("l", false, "Rate limit check") |
||
| 31 | repositoriesKeysManual = flag.String("r", "", "Repositories keys") |
||
| 32 | tmpFolder = flag.String("t", "test_data", "Clear HTTP cache (dry run)") |
||
| 33 | repositoriesKeys = []string{} |
||
| 34 | ) |
||
| 35 | 1 | flag.Parse() |
|
| 36 | 1 | if *clearHTTPCache || *clearHTTPCacheDryRun { |
|
| 37 | clearHTTPCacheFolder(*tmpFolder, *clearHTTPCacheDryRun) |
||
| 38 | os.Exit(0) |
||
| 39 | } |
||
| 40 | 1 | if *rateLimitCheck { |
|
| 41 | checkAndPrintRateLimit() |
||
| 42 | os.Exit(0) |
||
| 43 | } |
||
| 44 | 1 | if *rateLimitCheck { |
|
| 45 | checkAndPrintRateLimit() |
||
| 46 | os.Exit(0) |
||
| 47 | } |
||
| 48 | 1 | if *repositoriesKeysManual != "" { |
|
| 49 | repositoriesKeys = strings.Split(*repositoriesKeysManual, ",") |
||
| 50 | } else { |
||
| 51 | 1 | repositoriesKeys = []string{ |
|
| 52 | "astaxie/beego", |
||
| 53 | "gohugoio/hugo", |
||
| 54 | "gin-gonic/gin", |
||
| 55 | "labstack/echo", |
||
| 56 | "revel/revel", |
||
| 57 | "gobuffalo/buffalo", |
||
| 58 | "go-chi/chi", |
||
| 59 | "kataras/iris", |
||
| 60 | "zenazn/goji", |
||
| 61 | } |
||
| 62 | } |
||
| 63 | 1 | csvFilePath := "" |
|
| 64 | 1 | if *resultFileSavePath != "" { |
|
| 65 | csvFilePath = *resultFileSavePath |
||
| 66 | } else { |
||
| 67 | 1 | csvFilePath = "result.csv" |
|
| 68 | } |
||
| 69 | 1 | var ghData = [][]string{} |
|
| 70 | 1 | headers := []string{ |
|
| 71 | "Name", |
||
| 72 | "URL", |
||
| 73 | "Author", |
||
| 74 | "License", |
||
| 75 | "Author's followers", |
||
| 76 | "Top 10 contributors followers", |
||
| 77 | "Created at", |
||
| 78 | "Age in days", |
||
| 79 | "Total commits", |
||
| 80 | "Total additions", |
||
| 81 | "Total deletions", |
||
| 82 | "Total code changes", |
||
| 83 | "Last commit date", |
||
| 84 | "Commits/day", |
||
| 85 | "Medium commit size", |
||
| 86 | "Stargazers", |
||
| 87 | "Forks", |
||
| 88 | "Contributors", |
||
| 89 | "Active forkers, %", |
||
| 90 | "Open issues", |
||
| 91 | "Total issues", |
||
| 92 | "Issue/day", |
||
| 93 | "Closed issues, %", |
||
| 94 | "Place", |
||
| 95 | } |
||
| 96 | 1 | ghDataColumnIndexes := map[string]int{ |
|
| 97 | "nameColumn": 0, |
||
| 98 | "urlColumn": 1, |
||
| 99 | "authorColumn": 2, |
||
| 100 | "licenseColumn": 3, |
||
| 101 | "authorsFollowersColumn": 4, |
||
| 102 | "top10ContributorsFollowersColumn": 5, |
||
| 103 | "totalAdditionsColumn": 9, |
||
| 104 | "ageColumn": 7, |
||
| 105 | "totalCommitsColumn": 8, |
||
| 106 | "totalDeletionsColumn": 10, |
||
| 107 | "totalCodeChangesColumn": 11, |
||
| 108 | "lastCommitDateColumn": 12, |
||
| 109 | "commitsByDayColumn": 13, |
||
| 110 | "mediCommitSizeColumn": 14, |
||
| 111 | "stargazersColumn": 15, |
||
| 112 | "activeForkersColumn": 18, |
||
| 113 | "issuesByDayColumn": 21, |
||
| 114 | "closedIssuesPercentageColumn": 22, |
||
| 115 | "totalPointsColumnIndex": 23, |
||
| 116 | } |
||
| 117 | 1 | dataChan := make(chan []string, len(repositoriesKeys)) |
|
| 118 | 1 | for _, rKey := range repositoriesKeys { |
|
| 119 | 1 | go fillRepositoryStatistics(rKey, *tmpFolder, *debug, dataChan) |
|
| 120 | } |
||
| 121 | 1 | for range repositoriesKeys { |
|
| 122 | 1 | ghData = append(ghData, <-dataChan) |
|
| 123 | } |
||
| 124 | 1 | greetings := rateGhData(ghData, ghDataColumnIndexes) |
|
| 125 | 1 | fmt.Println(greetings) |
|
| 126 | 1 | writeCsv(csvFilePath, headers, ghData) |
|
| 127 | } |
||
| 266 |