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