Skip to content

Commit cb06812

Browse files
authored
Merge pull request cli#532 from mingrammer/consistent-printing
fix: inconsistent format between issue list and status
2 parents 74a2a24 + 0d38f1f commit cb06812

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

command/issue.go

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/cli/cli/git"
1515
"github.com/cli/cli/internal/ghrepo"
1616
"github.com/cli/cli/pkg/githubtemplate"
17-
"github.com/cli/cli/pkg/text"
1817
"github.com/cli/cli/utils"
1918
"github.com/spf13/cobra"
2019
"github.com/spf13/pflag"
@@ -138,23 +137,7 @@ func issueList(cmd *cobra.Command, args []string) error {
138137
}
139138

140139
out := cmd.OutOrStdout()
141-
table := utils.NewTablePrinter(out)
142-
for _, issue := range issues {
143-
issueNum := strconv.Itoa(issue.Number)
144-
if table.IsTTY() {
145-
issueNum = "#" + issueNum
146-
}
147-
labels := labelList(issue)
148-
if labels != "" && table.IsTTY() {
149-
labels = fmt.Sprintf("(%s)", labels)
150-
}
151-
table.AddField(issueNum, nil, colorFuncForState(issue.State))
152-
table.AddField(replaceExcessiveWhitespace(issue.Title), nil, nil)
153-
table.AddField(labels, nil, utils.Gray)
154-
table.EndRow()
155-
}
156-
table.Render()
157-
140+
printIssues(out, "", len(issues), issues)
158141
return nil
159142
}
160143

@@ -409,21 +392,26 @@ func issueCreate(cmd *cobra.Command, args []string) error {
409392
}
410393

411394
func printIssues(w io.Writer, prefix string, totalCount int, issues []api.Issue) {
395+
table := utils.NewTablePrinter(w)
412396
for _, issue := range issues {
413-
number := utils.Green("#" + strconv.Itoa(issue.Number))
414-
coloredLabels := labelList(issue)
415-
if coloredLabels != "" {
416-
coloredLabels = utils.Gray(fmt.Sprintf(" (%s)", coloredLabels))
397+
issueNum := strconv.Itoa(issue.Number)
398+
if table.IsTTY() {
399+
issueNum = "#" + issueNum
400+
}
401+
issueNum = prefix + issueNum
402+
labels := labelList(issue)
403+
if labels != "" && table.IsTTY() {
404+
labels = fmt.Sprintf("(%s)", labels)
417405
}
418-
419406
now := time.Now()
420407
ago := now.Sub(issue.UpdatedAt)
421-
422-
fmt.Fprintf(w, "%s%s %s%s %s\n", prefix, number,
423-
text.Truncate(70, replaceExcessiveWhitespace(issue.Title)),
424-
coloredLabels,
425-
utils.Gray(utils.FuzzyAgo(ago)))
408+
table.AddField(issueNum, nil, colorFuncForState(issue.State))
409+
table.AddField(replaceExcessiveWhitespace(issue.Title), nil, nil)
410+
table.AddField(labels, nil, utils.Gray)
411+
table.AddField(utils.FuzzyAgo(ago), nil, utils.Gray)
412+
table.EndRow()
426413
}
414+
table.Render()
427415
remaining := totalCount - len(issues)
428416
if remaining > 0 {
429417
fmt.Fprintf(w, utils.Gray("%sAnd %d more\n"), prefix, remaining)

command/issue_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ func TestIssueStatus(t *testing.T) {
2929
}
3030

3131
expectedIssues := []*regexp.Regexp{
32-
regexp.MustCompile(`#8.*carrots`),
33-
regexp.MustCompile(`#9.*squash`),
34-
regexp.MustCompile(`#10.*broccoli`),
35-
regexp.MustCompile(`#11.*swiss chard`),
32+
regexp.MustCompile(`(?m)8.*carrots.*about.*ago`),
33+
regexp.MustCompile(`(?m)9.*squash.*about.*ago`),
34+
regexp.MustCompile(`(?m)10.*broccoli.*about.*ago`),
35+
regexp.MustCompile(`(?m)11.*swiss chard.*about.*ago`),
3636
}
3737

3838
for _, r := range expectedIssues {

0 commit comments

Comments
 (0)