github.com/zaquestion/lab@v0.25.1/cmd/mr_close.go (about)

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/rsteube/carapace"
     7  	"github.com/spf13/cobra"
     8  	"github.com/zaquestion/lab/internal/action"
     9  	lab "github.com/zaquestion/lab/internal/gitlab"
    10  )
    11  
    12  var mrCloseCmd = &cobra.Command{
    13  	Use:              "close [remote] [<MR id or branch>]",
    14  	Short:            "Close merge request",
    15  	Example:          "lab mr close origin 10",
    16  	PersistentPreRun: labPersistentPreRun,
    17  	Run: func(cmd *cobra.Command, args []string) {
    18  		rn, id, err := parseArgsWithGitBranchMR(args)
    19  		if err != nil {
    20  			log.Fatal(err)
    21  		}
    22  
    23  		err = lab.MRClose(rn, int(id))
    24  		if err != nil {
    25  			log.Fatal(err)
    26  		}
    27  		fmt.Printf("Merge Request !%d closed\n", id)
    28  	},
    29  }
    30  
    31  func init() {
    32  	mrCmd.AddCommand(mrCloseCmd)
    33  	carapace.Gen(mrCloseCmd).PositionalCompletion(
    34  		action.Remotes(),
    35  		action.MergeRequests(mrList),
    36  	)
    37  }