X Tutup
Skip to content

Commit e4b8ae0

Browse files
author
Nate Smith
authored
Merge pull request cli#665 from cli/preview-default
switch {pr,issue} view default
2 parents 26022bc + e4b43b0 commit e4b8ae0

File tree

4 files changed

+45
-45
lines changed

4 files changed

+45
-45
lines changed

command/issue.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func init() {
3838
issueListCmd.Flags().StringP("author", "A", "", "Filter by author")
3939

4040
issueCmd.AddCommand(issueViewCmd)
41-
issueViewCmd.Flags().BoolP("preview", "p", false, "Display preview of issue content")
41+
issueViewCmd.Flags().BoolP("web", "w", false, "Open issue in browser")
4242
}
4343

4444
var issueCmd = &cobra.Command{
@@ -73,7 +73,7 @@ var issueViewCmd = &cobra.Command{
7373
}
7474
return nil
7575
},
76-
Short: "View an issue in the browser",
76+
Short: "View an issue",
7777
RunE: issueView,
7878
}
7979

@@ -213,17 +213,17 @@ func issueView(cmd *cobra.Command, args []string) error {
213213
}
214214
openURL := issue.URL
215215

216-
preview, err := cmd.Flags().GetBool("preview")
216+
web, err := cmd.Flags().GetBool("web")
217217
if err != nil {
218218
return err
219219
}
220220

221-
if preview {
222-
out := colorableOut(cmd)
223-
return printIssuePreview(out, issue)
224-
} else {
221+
if web {
225222
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", openURL)
226223
return utils.OpenInBrowser(openURL)
224+
} else {
225+
out := colorableOut(cmd)
226+
return printIssuePreview(out, issue)
227227
}
228228

229229
}

command/issue_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func TestIssueList_disabledIssues(t *testing.T) {
216216
}
217217
}
218218

219-
func TestIssueView(t *testing.T) {
219+
func TestIssueView_web(t *testing.T) {
220220
initBlankContext("OWNER/REPO", "master")
221221
http := initFakeHTTP()
222222
http.StubRepoResponse("OWNER", "REPO")
@@ -235,7 +235,7 @@ func TestIssueView(t *testing.T) {
235235
})
236236
defer restoreCmd()
237237

238-
output, err := RunCommand(issueViewCmd, "issue view 123")
238+
output, err := RunCommand(issueViewCmd, "issue view -w 123")
239239
if err != nil {
240240
t.Errorf("error running command `issue view`: %v", err)
241241
}
@@ -250,7 +250,7 @@ func TestIssueView(t *testing.T) {
250250
eq(t, url, "https://github.com/OWNER/REPO/issues/123")
251251
}
252252

253-
func TestIssueView_numberArgWithHash(t *testing.T) {
253+
func TestIssueView_web_numberArgWithHash(t *testing.T) {
254254
initBlankContext("OWNER/REPO", "master")
255255
http := initFakeHTTP()
256256
http.StubRepoResponse("OWNER", "REPO")
@@ -269,7 +269,7 @@ func TestIssueView_numberArgWithHash(t *testing.T) {
269269
})
270270
defer restoreCmd()
271271

272-
output, err := RunCommand(issueViewCmd, "issue view \"#123\"")
272+
output, err := RunCommand(issueViewCmd, "issue view -w \"#123\"")
273273
if err != nil {
274274
t.Errorf("error running command `issue view`: %v", err)
275275
}
@@ -284,7 +284,7 @@ func TestIssueView_numberArgWithHash(t *testing.T) {
284284
eq(t, url, "https://github.com/OWNER/REPO/issues/123")
285285
}
286286

287-
func TestIssueView_preview(t *testing.T) {
287+
func TestIssueView(t *testing.T) {
288288
initBlankContext("OWNER/REPO", "master")
289289
http := initFakeHTTP()
290290
http.StubRepoResponse("OWNER", "REPO")
@@ -309,7 +309,7 @@ func TestIssueView_preview(t *testing.T) {
309309
} } } }
310310
`))
311311

312-
output, err := RunCommand(issueViewCmd, "issue view -p 123")
312+
output, err := RunCommand(issueViewCmd, "issue view 123")
313313
if err != nil {
314314
t.Errorf("error running command `issue view`: %v", err)
315315
}
@@ -323,7 +323,7 @@ func TestIssueView_preview(t *testing.T) {
323323
"View this issue on GitHub: https://github.com/OWNER/REPO/issues/123")
324324
}
325325

326-
func TestIssueView_previewWithEmptyBody(t *testing.T) {
326+
func TestIssueView_WithEmptyBody(t *testing.T) {
327327
initBlankContext("OWNER/REPO", "master")
328328
http := initFakeHTTP()
329329
http.StubRepoResponse("OWNER", "REPO")
@@ -348,7 +348,7 @@ func TestIssueView_previewWithEmptyBody(t *testing.T) {
348348
} } } }
349349
`))
350350

