Merge pull request #2312 from jan25/jan25/issue-2042

Fetch and print all Issue labels
This commit is contained in:
Mislav Marohnić 2020-11-11 16:10:40 +01:00 committed by GitHub
commit 85a7dfbf4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 7 deletions

View file

@ -78,7 +78,7 @@ const fragments = `
url
state
updatedAt
labels(first: 3) {
labels(first: 100) {
nodes {
name
}

View file

@ -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, ", ")
}

View 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")
}
}