-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighlight.go
78 lines (72 loc) · 1.35 KB
/
highlight.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
package main
import (
"fmt"
"io"
)
func Write(w io.Writer, s Stats, top int, includeReviews bool) error {
if top == 0 {
top = 1000
}
data := []statHighlight{
{
stats: Sort(s, ExtractCommits),
trophy: "Commits",
kind: "commits",
}, {
stats: Sort(s, ExtractAdditions),
trophy: "Lines Added",
kind: "lines added",
}, {
stats: Sort(s, ExtractDeletions),
trophy: "Housekeeper",
kind: "lines removed",
},
}
if includeReviews {
data = append(data, statHighlight{
stats: Sort(s, Reviews),
trophy: "Pull Requests Reviewed",
kind: "pull requests reviewed",
})
}
// TODO: handle no results for a given topic
for _, d := range data {
if _, err := fmt.Fprintln(
w,
fmt.Sprintf("### %s champions are:", d.trophy),
); err != nil {
return err
}
j := top
if len(d.stats) < j {
j = len(d.stats)
}
for i := 0; i < j; i++ {
if _, err := fmt.Fprintln(w,
fmt.Sprintf(
"- %s %s with %d %s!",
emojiForPos(i),
d.stats[i].Key,
d.stats[i].Value,
d.kind,
),
); err != nil {
return err
}
}
fmt.Fprintln(w)
}
return nil
}
func emojiForPos(pos int) string {
emojis := []string{"\U0001f3c6", "\U0001f948", "\U0001f949"}
if pos < len(emojis) {
return emojis[pos]
}
return " "
}
type statHighlight struct {
stats []StatPair
trophy string
kind string
}