-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
pr.go
61 lines (51 loc) · 1.61 KB
/
pr.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
package main
import (
"fmt"
"strconv"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/gitty/vcs"
"github.com/muesli/reflow/truncate"
)
func printPullRequest(pr vcs.PullRequest, maxWidth int) {
genericStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorGray))
numberStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorBlue)).Width(maxWidth).Align(lipgloss.Right)
timeStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorGreen)).Width(8).Align(lipgloss.Right)
titleStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorDarkGray)).Width(80 - maxWidth)
var s string
s += numberStyle.Render(strconv.Itoa(pr.ID))
s += genericStyle.Render(" ")
s += titleStyle.Render(truncate.StringWithTail(pr.Title, uint(80-maxWidth), "…"))
s += genericStyle.Render(" ")
s += timeStyle.Render(ago(pr.CreatedAt))
s += genericStyle.Render(" ")
s += pr.Labels.View()
fmt.Println(s)
}
func printPullRequests(prs []vcs.PullRequest) {
headerStyle := lipgloss.NewStyle().
PaddingTop(1).
Foreground(lipgloss.Color(theme.colorMagenta))
fmt.Println(headerStyle.Render(fmt.Sprintf("%s %s", "📌", pluralize(len(prs), "open pull request", "open pull requests"))))
// trimmed := false
if *maxPullRequests > 0 && len(prs) > *maxPullRequests {
prs = prs[:*maxPullRequests]
// trimmed = true
}
// detect max width of pr number
var maxWidth int
for _, v := range prs {
if len(strconv.Itoa(v.ID)) > maxWidth {
maxWidth = len(strconv.Itoa(v.ID))
}
}
for _, v := range prs {
printPullRequest(v, maxWidth)
}
// if trimmed {
// fmt.Println("...")
// }
}