@@ -21,16 +21,17 @@ func init() {
2121 RootCmd .AddCommand (prCmd )
2222 prCmd .AddCommand (prCheckoutCmd )
2323 prCmd .AddCommand (prCreateCmd )
24- prCmd .AddCommand (prListCmd )
2524 prCmd .AddCommand (prStatusCmd )
26- prCmd .AddCommand (prViewCmd )
25+ prCmd .AddCommand (prCloseCmd )
2726
27+ prCmd .AddCommand (prListCmd )
2828 prListCmd .Flags ().IntP ("limit" , "L" , 30 , "Maximum number of items to fetch" )
2929 prListCmd .Flags ().StringP ("state" , "s" , "open" , "Filter by state: {open|closed|merged|all}" )
3030 prListCmd .Flags ().StringP ("base" , "B" , "" , "Filter by base branch" )
3131 prListCmd .Flags ().StringSliceP ("label" , "l" , nil , "Filter by label" )
3232 prListCmd .Flags ().StringP ("assignee" , "a" , "" , "Filter by assignee" )
3333
34+ prCmd .AddCommand (prViewCmd )
3435 prViewCmd .Flags ().BoolP ("web" , "w" , false , "Open a pull request in the browser" )
3536}
3637
@@ -65,6 +66,11 @@ is displayed.
6566With '--web', open the pull request in a web browser instead.` ,
6667 RunE : prView ,
6768}
69+ var prCloseCmd = & cobra.Command {
70+ Use : "close [{<number> | <url>}]" ,
71+ Short : "Close a pull request" ,
72+ RunE : prClose ,
73+ }
6874
6975func prStatus (cmd * cobra.Command , args []string ) error {
7076 ctx := contextForCommand (cmd )
@@ -328,6 +334,38 @@ func prView(cmd *cobra.Command, args []string) error {
328334 }
329335}
330336
337+ func prClose (cmd * cobra.Command , args []string ) error {
338+ ctx := contextForCommand (cmd )
339+ apiClient , err := apiClientForContext (ctx )
340+ if err != nil {
341+ return err
342+ }
343+
344+ baseRepo , err := determineBaseRepo (cmd , ctx )
345+ if err != nil {
346+ return err
347+ }
348+
349+ pr , err := prFromArg (apiClient , baseRepo , args [0 ])
350+ if err != nil {
351+ return err
352+ }
353+
354+ if pr .Closed {
355+ fmt .Fprintf (colorableErr (cmd ), "%s Pull request #%d is already closed\n " , utils .Yellow ("!" ), pr .Number )
356+ return nil
357+ }
358+
359+ err = api .PullRequestClose (apiClient , baseRepo , * pr )
360+ if err != nil {
361+ return fmt .Errorf ("API call failed:%w" , err )
362+ }
363+
364+ fmt .Fprintf (colorableErr (cmd ), "%s Closed pull request #%d\n " , utils .Red ("✔" ), pr .Number )
365+
366+ return nil
367+ }
368+
331369func printPrPreview (out io.Writer , pr * api.PullRequest ) error {
332370 // Header (Title and State)
333371 fmt .Fprintln (out , utils .Bold (pr .Title ))
0 commit comments