restore nontty + web but suppress informational prints
This commit is contained in:
parent
168bd33bc9
commit
bffcbce716
6 changed files with 48 additions and 27 deletions
|
|
@ -517,7 +517,9 @@ func issueCreate(cmd *cobra.Command, args []string) error {
|
|||
} else if len(nonLegacyTemplateFiles) > 1 {
|
||||
openURL += "/choose"
|
||||
}
|
||||
cmd.Printf("Opening %s in your browser.\n", displayURL(openURL))
|
||||
if connectedToTerminal(cmd) {
|
||||
cmd.Printf("Opening %s in your browser.\n", displayURL(openURL))
|
||||
}
|
||||
return utils.OpenInBrowser(openURL)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -753,6 +753,8 @@ func TestIssueCreate_web(t *testing.T) {
|
|||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
|
||||
defer stubTerminal(true)()
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
|
|
@ -779,6 +781,8 @@ func TestIssueCreate_webTitleBody(t *testing.T) {
|
|||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
|
||||
defer stubTerminal(true)()
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
|
|
|
|||
|
|
@ -362,10 +362,6 @@ func prView(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if web && !connectedToTerminal(cmd) {
|
||||
return errors.New("--web unsupported when not attached to a tty")
|
||||
}
|
||||
|
||||
pr, _, err := prFromArgs(ctx, apiClient, cmd, args)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -373,7 +369,9 @@ func prView(cmd *cobra.Command, args []string) error {
|
|||
openURL := pr.URL
|
||||
|
||||
if web {
|
||||
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", openURL)
|
||||
if connectedToTerminal(cmd) {
|
||||
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", openURL)
|
||||
}
|
||||
return utils.OpenInBrowser(openURL)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -226,10 +226,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
|
|||
}
|
||||
|
||||
if !connectedToTerminal(cmd) {
|
||||
if isWeb {
|
||||
return errors.New("--web unsupported when not attached to a tty")
|
||||
}
|
||||
if !cmd.Flags().Changed("title") && !autofill {
|
||||
if !isWeb && (!cmd.Flags().Changed("title") && !autofill) {
|
||||
return errors.New("--title or --fill required when not attached to a tty")
|
||||
}
|
||||
}
|
||||
|
|
@ -368,8 +365,10 @@ func prCreate(cmd *cobra.Command, _ []string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO could exceed max url length for explorer
|
||||
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", displayURL(openURL))
|
||||
if connectedToTerminal(cmd) {
|
||||
// TODO could exceed max url length for explorer
|
||||
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", displayURL(openURL))
|
||||
}
|
||||
return utils.OpenInBrowser(openURL)
|
||||
} else {
|
||||
panic("Unreachable state")
|
||||
|
|
|
|||
|
|
@ -15,6 +15,39 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPRCreate_nontty_web(t *testing.T) {
|
||||
initBlankContext("", "OWNER/REPO", "feature")
|
||||
defer stubTerminal(false)()
|
||||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": { "repository": { "forks": { "nodes": [
|
||||
] } } } }
|
||||
`))
|
||||
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
cs.Stub("") // git config --get-regexp (determineTrackingBranch)
|
||||
cs.Stub("") // git show-ref --verify (determineTrackingBranch)
|
||||
cs.Stub("") // git status
|
||||
cs.Stub("1234567890,commit 0\n2345678901,commit 1") // git log
|
||||
cs.Stub("") // git push
|
||||
cs.Stub("") // browser
|
||||
|
||||
output, err := RunCommand(`pr create --web`)
|
||||
eq(t, err, nil)
|
||||
|
||||
eq(t, output.String(), "")
|
||||
eq(t, output.Stderr(), "")
|
||||
|
||||
eq(t, len(cs.Calls), 6)
|
||||
eq(t, strings.Join(cs.Calls[4].Args, " "), "git push --set-upstream origin HEAD:feature")
|
||||
browserCall := cs.Calls[5].Args
|
||||
eq(t, browserCall[len(browserCall)-1], "https://github.com/OWNER/REPO/compare/master...feature?expand=1")
|
||||
|
||||
}
|
||||
|
||||
func TestPRCreate_nontty_insufficient_flags(t *testing.T) {
|
||||
initBlankContext("", "OWNER/REPO", "feature")
|
||||
defer stubTerminal(false)()
|
||||
|
|
|
|||
|
|
@ -1035,21 +1035,6 @@ func TestPRView_web_branchWithOwnerArg(t *testing.T) {
|
|||
eq(t, url, "https://github.com/hubot/REPO/pull/23")
|
||||
}
|
||||
|
||||
func TestPrView_web_nontty(t *testing.T) {
|
||||
initBlankContext("", "OWNER/REPO", "master")
|
||||
defer stubTerminal(false)()
|
||||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
|
||||
output, err := RunCommand("pr view -w")
|
||||
if err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
|
||||
assert.Equal(t, "--web unsupported when not attached to a tty", err.Error())
|
||||
assert.Equal(t, "", output.String())
|
||||
}
|
||||
|
||||
func TestReplaceExcessiveWhitespace(t *testing.T) {
|
||||
eq(t, replaceExcessiveWhitespace("hello\ngoodbye"), "hello goodbye")
|
||||
eq(t, replaceExcessiveWhitespace(" hello goodbye "), "hello goodbye")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue