Skip to content

Commit 8f9574b

Browse files
committed
added fix for empty body in pr preview
1 parent c27d780 commit 8f9574b

File tree

3 files changed

+85
-3
lines changed

3 files changed

+85
-3
lines changed

command/pr.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,11 @@ func printPrPreview(out io.Writer, pr *api.PullRequest) {
308308
pr.BaseRefName,
309309
pr.HeadRefName,
310310
)))
311-
fmt.Fprintln(out)
312-
fmt.Fprintln(out, utils.RenderMarkdown(pr.Body))
313-
fmt.Fprintln(out)
311+
if pr.Body != "" {
312+
fmt.Fprintln(out)
313+
fmt.Fprintln(out, utils.RenderMarkdown(pr.Body))
314+
fmt.Fprintln(out)
315+
}
314316
fmt.Fprintf(out, utils.Gray("View this pull request on GitHub: %s\n"), pr.URL)
315317
}
316318

command/pr_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,40 @@ func TestPRView_previewCurrentBranch(t *testing.T) {
313313
}
314314
}
315315

316+
func TestPRView_previewCurrentBranchWithEmptyBody(t *testing.T) {
317+
initBlankContext("OWNER/REPO", "blueberries")
318+
http := initFakeHTTP()
319+
http.StubRepoResponse("OWNER", "REPO")
320+
321+
jsonFile, _ := os.Open("../test/fixtures/prView_EmptyBody.json")
322+
defer jsonFile.Close()
323+
http.StubResponse(200, jsonFile)
324+
325+
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
326+
return &outputStub{}
327+
})
328+
defer restoreCmd()
329+
330+
output, err := RunCommand(prViewCmd, "pr view -p")
331+
if err != nil {
332+
t.Errorf("error running command `pr view`: %v", err)
333+
}
334+
335+
eq(t, output.Stderr(), "")
336+
337+
expectedLines := []*regexp.Regexp{
338+
regexp.MustCompile(`Blueberries are a good fruit`),
339+
regexp.MustCompile(`nobody wants to merge 8 commits into master from blueberries`),
340+
regexp.MustCompile(`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10`),
341+
}
342+
for _, r := range expectedLines {
343+
if !r.MatchString(output.String()) {
344+
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
345+
return
346+
}
347+
}
348+
}
349+
316350
func TestPRView_currentBranch(t *testing.T) {
317351
initBlankContext("OWNER/REPO", "blueberries")
318352
http := initFakeHTTP()
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"data": {
3+
"repository": {
4+
"pullRequests": {
5+
"nodes": [
6+
{
7+
"number": 12,
8+
"title": "Blueberries are from a fork",
9+
"body": "yeah",
10+
"url": "https://github.com/OWNER/REPO/pull/12",
11+
"headRefName": "blueberries",
12+
"baseRefName": "master",
13+
"headRepositoryOwner": {
14+
"login": "hubot"
15+
},
16+
"commits": {
17+
"totalCount": 12
18+
},
19+
"author": {
20+
"login": "nobody"
21+
},
22+
"isCrossRepository": true
23+
},
24+
{
25+
"number": 10,
26+
"title": "Blueberries are a good fruit",
27+
"body": "",
28+
"url": "https://github.com/OWNER/REPO/pull/10",
29+
"baseRefName": "master",
30+
"headRefName": "blueberries",
31+
"author": {
32+
"login": "nobody"
33+
},
34+
"headRepositoryOwner": {
35+
"login": "OWNER"
36+
},
37+
"commits": {
38+
"totalCount": 8
39+
},
40+
"isCrossRepository": false
41+
}
42+
]
43+
}
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)