appview/pages: show monthly commit count in profile timeline #854

merged
opened by oppi.li targeting master from op/smtsyvpnzwlw
Changed files
+22 -1
appview
models
pages
templates
state
+3 -1
appview/models/profile.go
···
}
type ByMonth struct {
+
Commits int
RepoEvents []RepoEvent
IssueEvents IssueEvents
PullEvents PullEvents
···
func (b ByMonth) IsEmpty() bool {
return len(b.RepoEvents) == 0 &&
len(b.IssueEvents.Items) == 0 &&
-
len(b.PullEvents.Items) == 0
+
len(b.PullEvents.Items) == 0 &&
+
b.Commits == 0
}
type IssueEvents struct {
+10
appview/pages/templates/user/overview.html
···
</p>
<div class="flex flex-col gap-1">
+
{{ block "commits" .Commits }} {{ end }}
{{ block "repoEvents" .RepoEvents }} {{ end }}
{{ block "issueEvents" .IssueEvents }} {{ end }}
{{ block "pullEvents" .PullEvents }} {{ end }}
···
</div>
{{ end }}
+
{{ define "commits" }}
+
{{ if . }}
+
<div class="flex flex-wrap items-center gap-1">
+
{{ i "git-commit-horizontal" "size-5" }}
+
created {{ . }} commits
+
</div>
+
{{ end }}
+
{{ end }}
+
{{ define "repoEvents" }}
{{ if gt (len .) 0 }}
<details>
+9
appview/state/profile.go
···
l.Error("failed to create timeline", "err", err)
}
+
// populate commit counts in the timeline, using the punchcard
+
currentMonth := time.Now().Month()
+
for _, p := range profile.Punchcard.Punches {
+
idx := currentMonth - p.Date.Month()
+
if int(idx) < len(timeline.ByMonth) {
+
timeline.ByMonth[idx].Commits += p.Count
+
}
+
}
+
s.pages.ProfileOverview(w, pages.ProfileOverviewParams{
LoggedInUser: s.oauth.GetUser(r),
Card: profile,