-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathrelease.go
74 lines (64 loc) · 2.2 KB
/
release.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
package main
import (
"fmt"
"time"
"github.com/charmbracelet/lipgloss"
"github.com/dustin/go-humanize"
"github.com/muesli/gitty/vcs"
)
func repoRelease(repo vcs.Repo) {
genericStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorGray))
repoStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorBlue))
versionStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorMagenta))
dateStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorGreen))
changesStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorGreen))
day := time.Hour * 24
week := day * 7
month := week * 4
since := time.Since(repo.LastRelease.PublishedAt)
switch {
case since > month*6:
dateStyle = dateStyle.Foreground(lipgloss.Color(theme.colorRed))
case since > month*3:
dateStyle = dateStyle.Foreground(lipgloss.Color(theme.colorYellow))
}
switch {
case len(repo.LastRelease.CommitsSince) > 32:
changesStyle = changesStyle.Foreground(lipgloss.Color(theme.colorRed))
case len(repo.LastRelease.CommitsSince) > 16:
changesStyle = changesStyle.Foreground(lipgloss.Color(theme.colorYellow))
}
if len(repo.LastRelease.CommitsSince) < *minNewCommits {
if *skipStaleRepos {
return
}
// genericStyle = genericStyle.Foreground(lipgloss.Color(theme.colorGray))
// repoStyle = repoStyle.Foreground(lipgloss.Color(theme.colorGray))
// versionStyle = versionStyle.Foreground(lipgloss.Color(theme.colorGray))
// dateStyle = dateStyle.Foreground(lipgloss.Color(theme.colorGray))
// changesStyle = changesStyle.Foreground(lipgloss.Color(theme.colorGray))
}
var s string
s += repoStyle.Render(repo.Name)
s += versionStyle.Render(" " + repo.LastRelease.TagName)
s += genericStyle.Render(" (")
s += dateStyle.Render(humanize.Time(repo.LastRelease.PublishedAt))
s += genericStyle.Render(", ")
s += changesStyle.Render(fmt.Sprintf("%d new commits since", len(repo.LastRelease.CommitsSince)))
s += genericStyle.Render(")")
fmt.Println(s)
if *withCommits && len(repo.LastRelease.CommitsSince) > 0 {
for i, commit := range repo.LastRelease.CommitsSince {
if i >= *maxCommits && *maxCommits > 0 {
break
}
printCommit(commit)
}
fmt.Println()
}
}