X Tutup
Skip to content

Commit 62e4c53

Browse files
committed
Ensure parentheses are preserved after truncating labels in table view
1 parent 9e03d01 commit 62e4c53

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pkg/cmd/issue/shared/display.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func PrintIssues(io *iostreams.IOStreams, prefix string, totalCount int, issues
3232
table.AddField(issue.State, nil, nil)
3333
}
3434
table.AddField(text.ReplaceExcessiveWhitespace(issue.Title), nil, nil)
35-
table.AddField(labels, nil, utils.Gray)
35+
table.AddField(labels, truncateLabels, utils.Gray)
3636
if table.IsTTY() {
3737
table.AddField(utils.FuzzyAgo(ago), nil, utils.Gray)
3838
} else {
@@ -47,6 +47,11 @@ func PrintIssues(io *iostreams.IOStreams, prefix string, totalCount int, issues
4747
}
4848
}
4949

50+
func truncateLabels(w int, t string) string {
51+
truncated := text.Truncate(w-2, t[1:len(t)-1])
52+
return fmt.Sprintf("(%s)", truncated)
53+
}
54+
5055
func IssueLabelList(issue api.Issue) string {
5156
if len(issue.Labels.Nodes) == 0 {
5257
return ""
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package shared
2+
3+
import "testing"
4+
5+
func Test_truncateLabels(t *testing.T) {
6+
got := truncateLabels(12, "(one, two, three)")
7+
expected := "(one, tw...)"
8+
if got != expected {
9+
t.Errorf("expected %q, got %q", expected, got)
10+
}
11+
}

0 commit comments

Comments
 (0)
X Tutup