Merge pull request #2312 from jan25/jan25/issue-2042
Fetch and print all Issue labels
This commit is contained in:
commit
85a7dfbf4c
3 changed files with 26 additions and 7 deletions
|
|
@ -78,7 +78,7 @@ const fragments = `
|
|||
url
|
||||
state
|
||||
updatedAt
|
||||
labels(first: 3) {
|
||||
labels(first: 100) {
|
||||
nodes {
|
||||
name
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func PrintIssues(io *iostreams.IOStreams, prefix string, totalCount int, issues
|
|||
table.AddField(issue.State, nil, nil)
|
||||
}
|
||||
table.AddField(text.ReplaceExcessiveWhitespace(issue.Title), nil, nil)
|
||||
table.AddField(labels, nil, cs.Gray)
|
||||
table.AddField(labels, truncateLabels, cs.Gray)
|
||||
if table.IsTTY() {
|
||||
table.AddField(utils.FuzzyAgo(ago), nil, cs.Gray)
|
||||
} else {
|
||||
|
|
@ -48,6 +48,14 @@ func PrintIssues(io *iostreams.IOStreams, prefix string, totalCount int, issues
|
|||
}
|
||||
}
|
||||
|
||||
func truncateLabels(w int, t string) string {
|
||||
if len(t) < 2 {
|
||||
return t
|
||||
}
|
||||
truncated := text.Truncate(w-2, t[1:len(t)-1])
|
||||
return fmt.Sprintf("(%s)", truncated)
|
||||
}
|
||||
|
||||
func IssueLabelList(issue api.Issue) string {
|
||||
if len(issue.Labels.Nodes) == 0 {
|
||||
return ""
|
||||
|
|
@ -58,9 +66,5 @@ func IssueLabelList(issue api.Issue) string {
|
|||
labelNames = append(labelNames, label.Name)
|
||||
}
|
||||
|
||||
list := strings.Join(labelNames, ", ")
|
||||
if issue.Labels.TotalCount > len(issue.Labels.Nodes) {
|
||||
list += ", …"
|
||||
}
|
||||
return list
|
||||
return strings.Join(labelNames, ", ")
|
||||
}
|
||||
|
|
|
|||
15
pkg/cmd/issue/shared/display_test.go
Normal file
15
pkg/cmd/issue/shared/display_test.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package shared
|
||||
|
||||
import "testing"
|
||||
|
||||
func Test_truncateLabels(t *testing.T) {
|
||||
got := truncateLabels(12, "(one, two, three)")
|
||||
expected := "(one, tw...)"
|
||||
if got != expected {
|
||||
t.Errorf("expected %q, got %q", expected, got)
|
||||
}
|
||||
|
||||
if truncateLabels(10, "") != "" {
|
||||
t.Error("blank value error")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue