From 2c2c8a999148a402ce4c69ee4313b25ce885b2ad Mon Sep 17 00:00:00 2001 From: Anowar Islam Date: Thu, 13 Feb 2020 01:44:03 -0800 Subject: [PATCH] added fix for empty body in issue preview --- command/issue.go | 8 +++++--- command/issue_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/command/issue.go b/command/issue.go index 4641d91c8..6caf81c12 100644 --- a/command/issue.go +++ b/command/issue.go @@ -255,9 +255,11 @@ func printIssuePreview(out io.Writer, issue *api.Issue) { utils.Pluralize(issue.Comments.TotalCount, "comment"), coloredLabels, ))) - fmt.Fprintln(out) - fmt.Fprintln(out, utils.RenderMarkdown(issue.Body)) - fmt.Fprintln(out) + if issue.Body != "" { + fmt.Fprintln(out) + fmt.Fprintln(out, utils.RenderMarkdown(issue.Body)) + fmt.Fprintln(out) + } fmt.Fprintf(out, utils.Gray("View this issue on GitHub: %s\n"), issue.URL) } diff --git a/command/issue_test.go b/command/issue_test.go index edce87fb6..c09de2c62 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -288,6 +288,51 @@ func TestIssueView_preview(t *testing.T) { } } +func TestIssueView_previewWithEmptyBody(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repository": { "hasIssuesEnabled": true, "issue": { + "number": 123, + "body": "", + "title": "ix of coins", + "author": { + "login": "marseilles" + }, + "labels": { + "nodes": [ + {"name": "tarot"} + ] + }, + "comments": { + "totalCount": 9 + }, + "url": "https://github.com/OWNER/REPO/issues/123" + } } } } + `)) + + 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(`opened by marseilles. 9 comments. \(tarot\)`), + 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_notFound(t *testing.T) { initBlankContext("OWNER/REPO", "master") http := initFakeHTTP()