351-
output, err := RunCommand(issueViewCmd, "issue view -p 123")
351+
output, err := RunCommand(issueViewCmd, "issue view 123")
352352
if err != nil {
353353
t.Errorf("error running command `issue view`: %v", err)
354354
}
@@ -361,7 +361,7 @@ func TestIssueView_previewWithEmptyBody(t *testing.T) {
361361
"View this issue on GitHub: https://github.com/OWNER/REPO/issues/123")
362362
}
363363

364-
func TestIssueView_notFound(t *testing.T) {
364+
func TestIssueView_web_notFound(t *testing.T) {
365365
initBlankContext("OWNER/REPO", "master")
366366
http := initFakeHTTP()
367367

@@ -378,7 +378,7 @@ func TestIssueView_notFound(t *testing.T) {
378378
})
379379
defer restoreCmd()
380380

381-
_, err := RunCommand(issueViewCmd, "issue view 9999")
381+
_, err := RunCommand(issueViewCmd, "issue view -w 9999")
382382
if err == nil || err.Error() != "graphql error: 'Could not resolve to an Issue with the number of 9999.'" {
383383
t.Errorf("error running command `issue view`: %v", err)
384384
}
@@ -406,7 +406,7 @@ func TestIssueView_disabledIssues(t *testing.T) {
406406
}
407407
}
408408

