@@ -32,7 +32,7 @@ func init() {
3232 prListCmd .Flags ().StringSliceP ("label" , "l" , nil , "Filter by label" )
3333 prListCmd .Flags ().StringP ("assignee" , "a" , "" , "Filter by assignee" )
3434
35- prViewCmd .Flags ().BoolP ("preview" , "p" , false , "Preview PR in termianl " )
35+ prViewCmd .Flags ().BoolP ("preview" , "p" , false , "Preview PR in terminal " )
3636}
3737
3838var prCmd = & cobra.Command {
@@ -276,6 +276,12 @@ func prView(cmd *cobra.Command, args []string) error {
276276
277277 if prNumber > 0 {
278278 openURL = fmt .Sprintf ("https://github.com/%s/%s/pull/%d" , baseRepo .RepoOwner (), baseRepo .RepoName (), prNumber )
279+ if preview {
280+ pr , err = api .PullRequestByNumber (apiClient , baseRepo , prNumber )
281+ if err != nil {
282+ return err
283+ }
284+ }
279285 } else {
280286 pr , err = api .PullRequestForBranch (apiClient , baseRepo , branchWithOwner )
281287 if err != nil {
@@ -291,35 +297,30 @@ func prView(cmd *cobra.Command, args []string) error {
291297 }
292298
293299 if preview {
294- meta := "%s wants to merge %d commit"
295- if pr .Commits .TotalCount == 1 {
296- meta += " "
297- } else {
298- meta += "s "
299- }
300- meta += "into %s from %s"
301-
302300 out := colorableOut (cmd )
303-
304- fmt .Fprintln (out , utils .Bold (pr .Title ))
305- fmt .Fprintln (out , utils .Gray (fmt .Sprintf (meta ,
306- pr .Author .Login ,
307- pr .Commits .TotalCount ,
308- pr .BaseRefName ,
309- pr .HeadRefName ,
310- )))
311- fmt .Fprintln (out )
312- fmt .Fprintln (out , utils .RenderMarkdown (pr .Body ))
313- fmt .Fprintln (out )
314- fmt .Fprintf (out , utils .Gray ("View this PR on GitHub: %s\n " ), openURL )
315-
301+ printPrPreview (out , pr )
316302 return nil
317303 } else {
318304 fmt .Fprintf (cmd .ErrOrStderr (), "Opening %s in your browser.\n " , openURL )
319305 return utils .OpenInBrowser (openURL )
320306 }
321307}
322308
309+ func printPrPreview (out io.Writer , pr * api.PullRequest ) {
310+ fmt .Fprintln (out , utils .Bold (pr .Title ))
311+ fmt .Fprintln (out , utils .Gray (fmt .Sprintf (
312+ "%s wants to merge %s into %s from %s" ,
313+ pr .Author .Login ,
314+ utils .Pluralize (pr .Commits .TotalCount , "commit" ),
315+ pr .BaseRefName ,
316+ pr .HeadRefName ,
317+ )))
318+ fmt .Fprintln (out )
319+ fmt .Fprintln (out , utils .RenderMarkdown (pr .Body ))
320+ fmt .Fprintln (out )
321+ fmt .Fprintf (out , utils .Gray ("View this PR on GitHub: %s\n " ), pr .URL )
322+ }
323+
323324var prURLRE = regexp .MustCompile (`^https://github\.com/([^/]+)/([^/]+)/pull/(\d+)` )
324325
325326func prFromArg (apiClient * api.Client , baseRepo context.GitHubRepository , arg string ) (* api.PullRequest , error ) {
0 commit comments