added fix for empty body in pr preview
This commit is contained in:
parent
c27d7807a0
commit
8f9574be35
3 changed files with 85 additions and 3 deletions
|
|
@ -308,9 +308,11 @@ func printPrPreview(out io.Writer, pr *api.PullRequest) {
|
|||
pr.BaseRefName,
|
||||
pr.HeadRefName,
|
||||
)))
|
||||
fmt.Fprintln(out)
|
||||
fmt.Fprintln(out, utils.RenderMarkdown(pr.Body))
|
||||
fmt.Fprintln(out)
|
||||
if pr.Body != "" {
|
||||
fmt.Fprintln(out)
|
||||
fmt.Fprintln(out, utils.RenderMarkdown(pr.Body))
|
||||
fmt.Fprintln(out)
|
||||
}
|
||||
fmt.Fprintf(out, utils.Gray("View this pull request on GitHub: %s\n"), pr.URL)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -313,6 +313,40 @@ func TestPRView_previewCurrentBranch(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPRView_previewCurrentBranchWithEmptyBody(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "blueberries")
|
||||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
|
||||
jsonFile, _ := os.Open("../test/fixtures/prView_EmptyBody.json")
|
||||
defer jsonFile.Close()
|
||||
http.StubResponse(200, jsonFile)
|
||||
|
||||
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
|
||||
return &outputStub{}
|
||||
})
|
||||
defer restoreCmd()
|
||||
|
||||
output, err := RunCommand(prViewCmd, "pr view -p")
|
||||
if err != nil {
|
||||
t.Errorf("error running command `pr view`: %v", err)
|
||||
}
|
||||
|
||||
eq(t, output.Stderr(), "")
|
||||
|
||||
expectedLines := []*regexp.Regexp{
|
||||
regexp.MustCompile(`Blueberries are a good fruit`),
|
||||
regexp.MustCompile(`nobody wants to merge 8 commits into master from blueberries`),
|
||||
regexp.MustCompile(`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10`),
|
||||
}
|
||||
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 TestPRView_currentBranch(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "blueberries")
|
||||
http := initFakeHTTP()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue