github.com/zaquestion/lab@v0.25.1/cmd/mr_thumb.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 mrThumbCmd = &cobra.Command{
    14  	Use:              "thumb",
    15  	Aliases:          []string{},
    16  	Short:            "Thumb operations on merge requests",
    17  	PersistentPreRun: labPersistentPreRun,
    18  }
    19  
    20  var mrThumbUpCmd = &cobra.Command{
    21  	Use:     "up [remote] [<MR id or branch>]",
    22  	Aliases: []string{},
    23  	Short:   "Thumb up merge request",
    24  	Example: heredoc.Doc(`
    25  		lab mr thumb up origin
    26  		lab mr thumb up origin 10`),
    27  	PersistentPreRun: labPersistentPreRun,
    28  	Run: func(cmd *cobra.Command, args []string) {
    29  		rn, id, err := parseArgsWithGitBranchMR(args)
    30  		if err != nil {
    31  			log.Fatal(err)
    32  		}
    33  
    34  		err = lab.MRThumbUp(rn, int(id))
    35  		if err != nil {
    36  			log.Fatal(err)
    37  		}
    38  		fmt.Printf("Merge Request !%d thumb'd up\n", id)
    39  	},
    40  }
    41  
    42  var mrThumbDownCmd = &cobra.Command{
    43  	Use:     "down [remote] [<MR id or branch>]",
    44  	Aliases: []string{},
    45  	Short:   "Thumbs down merge request",
    46  	Example: heredoc.Doc(`
    47  		lab mr thumb down origin
    48  		lab mr thumb down origin 10`),
    49  	Run: func(cmd *cobra.Command, args []string) {
    50  		rn, id, err := parseArgsWithGitBranchMR(args)
    51  		if err != nil {
    52  			log.Fatal(err)
    53  		}
    54  
    55  		err = lab.MRThumbDown(rn, int(id))
    56  		if err != nil {
    57  			log.Fatal(err)
    58  		}
    59  		fmt.Printf("Merge Request !%d thumb'd down\n", id)
    60  	},
    61  }
    62  
    63  func init() {
    64  	mrCmd.AddCommand(mrThumbCmd)
    65  
    66  	mrThumbCmd.AddCommand(mrThumbUpCmd)
    67  	carapace.Gen(mrThumbUpCmd).PositionalCompletion(
    68  		action.Remotes(),
    69  		action.MergeRequests(mrList),
    70  	)
    71  
    72  	mrThumbCmd.AddCommand(mrThumbDownCmd)
    73  	carapace.Gen(mrThumbDownCmd).PositionalCompletion(
    74  		action.Remotes(),
    75  		action.MergeRequests(mrList),
    76  	)
    77  }