github.com/zaquestion/lab@v0.25.1/cmd/todo_mr.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 6 "github.com/MakeNowJust/heredoc/v2" 7 "github.com/spf13/cobra" 8 lab "github.com/zaquestion/lab/internal/gitlab" 9 ) 10 11 var todoMRCmd = &cobra.Command{ 12 Use: "mr [remote] <id>", 13 Short: "Add a Merge Request to Todo list", 14 Example: heredoc.Doc(` 15 lab todo mr 1234 #adds MR 1234 to user's Todo list 16 lab todo mr otherRemote 5678`), 17 PersistentPreRun: labPersistentPreRun, 18 Run: func(cmd *cobra.Command, args []string) { 19 rn, num, err := parseArgsRemoteAndID(args) 20 if err != nil { 21 log.Fatal(err) 22 } 23 24 todoAddMergeRequest(rn, int(num)) 25 }, 26 } 27 28 func todoAddMergeRequest(remote string, mrNum int) { 29 todoID, err := lab.TodoMRCreate(remote, mrNum) 30 if err != nil { 31 if err == lab.ErrNotModified { 32 log.Fatalf("Todo entry already exists for MR !%d", mrNum) 33 } 34 log.Fatal(err) 35 } 36 37 mr, err := lab.MRGet(remote, mrNum) 38 if err != nil { 39 log.Fatal(err) 40 } 41 fmt.Println(todoID, mr.WebURL) 42 } 43 44 func init() { 45 todoCmd.AddCommand(todoMRCmd) 46 }