github.com/zaquestion/lab@v0.25.1/cmd/mr_browse.go (about) 1 package cmd 2 3 import ( 4 "net/url" 5 "path" 6 "strconv" 7 8 "github.com/rsteube/carapace" 9 "github.com/spf13/cobra" 10 "github.com/zaquestion/lab/internal/action" 11 lab "github.com/zaquestion/lab/internal/gitlab" 12 ) 13 14 var mrBrowseCmd = &cobra.Command{ 15 Use: "browse [remote] [<MR id or branch>]", 16 Aliases: []string{"b"}, 17 Short: "View merge request in a browser", 18 Example: "lab mr browse origin", 19 PersistentPreRun: labPersistentPreRun, 20 Run: func(cmd *cobra.Command, args []string) { 21 rn, num, err := parseArgsWithGitBranchMR(args) 22 if err != nil { 23 log.Fatal(err) 24 } 25 26 host := lab.Host() 27 hostURL, err := url.Parse(host) 28 if err != nil { 29 log.Fatal(err) 30 } 31 hostURL.Path = path.Join(hostURL.Path, rn, "merge_requests") 32 hostURL.Path = path.Join(hostURL.Path, strconv.FormatInt(num, 10)) 33 34 err = browse(hostURL.String()) 35 if err != nil { 36 log.Fatal(err) 37 } 38 }, 39 } 40 41 func init() { 42 mrCmd.AddCommand(mrBrowseCmd) 43 carapace.Gen(mrBrowseCmd).PositionalCompletion( 44 action.Remotes(), 45 action.MergeRequests(mrList), 46 ) 47 }