switch defaults for pr view

This commit is contained in:
vilmibm 2020-03-17 17:03:10 -05:00
parent 74a2a24104
commit c30b482bf0
2 changed files with 24 additions and 24 deletions

View file

@ -31,7 +31,7 @@ func init() {
prListCmd.Flags().StringSliceP("label", "l", nil, "Filter by label")
prListCmd.Flags().StringP("assignee", "a", "", "Filter by assignee")
prViewCmd.Flags().BoolP("preview", "p", false, "Display preview of pull request content")
prViewCmd.Flags().BoolP("web", "w", false, "Open pull request in browser")
}
var prCmd = &cobra.Command{
@ -262,7 +262,7 @@ func prView(cmd *cobra.Command, args []string) error {
return err
}
preview, err := cmd.Flags().GetBool("preview")
web, err := cmd.Flags().GetBool("web")
if err != nil {
return err
}
@ -283,7 +283,7 @@ func prView(cmd *cobra.Command, args []string) error {
if prNumber > 0 {
openURL = fmt.Sprintf("https://github.com/%s/pull/%d", ghrepo.FullName(baseRepo), prNumber)
if preview {
if !web {
pr, err = api.PullRequestByNumber(apiClient, baseRepo, prNumber)
if err != nil {
return err
@ -299,12 +299,12 @@ func prView(cmd *cobra.Command, args []string) error {
}
}
if preview {
out := colorableOut(cmd)
return printPrPreview(out, pr)
} else {
if web {
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", openURL)
return utils.OpenInBrowser(openURL)
} else {
out := colorableOut(cmd)
return printPrPreview(out, pr)
}
}

View file

@ -391,7 +391,7 @@ func TestPRView_preview(t *testing.T) {
defer jsonFile.Close()
http.StubResponse(200, jsonFile)
output, err := RunCommand(prViewCmd, "pr view -p 12")
output, err := RunCommand(prViewCmd, "pr view 12")
if err != nil {
t.Errorf("error running command `pr view`: %v", err)
}
@ -426,7 +426,7 @@ func TestPRView_previewCurrentBranch(t *testing.T) {
})
defer restoreCmd()
output, err := RunCommand(prViewCmd, "pr view -p")
output, err := RunCommand(prViewCmd, "pr view")
if err != nil {
t.Errorf("error running command `pr view`: %v", err)
}
@ -461,7 +461,7 @@ func TestPRView_previewCurrentBranchWithEmptyBody(t *testing.T) {
})
defer restoreCmd()
output, err := RunCommand(prViewCmd, "pr view -p")
output, err := RunCommand(prViewCmd, "pr view")
if err != nil {
t.Errorf("error running command `pr view`: %v", err)
}
@ -481,7 +481,7 @@ func TestPRView_previewCurrentBranchWithEmptyBody(t *testing.T) {
}
}
func TestPRView_currentBranch(t *testing.T) {
func TestPRView_web_currentBranch(t *testing.T) {
initBlankContext("OWNER/REPO", "blueberries")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
@ -502,7 +502,7 @@ func TestPRView_currentBranch(t *testing.T) {
})
defer restoreCmd()
output, err := RunCommand(prViewCmd, "pr view")
output, err := RunCommand(prViewCmd, "pr view -w")
if err != nil {
t.Errorf("error running command `pr view`: %v", err)
}
@ -519,7 +519,7 @@ func TestPRView_currentBranch(t *testing.T) {
}
}
func TestPRView_noResultsForBranch(t *testing.T) {
func TestPRView_web_noResultsForBranch(t *testing.T) {
initBlankContext("OWNER/REPO", "blueberries")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
@ -540,7 +540,7 @@ func TestPRView_noResultsForBranch(t *testing.T) {
})
defer restoreCmd()
_, err := RunCommand(prViewCmd, "pr view")
_, err := RunCommand(prViewCmd, "pr view -w")
if err == nil || err.Error() != `no open pull requests found for branch "blueberries"` {
t.Errorf("error running command `pr view`: %v", err)
}
@ -550,7 +550,7 @@ func TestPRView_noResultsForBranch(t *testing.T) {
}
}
func TestPRView_numberArg(t *testing.T) {
func TestPRView_web_numberArg(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
@ -568,7 +568,7 @@ func TestPRView_numberArg(t *testing.T) {
})
defer restoreCmd()
output, err := RunCommand(prViewCmd, "pr view 23")
output, err := RunCommand(prViewCmd, "pr view -w 23")
if err != nil {
t.Errorf("error running command `pr view`: %v", err)
}
@ -582,7 +582,7 @@ func TestPRView_numberArg(t *testing.T) {
eq(t, url, "https://github.com/OWNER/REPO/pull/23")
}
func TestPRView_numberArgWithHash(t *testing.T) {
func TestPRView_web_numberArgWithHash(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
@ -600,7 +600,7 @@ func TestPRView_numberArgWithHash(t *testing.T) {
})
defer restoreCmd()
output, err := RunCommand(prViewCmd, "pr view \"#23\"")
output, err := RunCommand(prViewCmd, "pr view -w \"#23\"")
if err != nil {
t.Errorf("error running command `pr view`: %v", err)
}
@ -614,7 +614,7 @@ func TestPRView_numberArgWithHash(t *testing.T) {
eq(t, url, "https://github.com/OWNER/REPO/pull/23")
}
func TestPRView_urlArg(t *testing.T) {
func TestPRView_web_urlArg(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
@ -632,7 +632,7 @@ func TestPRView_urlArg(t *testing.T) {
})
defer restoreCmd()
output, err := RunCommand(prViewCmd, "pr view https://github.com/OWNER/REPO/pull/23/files")
output, err := RunCommand(prViewCmd, "pr view -w https://github.com/OWNER/REPO/pull/23/files")
if err != nil {
t.Errorf("error running command `pr view`: %v", err)
}
@ -646,7 +646,7 @@ func TestPRView_urlArg(t *testing.T) {
eq(t, url, "https://github.com/OWNER/REPO/pull/23")
}
func TestPRView_branchArg(t *testing.T) {
func TestPRView_web_branchArg(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
@ -666,7 +666,7 @@ func TestPRView_branchArg(t *testing.T) {
})
defer restoreCmd()
output, err := RunCommand(prViewCmd, "pr view blueberries")
output, err := RunCommand(prViewCmd, "pr view -w blueberries")
if err != nil {
t.Errorf("error running command `pr view`: %v", err)
}
@ -680,7 +680,7 @@ func TestPRView_branchArg(t *testing.T) {
eq(t, url, "https://github.com/OWNER/REPO/pull/23")
}
func TestPRView_branchWithOwnerArg(t *testing.T) {
func TestPRView_web_branchWithOwnerArg(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
@ -701,7 +701,7 @@ func TestPRView_branchWithOwnerArg(t *testing.T) {
})
defer restoreCmd()
output, err := RunCommand(prViewCmd, "pr view hubot:blueberries")
output, err := RunCommand(prViewCmd, "pr view -w hubot:blueberries")
if err != nil {
t.Errorf("error running command `pr view`: %v", err)
}