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

     1  package cmd
     2  
     3  import (
     4  	"github.com/MakeNowJust/heredoc/v2"
     5  	"github.com/spf13/cobra"
     6  	lab "github.com/zaquestion/lab/internal/gitlab"
     7  
     8  	"fmt"
     9  )
    10  
    11  var mrDeleteCmd = &cobra.Command{
    12  	Use:     "delete [remote] [<MR id or branch>]",
    13  	Aliases: []string{"del"},
    14  	Short:   "Delete a merge request on GitLab",
    15  	Long: heredoc.Doc(`
    16  		Delete a specific merge request or the one created on the default
    17  		of the main remote.`),
    18  	Args:             cobra.MaximumNArgs(2),
    19  	Example:          "lab mr delete upstream 22",
    20  	PersistentPreRun: labPersistentPreRun,
    21  	Run: func(cmd *cobra.Command, args []string) {
    22  		remote, id, err := parseArgsWithGitBranchMR(args)
    23  		if err != nil {
    24  			log.Fatal(err)
    25  		}
    26  		mrNum := int(id)
    27  
    28  		err = lab.MRDelete(remote, mrNum)
    29  		if err != nil {
    30  			log.Fatal(err)
    31  		}
    32  
    33  		fmt.Printf("Merge request #%d deleted\n", mrNum)
    34  	},
    35  }
    36  
    37  func init() {
    38  	mrCmd.AddCommand(mrDeleteCmd)
    39  }