Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions command/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package command
import (
"fmt"
"io"
"os"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -206,8 +207,13 @@ func prList(cmd *cobra.Command, args []string) error {
})

title := listHeader(ghrepo.FullName(baseRepo), "pull request", len(listResult.PullRequests), listResult.TotalCount, hasFilters)
// TODO: avoid printing header if piped to a script
fmt.Fprintf(colorableErr(cmd), "\n%s\n\n", title)

out := cmd.OutOrStdout()
if outFile, isFile := out.(*os.File); isFile {
if utils.IsTerminal(outFile) {
fmt.Fprintf(colorableErr(cmd), "\n%s\n\n", title)
}
}

table := utils.NewTablePrinter(cmd.OutOrStdout())
for _, pr := range listResult.PullRequests {
Expand Down
14 changes: 4 additions & 10 deletions command/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ Requesting a code review from you
}
}

func TestPRList(t *testing.T) {
func TestPRList_stdout_is_not_a_tty(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated test name makes me think that we should really have a way to force "tty mode" in tests to be able to assert such output. 🤔

This is not something that you have to do in this PR, btw. I don't know yet how would we pass that information to tests.

This comment was marked as spam.

initBlankContext("", "OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
Expand All @@ -278,17 +278,14 @@ func TestPRList(t *testing.T) {
t.Fatal(err)
}

eq(t, output.Stderr(), `
Showing 3 of 3 pull requests in OWNER/REPO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend that we hold off merging this until we figure out how to simulate tty mode for tests so we can keep asserting this output. The header is an important part of output and I wish we can keep test coverage of it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is fair. In reviewing #572 and then returning to this I think we need to step back and design a holistic approach to determining what kind of output (both formatting and color) to use; something routed via the cmd reference that can be stubbed appropriately when running commands in a test.

This comment was marked as spam.


`)
eq(t, output.Stderr(), ``)
eq(t, output.String(), `32 New feature feature
29 Fixed bad bug hubot:bug-fix
28 Improve documentation docs
`)
}

func TestPRList_filtering(t *testing.T) {
func TestPRList_filtering_stdout_is_not_a_tty(t *testing.T) {
initBlankContext("", "OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
Expand All @@ -302,10 +299,7 @@ func TestPRList_filtering(t *testing.T) {
}

eq(t, output.String(), "")
eq(t, output.Stderr(), `
No pull requests match your search in OWNER/REPO

`)
eq(t, output.Stderr(), ``)

bodyBytes, _ := ioutil.ReadAll(http.Requests[1].Body)
reqBody := struct {
Expand Down