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.
Passed
Push — master ( d584ee...909e6e )
by Fedir
02:16
created

files.go (1 issue)

Severity
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
package main
6
7
import (
8
	"encoding/csv"
9
	"fmt"
10
	"log"
11
	"os"
12
	"path/filepath"
13
	"reflect"
14
)
15
16
func clearHTTPCacheFolder(tmpFolderPath string, dryRun bool) error {
17
	d, err := os.Open(tmpFolderPath)
18
	if err != nil {
19
		log.Fatalf("Could not open %s", tmpFolderPath)
20
	}
21
	defer d.Close()
22
	names, err := d.Readdirnames(-1)
23
	if err != nil {
24
		log.Fatalf("Could not read from %s", tmpFolderPath)
25
	}
26
	for _, name := range names {
27
		fp := filepath.Join(tmpFolderPath, name)
28
		if dryRun {
29
			fmt.Printf("Deleted %s\n", fp)
30
		} else {
31
			err = os.RemoveAll(fp)
32
			if err != nil {
33
				log.Fatalf("Could not remove %s", fp)
34
			}
35
			fmt.Printf("Deleted %s\n", fp)
36
		}
37
	}
38
	return nil
39
}
40
41
func writeCSVStatistics(ghData []Repository, csvFilePath string) {
42 1
	var csvData [][]string
43 1
	csvData = append(csvData, headersFromStructTags())
44 1
	for _, r := range ghData {
45 1
		csvData = append(csvData, formatRepositoryDataForCSV(r))
46
	}
47 1
	writeCsv(csvFilePath, csvData)
48
}
49
50
func formatRepositoryDataForCSV(r Repository) []string {
51 1
	ghProjectData := []string{
52
		r.Name,
53
		fmt.Sprintf("%s", r.URL),
54
		fmt.Sprintf("%s", r.Author),
55
		fmt.Sprintf("%s", r.Language),
56
		fmt.Sprintf("%s", r.License),
57
		fmt.Sprintf("%d", r.AuthorsFollowers),
58
		fmt.Sprintf("%d", r.Top10ContributorsFollowers),
59
		fmt.Sprintf("%d/%02d", r.CreatedAt.Year(), r.CreatedAt.Month()),
60
		fmt.Sprintf("%d", r.Age),
61
		fmt.Sprintf("%d", r.TotalCommits),
62
		fmt.Sprintf("%d", r.TotalAdditions),
63
		fmt.Sprintf("%d", r.TotalDeletions),
64
		fmt.Sprintf("%d", r.TotalCodeChanges),
65
		fmt.Sprintf(r.LastCommitDate.Format("2006-01-02 15:04:05")),
0 ignored issues
show
can't check non-constant format in call to Sprintf
Loading history...
66
		fmt.Sprintf("%.4f", r.CommitsByDay),
67
		fmt.Sprintf("%d", r.MediCommitSize),
68
		fmt.Sprintf("%d", r.TotalTags),
69
		fmt.Sprintf("%d", r.Watchers),
70
		fmt.Sprintf("%d", r.Forks),
71
		fmt.Sprintf("%d", r.Contributors),
72
		fmt.Sprintf("%.2f", r.ActiveForkersPercentage),
73
		fmt.Sprintf("%d", r.OpenIssues),
74
		fmt.Sprintf("%d", r.TotalIssues),
75
		fmt.Sprintf("%.4f", r.IssueByDay),
76
		fmt.Sprintf("%.2f", r.ClosedIssuesPercentage),
77
		fmt.Sprintf("%.2f", r.ClosedIssuesPercentage),
78
		fmt.Sprintf("%d", r.PlacementPopularity),
79
		fmt.Sprintf("%d", r.PlacementAge),
80
		fmt.Sprintf("%d", r.PlacementTotalCommits),
81
		fmt.Sprintf("%d", r.PlacementTotalTags),
82
		fmt.Sprintf("%d", r.PlacementTop10ContributorsFollowers),
83
		fmt.Sprintf("%d", r.PlacementClosedIssuesPercentage),
84
		fmt.Sprintf("%d", r.PlacementCommitsByDay),
85
		fmt.Sprintf("%d", r.PlacementActiveForkersColumn),
86
		fmt.Sprintf("%d", r.PlacementOverall),
87
	}
88 1
	return ghProjectData
89
}
90
91
func headersFromStructTags() []string {
92 1
	r := new(Repository)
93 1
	return r.reflectRepositoryHeaders()
94
}
95
96
func (f *Repository) reflectRepositoryHeaders() []string {
97 1
	var headers []string
98 1
	val := reflect.ValueOf(f).Elem()
99 1
	for i := 0; i < val.NumField(); i++ {
100 1
		headers = append(headers, val.Type().Field(i).Tag.Get("header"))
101
	}
102 1
	return headers
103
}
104
105
func writeCsv(csvFilePath string, csvData [][]string) {
106 1
	file, err := os.Create(csvFilePath)
107 1
	if err != nil {
108
		log.Fatal("Cannot create file", err)
109
	}
110 1
	defer file.Close()
111 1
	writer := csv.NewWriter(file)
112 1
	defer writer.Flush()
113 1
	for _, value := range csvData {
114 1
		err := writer.Write(value)
115 1
		if err != nil {
116
			log.Fatal("Cannot write to file", err)
117
		}
118
	}
119
}
120