diff --git a/command/issue.go b/command/issue.go index 96e33643a..5111fdec8 100644 --- a/command/issue.go +++ b/command/issue.go @@ -261,13 +261,13 @@ func printIssuePreview(out io.Writer, issue *api.Issue) error { fmt.Fprintln(out, utils.Bold(issue.Title)) fmt.Fprintf(out, "%s", issueStateColorFunc(issue.State)) fmt.Fprint(out, utils.Gray(fmt.Sprintf( - " • %s opened %s • %s • ", + " • %s opened %s • %s", issue.Author.Login, utils.FuzzyAgo(ago), utils.Pluralize(issue.Comments.TotalCount, "comment"), ))) if coloredLabels != "" { - fmt.Fprintf(out, "%s", utils.Gray(coloredLabels)) + fmt.Fprintf(out, utils.Gray(fmt.Sprintf(" • %s", coloredLabels))) } fmt.Fprintf(out, "\n") diff --git a/command/issue_test.go b/command/issue_test.go index 845f2aca9..c4a9e3405 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -309,6 +309,36 @@ func TestIssueView_preview(t *testing.T) { } } +func TestIssueView_previewNoLabel(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + jsonFile, _ := os.Open("../test/fixtures/issueView_previewNoLabel.json") + defer jsonFile.Close() + http.StubResponse(200, jsonFile) + + output, err := RunCommand(issueViewCmd, "issue view -p 123") + if err != nil { + t.Errorf("error running command `issue view`: %v", err) + } + + eq(t, output.Stderr(), "") + + expectedLines := []*regexp.Regexp{ + regexp.MustCompile(`ix of coins`), + regexp.MustCompile(`OPEN • marseilles opened about 292 years ago • 9 comments`), + regexp.MustCompile(`bold story`), + regexp.MustCompile(`View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`), + } + for _, r := range expectedLines { + if !r.MatchString(output.String()) { + t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output) + return + } + } +} + func TestIssueView_previewClosedState(t *testing.T) { initBlankContext("OWNER/REPO", "master") http := initFakeHTTP() diff --git a/test/fixtures/issueView_previewNoLabel.json b/test/fixtures/issueView_previewNoLabel.json new file mode 100644 index 000000000..1891100eb --- /dev/null +++ b/test/fixtures/issueView_previewNoLabel.json @@ -0,0 +1,25 @@ +{ + "data": { + "repository": { + "hasIssuesEnabled": true, + "issue": { + "number": 123, + "body": "**bold story**", + "title": "ix of coins", + "state": "OPEN", + "created_at": "2011-01-26T19:01:12Z", + "author": { + "login": "marseilles" + }, + "labels": { + "nodes": [ + ] + }, + "comments": { + "totalCount": 9 + }, + "url": "https://github.com/OWNER/REPO/issues/123" + } + } + } +}