gitlab.com/prarit/lab@v0.14.0/cmd/mr_show.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "log" 6 "strings" 7 8 "github.com/spf13/cobra" 9 "github.com/xanzy/go-gitlab" 10 lab "github.com/zaquestion/lab/internal/gitlab" 11 ) 12 13 var mrShowCmd = &cobra.Command{ 14 Use: "show [remote] <id>", 15 Aliases: []string{"get"}, 16 ArgAliases: []string{"s"}, 17 Short: "Describe a merge request", 18 Long: ``, 19 Run: func(cmd *cobra.Command, args []string) { 20 rn, mrNum, err := parseArgs(args) 21 if err != nil { 22 log.Fatal(err) 23 } 24 25 mr, err := lab.MRGet(rn, int(mrNum)) 26 if err != nil { 27 log.Fatal(err) 28 } 29 30 printMR(mr, rn) 31 }, 32 } 33 34 func printMR(mr *gitlab.MergeRequest, project string) { 35 assignee := "None" 36 milestone := "None" 37 labels := "None" 38 state := map[string]string{ 39 "opened": "Open", 40 "closed": "Closed", 41 "merged": "Merged", 42 }[mr.State] 43 if mr.Assignee.Username != "" { 44 assignee = mr.Assignee.Username 45 } 46 if mr.Milestone != nil { 47 milestone = mr.Milestone.Title 48 } 49 if len(mr.Labels) > 0 { 50 labels = strings.Join(mr.Labels, ", ") 51 } 52 53 fmt.Printf(` 54 #%d %s 55 =================================== 56 %s 57 ----------------------------------- 58 Project: %s 59 Branches: %s->%s 60 Status: %s 61 Assignee: %s 62 Author: %s 63 Milestone: %s 64 Labels: %s 65 WebURL: %s 66 `, 67 mr.IID, mr.Title, mr.Description, project, mr.SourceBranch, 68 mr.TargetBranch, state, assignee, 69 mr.Author.Username, milestone, labels, mr.WebURL) 70 } 71 72 func init() { 73 mrCmd.AddCommand(mrShowCmd) 74 }