-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi.go
156 lines (111 loc) · 2.84 KB
/
api.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package main
import (
"fmt"
"strings"
)
func countFiles(repoPath string) int {
files := getFiles(repoPath)
return len(files)
}
func countLanguages(repoPath string) map[string]int {
// XXX tie-into getLanguages()
languages := map[string]int{}
files := getFiles(repoPath)
for _, file := range files {
ext := strings.Split(file, ".")
if _, ok := languages[ext[len(ext)-1]]; ok {
languages[ext[len(ext)-1]] = languages[ext[len(ext)-1]] + 1
} else {
languages[ext[len(ext)-1]] = 1
}
}
return languages
}
func determineLanguage(templates map[string]*Template, file string, flagBools []bool) (string, *Template) {
if !flagBools[0] && flagBools[2] {
fmt.Println("checking language type for file", file)
}
parts := strings.Split(file, ".")
ext := "." + parts[len(parts)-1]
language := "unknown"
for _, t := range templates {
e := t.Extensions
//fmt.Println("checking provided extension", ext, "against template extension:", e)
if ext == e {
if !flagBools[0] && flagBools[2] {
fmt.Println("found match...")
}
language = t.Name
return language, t
}
}
return language, nil
}
func countLines(file string) int {
data := getFileContents(file)
lines := strings.Split(string(data), "\n")
return len(lines)
}
func countLinesPerLanguage(repoPath string) map[string]int {
counts := map[string]int{}
files := getFiles(repoPath)
for _, file := range files {
ext := strings.Split(file, ".")
if _, ok := counts[ext[len(ext)-1]]; ok {
counts[ext[len(ext)-1]] = counts[ext[len(ext)-1]] + countLines(file)
} else {
counts[ext[len(ext)-1]] = countLines(file)
}
}
return counts
}
func countCommits(repoPath string) int {
commits, _ := getCommits(repoPath)
return len(commits)
}
func countAuthors(repoPath string) int {
authors := countAuthorCommits(repoPath)
return len(authors)
}
func countAuthorsByCommits(repoPath string, commit string) int {
counts := map[string]int{}
commits, commitMap := getCommits(repoPath)
index := -1
for i, c := range commits {
if strings.EqualFold(commit, c) {
index = i
}
}
if index != -1 {
commits = commits[index:]
}
for k, commit := range commitMap {
for _, c := range commits {
if c == k {
if _, ok := counts[commit["author"]]; ok {
counts[commit["author"]] = counts[commit["author"]] + 1
} else {
counts[commit["author"]] = 1
}
}
}
}
return len(counts)
}
func countAuthorCommits(repoPath string) map[string]int {
counts := map[string]int{}
_, commits := getCommits(repoPath)
for _, commit := range commits {
if _, ok := counts[commit["author"]]; ok {
counts[commit["author"]] = counts[commit["author"]] + 1
} else {
counts[commit["author"]] = 1
}
}
return counts
}
func countAuthorLines(repoPath string) map[string]int {
// XXX stub, requires reading diffs
counts := map[string]int{}
return counts
}