409-
func TestIssueView_urlArg(t *testing.T) {
409+
func TestIssueView_web_urlArg(t *testing.T) {
410410
initBlankContext("OWNER/REPO", "master")
411411
http := initFakeHTTP()
412412
http.StubRepoResponse("OWNER", "REPO")
@@ -425,7 +425,7 @@ func TestIssueView_urlArg(t *testing.T) {
425425
})
426426
defer restoreCmd()
427427

428-
output, err := RunCommand(issueViewCmd, "issue view https://github.com/OWNER/REPO/issues/123")
428+
output, err := RunCommand(issueViewCmd, "issue view -w https://github.com/OWNER/REPO/issues/123")
429429
if err != nil {
430430
t.Errorf("error running command `issue view`: %v", err)
431431
}

command/pr.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func init() {
3131
prListCmd.Flags().StringSliceP("label", "l", nil, "Filter by label")
3232
prListCmd.Flags().StringP("assignee", "a", "", "Filter by assignee")
3333

34-
prViewCmd.Flags().BoolP("preview", "p", false, "Display preview of pull request content")
34+
prViewCmd.Flags().BoolP("web", "w", false, "Open pull request in browser")
3535
}
3636

3737
var prCmd = &cobra.Command{
@@ -57,10 +57,10 @@ var prStatusCmd = &cobra.Command{
5757
var prViewCmd = &cobra.Command{
5858
Use: "view [{<number> | <url> | <branch>}]",
5959
Short: "View a pull request in the browser",
60-
Long: `View a pull request specified by the argument in the browser.
60+
Long: `View a pull request specified by the argument.
6161
6262
Without an argument, the pull request that belongs to the current
63-
branch is opened.`,
63+
branch is displayed.`,
6464
RunE: prView,
6565
}
6666

@@ -272,7 +272,7 @@ func prView(cmd *cobra.Command, args []string) error {
272272
}
273273
}
274274

275-
preview, err := cmd.Flags().GetBool("preview")
275+
web, err := cmd.Flags().GetBool("web")
276276
if err != nil {
277277
return err
278278
}
@@ -293,7 +293,7 @@ func prView(cmd *cobra.Command, args []string) error {
293293

294294
if prNumber > 0 {
295295
openURL = fmt.Sprintf("https://github.com/%s/pull/%d", ghrepo.FullName(baseRepo), prNumber)
296-
if preview {
296+
if !web {
297297
pr, err = api.PullRequestByNumber(apiClient, baseRepo, prNumber)
298298
if err != nil {
299299
return err
@@ -309,12 +309,12 @@ func prView(cmd *cobra.Command, args []string) error {
309309
}
310310
}
311311

312-
if preview {
313-
out := colorableOut(cmd)
314-
return printPrPreview(out, pr)
315-
} else {
312+
if web {
316313
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", openURL)
317314
return utils.OpenInBrowser(openURL)
315+
} else {
316+
out := colorableOut(cmd)
317+
return printPrPreview(out, pr)
318318
}
319319
}
320320

command/pr_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ func TestPRView_preview(t *testing.T) {
409409
defer jsonFile.Close()
410410
http.StubResponse(200, jsonFile)
411411

412-
output, err := RunCommand(prViewCmd, "pr view -p 12")
412+
output, err := RunCommand(prViewCmd, "pr view 12")
413413
if err != nil {
414414
t.Errorf("error running command `pr view`: %v", err)
415415
}
@@ -437,7 +437,7 @@ func TestPRView_previewCurrentBranch(t *testing.T) {
437437
})
438438
defer restoreCmd()
439439

440-
output, err := RunCommand(prViewCmd, "pr view -p")
440+
output, err := RunCommand(prViewCmd, "pr view")
441441
if err != nil {
442442
t.Errorf("error running command `pr view`: %v", err)
443443
}
@@ -465,7 +465,7 @@ func TestPRView_previewCurrentBranchWithEmptyBody(t *testing.T) {
465465
})
466466
defer restoreCmd()
467467

468-
output, err := RunCommand(prViewCmd, "pr view -p")
468+
output, err := RunCommand(prViewCmd, "pr view")
469469
if err != nil {
470470
t.Errorf("error running command `pr view`: %v", err)
471471
}
@@ -478,7 +478,7 @@ func TestPRView_previewCurrentBranchWithEmptyBody(t *testing.T) {
478478
"View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10")
479479
}
480480

481-
func TestPRView_currentBranch(t *testing.T) {
481+
func TestPRView_web_currentBranch(t *testing.T) {
482482
initBlankContext("OWNER/REPO", "blueberries")
483483
http := initFakeHTTP()
484484
http.StubRepoResponse("OWNER", "REPO")
@@ -499,7 +499,7 @@ func TestPRView_currentBranch(t *testing.T) {
499499
})
500500
defer restoreCmd()
501501

502-
output, err := RunCommand(prViewCmd, "pr view")
502+
output, err := RunCommand(prViewCmd, "pr view -w")
503503
if err != nil {
504504
t.Errorf("error running command `pr view`: %v", err)
505505
}
@@ -516,7 +516,7 @@ func TestPRView_currentBranch(t *testing.T) {
516516
}
517517
}
518518

519-
func TestPRView_noResultsForBranch(t *testing.T) {
519+
func TestPRView_web_noResultsForBranch(t *testing.T) {
520520
initBlankContext("OWNER/REPO", "blueberries")
521521
http := initFakeHTTP()
522522
http.StubRepoResponse("OWNER", "REPO")
@@ -537,7 +537,7 @@ func TestPRView_noResultsForBranch(t *testing.T) {
537537
})
538538
defer restoreCmd()
539539

540-
_, err := RunCommand(prViewCmd, "pr view")
540+
_, err := RunCommand(prViewCmd, "pr view -w")
541541
if err == nil || err.Error() != `no open pull requests found for branch "blueberries"` {
542542
t.Errorf("error running command `pr view`: %v", err)
543543
}
@@ -547,7 +547,7 @@ func TestPRView_noResultsForBranch(t *testing.T) {
547547
}
548548
}
549549

550-
func TestPRView_numberArg(t *testing.T) {
550+
func TestPRView_web_numberArg(t *testing.T) {
551551
initBlankContext("OWNER/REPO", "master")
552552
http := initFakeHTTP()
553553
http.StubRepoResponse("OWNER", "REPO")
@@ -565,7 +565,7 @@ func TestPRView_numberArg(t *testing.T) {
565565
})
566566
defer restoreCmd()
567567

568-
output, err := RunCommand(prViewCmd, "pr view 23")
568+
output, err := RunCommand(prViewCmd, "pr view -w 23")
569569
if err != nil {
570570
t.Errorf("error running command `pr view`: %v", err)
571571
}
@@ -579,7 +579,7 @@ func TestPRView_numberArg(t *testing.T) {
579579
eq(t, url, "https://github.com/OWNER/REPO/pull/23")
580580
}
581581

582-
func TestPRView_numberArgWithHash(t *testing.T) {
582+
func TestPRView_web_numberArgWithHash(t *testing.T) {
583583
initBlankContext("OWNER/REPO", "master")
584584
http := initFakeHTTP()
585585
http.StubRepoResponse("OWNER", "REPO")
@@ -597,7 +597,7 @@ func TestPRView_numberArgWithHash(t *testing.T) {
597597
})
598598
defer restoreCmd()
599599

600-
output, err := RunCommand(prViewCmd, "pr view \"#23\"")
600+
output, err := RunCommand(prViewCmd, "pr view -w \"#23\"")
601601
if err != nil {
602602
t.Errorf("error running command `pr view`: %v", err)
603603
}
@@ -611,7 +611,7 @@ func TestPRView_numberArgWithHash(t *testing.T) {
611611
eq(t, url, "https://github.com/OWNER/REPO/pull/23")
612612
}
613613

614-
func TestPRView_urlArg(t *testing.T) {
614+
func TestPRView_web_urlArg(t *testing.T) {
615615
initBlankContext("OWNER/REPO", "master")
616616
http := initFakeHTTP()
617617

@@ -628,7 +628,7 @@ func TestPRView_urlArg(t *testing.T) {
628628
})
629629
defer restoreCmd()
630630

631-
output, err := RunCommand(prViewCmd, "pr view https://github.com/OWNER/REPO/pull/23/files")
631+
output, err := RunCommand(prViewCmd, "pr view -w https://github.com/OWNER/REPO/pull/23/files")
632632
if err != nil {
633633
t.Errorf("error running command `pr view`: %v", err)
634634
}
@@ -642,7 +642,7 @@ func TestPRView_urlArg(t *testing.T) {
642642
eq(t, url, "https://github.com/OWNER/REPO/pull/23")
643643
}
644644

645-
func TestPRView_branchArg(t *testing.T) {
645+
func TestPRView_web_branchArg(t *testing.T) {
646646
initBlankContext("OWNER/REPO", "master")
647647
http := initFakeHTTP()
648648
http.StubRepoResponse("OWNER", "REPO")
@@ -662,7 +662,7 @@ func TestPRView_branchArg(t *testing.T) {
662662
})
663663
defer restoreCmd()
664664

665-
output, err := RunCommand(prViewCmd, "pr view blueberries")
665+
output, err := RunCommand(prViewCmd, "pr view -w blueberries")
666666
if err != nil {
667667
t.Errorf("error running command `pr view`: %v", err)
668668
}
@@ -676,7 +676,7 @@ func TestPRView_branchArg(t *testing.T) {
676676
eq(t, url, "https://github.com/OWNER/REPO/pull/23")
677677
}
678678

679-
func TestPRView_branchWithOwnerArg(t *testing.T) {
679+
func TestPRView_web_branchWithOwnerArg(t *testing.T) {
680680
initBlankContext("OWNER/REPO", "master")
681681
http := initFakeHTTP()
682682
http.StubRepoResponse("OWNER", "REPO")
@@ -697,7 +697,7 @@ func TestPRView_branchWithOwnerArg(t *testing.T) {
697697
})
698698
defer restoreCmd()
699699

700-
output, err := RunCommand(prViewCmd, "pr view hubot:blueberries")
700+
output, err := RunCommand(prViewCmd, "pr view -w hubot:blueberries")
701701
if err != nil {
702702
t.Errorf("error running command `pr view`: %v", err)
703703
}

0 commit comments

Comments
 (0)
X Tutup