Skip to content

Commit 2c2c8a9

Browse files
committed
added fix for empty body in issue preview
1 parent 8f9574b commit 2c2c8a9

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

command/issue.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,11 @@ func printIssuePreview(out io.Writer, issue *api.Issue) {
255255
utils.Pluralize(issue.Comments.TotalCount, "comment"),
256256
coloredLabels,
257257
)))
258-
fmt.Fprintln(out)
259-
fmt.Fprintln(out, utils.RenderMarkdown(issue.Body))
260-
fmt.Fprintln(out)
258+
if issue.Body != "" {
259+
fmt.Fprintln(out)
260+
fmt.Fprintln(out, utils.RenderMarkdown(issue.Body))
261+
fmt.Fprintln(out)
262+
}
261263
fmt.Fprintf(out, utils.Gray("View this issue on GitHub: %s\n"), issue.URL)
262264
}
263265

command/issue_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,51 @@ func TestIssueView_preview(t *testing.T) {
288288
}
289289
}
290290

291+
func TestIssueView_previewWithEmptyBody(t *testing.T) {
292+
initBlankContext("OWNER/REPO", "master")
293+
http := initFakeHTTP()
294+
http.StubRepoResponse("OWNER", "REPO")
295+
296+
http.StubResponse(200, bytes.NewBufferString(`
297+
{ "data": { "repository": { "hasIssuesEnabled": true, "issue": {
298+
"number": 123,
299+
"body": "",
300+
"title": "ix of coins",
301+
"author": {
302+
"login": "marseilles"
303+
},
304+
"labels": {
305+
"nodes": [
306+
{"name": "tarot"}
307+
]
308+
},
309+
"comments": {
310+
"totalCount": 9
311+
},
312+
"url": "https://github.com/OWNER/REPO/issues/123"
313+
} } } }
314+
`))
315+
316+
output, err := RunCommand(issueViewCmd, "issue view -p 123")
317+
if err != nil {
318+
t.Errorf("error running command `issue view`: %v", err)
319+
}
320+
321+
eq(t, output.Stderr(), "")
322+
323+
expectedLines := []*regexp.Regexp{
324+
regexp.MustCompile(`ix of coins`),
325+
regexp.MustCompile(`opened by marseilles. 9 comments. \(tarot\)`),
326+
regexp.MustCompile(`View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`),
327+
}
328+
for _, r := range expectedLines {
329+
if !r.MatchString(output.String()) {
330+
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
331+
return
332+
}
333+
}
334+
}
335+
291336
func TestIssueView_notFound(t *testing.T) {
292337
initBlankContext("OWNER/REPO", "master")
293338
http := initFakeHTTP()

0 commit comments

Comments
 (0)