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
|
package shared
import (
"fmt"
"strconv"
"strings"
"time"
"github.com/cli/cli/v2/api"
"github.com/cli/cli/v2/internal/tableprinter"
"github.com/cli/cli/v2/internal/text"
prShared "github.com/cli/cli/v2/pkg/cmd/pr/shared"
"github.com/cli/cli/v2/pkg/iostreams"
)
func PrintIssues(io *iostreams.IOStreams, now time.Time, prefix string, totalCount int, issues []api.Issue) {
cs := io.ColorScheme()
isTTY := io.IsStdoutTTY()
headers := []string{"ID"}
if !isTTY {
headers = append(headers, "STATE")
}
headers = append(headers,
"TITLE",
"LABELS",
"UPDATED",
)
table := tableprinter.New(io, tableprinter.WithHeader(headers...))
for _, issue := range issues {
issueNum := strconv.Itoa(issue.Number)
if isTTY {
issueNum = "#" + issueNum
}
issueNum = prefix + issueNum
table.AddField(issueNum, tableprinter.WithColor(cs.ColorFromString(prShared.ColorForIssueState(issue))))
if !isTTY {
table.AddField(issue.State)
}
table.AddField(text.RemoveExcessiveWhitespace(issue.Title))
table.AddField(issueLabelList(&issue, cs, isTTY))
table.AddTimeField(now, issue.UpdatedAt, cs.Gray)
table.EndRow()
}
_ = table.Render()
remaining := totalCount - len(issues)
if remaining > 0 {
fmt.Fprintf(io.Out, cs.Gray("%sAnd %d more\n"), prefix, remaining)
}
}
func issueLabelList(issue *api.Issue, cs *iostreams.ColorScheme, colorize bool) string {
if len(issue.Labels.Nodes) == 0 {
return ""
}
labelNames := make([]string, 0, len(issue.Labels.Nodes))
for _, label := range issue.Labels.Nodes {
if colorize {
labelNames = append(labelNames, cs.HexToRGB(label.Color, label.Name))
} else {
labelNames = append(labelNames, label.Name)
}
}
return strings.Join(labelNames, ", ")
}
|