github.com/nkprince007/lab@v0.6.2-0.20171218071646-19d68b56f403/cmd/issueShow.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "log" 6 "strings" 7 "time" 8 9 "github.com/spf13/cobra" 10 "github.com/xanzy/go-gitlab" 11 "github.com/zaquestion/lab/internal/git" 12 lab "github.com/zaquestion/lab/internal/gitlab" 13 ) 14 15 var issueShowCmd = &cobra.Command{ 16 Use: "show [remote]", 17 Aliases: []string{"get"}, 18 ArgAliases: []string{"s"}, 19 Short: "Describe an issue", 20 Long: ``, 21 Run: func(cmd *cobra.Command, args []string) { 22 remote, issueNum, err := parseArgsRemote(args) 23 if err != nil { 24 log.Fatal(err) 25 } 26 if remote == "" { 27 remote = forkedFromRemote 28 } 29 rn, err := git.PathWithNameSpace(remote) 30 if err != nil { 31 log.Fatal(err) 32 } 33 34 issue, err := lab.IssueGet(rn, int(issueNum)) 35 if err != nil { 36 log.Fatal(err) 37 } 38 39 printIssue(issue, rn) 40 }, 41 } 42 43 func printIssue(issue *gitlab.Issue, project string) { 44 milestone := "None" 45 timestats := "None" 46 dueDate := "None" 47 assignee := "None" 48 state := map[string]string{ 49 "opened": "Open", 50 "closed": "Closed", 51 }[issue.State] 52 if issue.Milestone != nil { 53 milestone = issue.Milestone.Title 54 } 55 if issue.TimeStats != nil && issue.TimeStats.HumanTimeEstimate != "" && 56 issue.TimeStats.HumanTotalTimeSpent != "" { 57 timestats = fmt.Sprintf( 58 "Estimated %s, Spent %s", 59 issue.TimeStats.HumanTimeEstimate, 60 issue.TimeStats.HumanTotalTimeSpent) 61 } 62 if issue.DueDate != nil { 63 dueDate = time.Time(*issue.DueDate).String() 64 } 65 if issue.Assignee.Username != "" { 66 assignee = issue.Assignee.Username 67 } 68 69 fmt.Printf(` 70 #%d %s 71 =================================== 72 %s 73 ----------------------------------- 74 Project: %s 75 Status: %s 76 Assignee: %s 77 Author: %s 78 Milestone: %s 79 Due Date: %s 80 Time Stats: %s 81 Labels: %s 82 WebURL: %s 83 `, 84 issue.IID, issue.Title, issue.Description, project, state, assignee, 85 issue.Author.Username, milestone, dueDate, timestats, 86 strings.Join(issue.Labels, ", "), issue.WebURL, 87 ) 88 } 89 90 func init() { 91 issueCmd.AddCommand(issueShowCmd) 92 }