-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.go
More file actions
223 lines (201 loc) · 7 KB
/
report.go
File metadata and controls
223 lines (201 loc) · 7 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
package main
import (
"fmt"
"strings"
"time"
)
// Report holds all data for generating reports
type Report struct {
Stats Stats
Streaks StreakInfo
Churn []FileChurn
Days int
RepoName string
}
// GenerateReport creates a comprehensive report
func GenerateReport(stats Stats, streaks StreakInfo, churn []FileChurn, days int) Report {
return Report{
Stats: stats,
Streaks: streaks,
Churn: churn,
Days: days,
}
}
// PrintTerminal prints the report to the terminal
func (r Report) PrintTerminal() {
printHeader("📋 Comprehensive Report", fmt.Sprintf("Last %d days", r.Days))
// Section 1: Overview
fmt.Println(colorize(" ── Overview ──", BrightWhite+Bold))
fmt.Println()
printKV("Period", fmt.Sprintf("%s → %s (%d days)",
r.Stats.FirstCommit.Format("Jan 2"),
r.Stats.LastCommit.Format("Jan 2, 2006"),
r.Days))
printKV("Total Commits", fmt.Sprintf("%d", r.Stats.TotalCommits))
printKV("Active Days", fmt.Sprintf("%d (%.0f%%)",
r.Stats.ActiveDays,
float64(r.Stats.ActiveDays)/float64(r.Days)*100))
printKV("Lines Changed",
fmt.Sprintf("%s / %s",
colorize(fmt.Sprintf("+%d", r.Stats.TotalInsertions), Green),
colorize(fmt.Sprintf("-%d", r.Stats.TotalDeletions), Red)))
printKV("Commits/Day", fmt.Sprintf("%.1f", r.Stats.AvgCommitsPerDay))
fmt.Println()
// Section 2: Streaks
fmt.Println(colorize(" ── Streaks ──", BrightWhite+Bold))
fmt.Println()
printKV("Current Streak", fmt.Sprintf("%d days 🔥", r.Streaks.CurrentStreak))
printKV("Longest Streak", fmt.Sprintf("%d days 🏆", r.Streaks.LongestStreak))
printKV("Activity Rate", fmt.Sprintf("%.1f%%", r.Streaks.ActivityRate))
fmt.Println()
// Section 3: Patterns
fmt.Println(colorize(" ── Patterns ──", BrightWhite+Bold))
fmt.Println()
peakHour, hCount := PeakHour(r.Stats.CommitsByHour)
peakDay, dCount := PeakDay(r.Stats.CommitsByWeekday)
printKV("Peak Hour", fmt.Sprintf("%02d:00 (%d commits)", peakHour, hCount))
printKV("Peak Day", fmt.Sprintf("%s (%d commits)", peakDay, dCount))
if r.Stats.BusiestDay != "" {
printKV("Busiest Date", fmt.Sprintf("%s (%d commits)", r.Stats.BusiestDay, r.Stats.BusiestDayCount))
}
fmt.Println()
// Section 4: Top contributors
if len(r.Stats.AuthorCommits) > 1 {
fmt.Println(colorize(" ── Contributors ──", BrightWhite+Bold))
fmt.Println()
authors := TopAuthors(r.Stats.AuthorCommits, 5)
for i, a := range authors {
pct := float64(a.Commits) / float64(r.Stats.TotalCommits) * 100
fmt.Printf(" %d. %-20s %d commits (%.0f%%)\n", i+1, a.Name, a.Commits, pct)
}
fmt.Println()
}
// Section 5: Hottest files
if len(r.Churn) > 0 {
fmt.Println(colorize(" ── Hottest Files ──", BrightWhite+Bold))
fmt.Println()
limit := min(10, len(r.Churn))
for i := 0; i < limit; i++ {
f := r.Churn[i]
fmt.Printf(" %2d. %-45s %dx changed\n", i+1, truncate(f.Path, 45), f.Changes)
}
fmt.Println()
}
printFooter()
}
// ToMarkdown generates a markdown report
func (r Report) ToMarkdown() string {
var sb strings.Builder
sb.WriteString("# Git Activity Report\n\n")
sb.WriteString(fmt.Sprintf("*Generated by gitcap v%s on %s*\n\n",
version, time.Now().Format("January 2, 2006")))
// Overview
sb.WriteString("## 📊 Overview\n\n")
sb.WriteString(fmt.Sprintf("| Metric | Value |\n"))
sb.WriteString(fmt.Sprintf("|--------|-------|\n"))
sb.WriteString(fmt.Sprintf("| Period | %s → %s (%d days) |\n",
r.Stats.FirstCommit.Format("Jan 2"),
r.Stats.LastCommit.Format("Jan 2, 2006"),
r.Days))
sb.WriteString(fmt.Sprintf("| Total Commits | %d |\n", r.Stats.TotalCommits))
sb.WriteString(fmt.Sprintf("| Active Days | %d (%.0f%%) |\n",
r.Stats.ActiveDays,
float64(r.Stats.ActiveDays)/float64(max(r.Days, 1))*100))
sb.WriteString(fmt.Sprintf("| Lines Added | +%d |\n", r.Stats.TotalInsertions))
sb.WriteString(fmt.Sprintf("| Lines Removed | -%d |\n", r.Stats.TotalDeletions))
sb.WriteString(fmt.Sprintf("| Files Changed | %d |\n", r.Stats.TotalFiles))
sb.WriteString(fmt.Sprintf("| Avg Commits/Day | %.1f |\n", r.Stats.AvgCommitsPerDay))
sb.WriteString("\n")
// Streaks
sb.WriteString("## 🔥 Streaks\n\n")
sb.WriteString(fmt.Sprintf("- **Current Streak:** %d days\n", r.Streaks.CurrentStreak))
sb.WriteString(fmt.Sprintf("- **Longest Streak:** %d days (%s → %s)\n",
r.Streaks.LongestStreak,
r.Streaks.LongestStreakStart.Format("Jan 2"),
r.Streaks.LongestStreakEnd.Format("Jan 2, 2006")))
sb.WriteString(fmt.Sprintf("- **Activity Rate:** %.1f%%\n", r.Streaks.ActivityRate))
sb.WriteString("\n")
// Patterns
sb.WriteString("## 🕐 Patterns\n\n")
peakHour, hCount := PeakHour(r.Stats.CommitsByHour)
peakDay, dCount := PeakDay(r.Stats.CommitsByWeekday)
sb.WriteString(fmt.Sprintf("- **Peak Hour:** %02d:00 (%d commits)\n", peakHour, hCount))
sb.WriteString(fmt.Sprintf("- **Peak Day:** %s (%d commits)\n", peakDay, dCount))
if r.Stats.BusiestDay != "" {
sb.WriteString(fmt.Sprintf("- **Busiest Date:** %s (%d commits)\n",
r.Stats.BusiestDay, r.Stats.BusiestDayCount))
}
sb.WriteString("\n")
// Hour distribution
sb.WriteString("### Commits by Hour\n\n")
sb.WriteString("```\n")
maxH := 0
for _, c := range r.Stats.CommitsByHour {
if c > maxH {
maxH = c
}
}
for h := 0; h < 24; h++ {
barLen := 0
if maxH > 0 {
barLen = r.Stats.CommitsByHour[h] * 40 / maxH
}
sb.WriteString(fmt.Sprintf("%02d:00 %s %d\n", h,
strings.Repeat("█", barLen), r.Stats.CommitsByHour[h]))
}
sb.WriteString("```\n\n")
// Day distribution
sb.WriteString("### Commits by Day\n\n")
sb.WriteString("```\n")
dayNames := []string{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}
maxD := 0
for _, c := range r.Stats.CommitsByWeekday {
if c > maxD {
maxD = c
}
}
for d := 0; d < 7; d++ {
barLen := 0
if maxD > 0 {
barLen = r.Stats.CommitsByWeekday[d] * 40 / maxD
}
sb.WriteString(fmt.Sprintf("%s %s %d\n", dayNames[d],
strings.Repeat("█", barLen), r.Stats.CommitsByWeekday[d]))
}
sb.WriteString("```\n\n")
// Contributors
if len(r.Stats.AuthorCommits) > 1 {
sb.WriteString("## 👥 Contributors\n\n")
sb.WriteString("| Rank | Author | Commits | % |\n")
sb.WriteString("|------|--------|---------|---|\n")
authors := TopAuthors(r.Stats.AuthorCommits, 10)
for i, a := range authors {
pct := float64(a.Commits) / float64(r.Stats.TotalCommits) * 100
sb.WriteString(fmt.Sprintf("| %d | %s | %d | %.0f%% |\n",
i+1, a.Name, a.Commits, pct))
}
sb.WriteString("\n")
}
// Hottest files
if len(r.Churn) > 0 {
sb.WriteString("## 📁 Hottest Files\n\n")
sb.WriteString("| Rank | File | Changes | +/- |\n")
sb.WriteString("|------|------|---------|-----|\n")
limit := min(15, len(r.Churn))
for i := 0; i < limit; i++ {
f := r.Churn[i]
sb.WriteString(fmt.Sprintf("| %d | `%s` | %d | +%d/-%d |\n",
i+1, f.Path, f.Changes, f.Insertions, f.Deletions))
}
sb.WriteString("\n")
}
sb.WriteString("---\n")
sb.WriteString(fmt.Sprintf("*Generated by [gitcap](https://github.com/thinkshake/gitcap) v%s*\n", version))
return sb.String()
}
func max(a, b int) int {
if a > b {
return a
}
return b
}