forked from muesli/gitty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit.go
69 lines (57 loc) · 1.78 KB
/
commit.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
package main
import (
"fmt"
"github.com/charmbracelet/lipgloss"
"github.com/dustin/go-humanize"
"github.com/muesli/gitty/vcs"
"github.com/muesli/reflow/truncate"
)
func printCommit(commit vcs.Commit) {
genericStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorGray))
numberStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorBlue))
timeStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorGreen)).Width(8).Align(lipgloss.Right)
titleStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorDarkGray)).Width(80 - 7)
var s string
s += numberStyle.Render(commit.ID[:7])
s += genericStyle.Render(" ")
s += titleStyle.Render(truncate.StringWithTail(commit.MessageHeadline, 80-7, "…"))
s += genericStyle.Render(" ")
s += timeStyle.Render(ago(commit.CommittedAt))
s += genericStyle.Render(" ")
s += numberStyle.Render(commit.Author)
fmt.Println(s)
}
func printCommits(repo vcs.Repo) {
commits := repo.LastRelease.CommitsSince
// dimColor := gamut.ToHex(gamut.Darker(gamut.Hex(theme.colorMagenta), 0.40))
headerStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorMagenta))
// headerDimStyle := lipgloss.NewStyle().
// Foreground(lipgloss.Color(dimColor))
sinceTag := repo.LastRelease.TagName
if sinceTag == "" {
sinceTag = "creation"
}
fmt.Printf("\n🔥 %s %s\n",
headerStyle.Render(fmt.Sprintf("%s %s",
pluralize(len(commits), "commit since", "commits since"),
sinceTag)),
headerStyle.Render(fmt.Sprintf("(%s)",
humanize.Time(repo.LastRelease.PublishedAt))),
)
// trimmed := false
if *maxCommits > 0 && len(commits) > *maxCommits {
commits = commits[:*maxCommits]
// trimmed = true
}
for _, v := range commits {
printCommit(v)
}
// if trimmed {
// fmt.Println("...")
// }
}