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

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