Some fixes
This commit is contained in:
parent
5a2f3f98ac
commit
5927b657f9
5 changed files with 72 additions and 26 deletions
|
|
@ -16,8 +16,8 @@ type EditCmd struct {
|
||||||
file string
|
file string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEditCmd(args []string) (*CreateCmd, error) {
|
func NewEditCmd(args []string) (*EditCmd, error) {
|
||||||
ccmd := &CreateCmd{project: os.Getenv("JIRA_PROJECT")}
|
ccmd := &EditCmd{project: os.Getenv("JIRA_PROJECT")}
|
||||||
f := flag.NewFlagSet("x", flag.ExitOnError)
|
f := flag.NewFlagSet("x", flag.ExitOnError)
|
||||||
f.StringVar(&ccmd.project, "p", "", "Jira project key")
|
f.StringVar(&ccmd.project, "p", "", "Jira project key")
|
||||||
f.StringVar(&ccmd.file, "f", "filename", "File to get issue description from")
|
f.StringVar(&ccmd.file, "f", "filename", "File to get issue description from")
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,11 @@ func findRCFile() {
|
||||||
func runcmd(args []string) error {
|
func runcmd(args []string) error {
|
||||||
switch args[0] {
|
switch args[0] {
|
||||||
case "list":
|
case "list":
|
||||||
return List(flag.Args()[1:])
|
lcmd, err := NewListCmd(flag.Args()[1:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return lcmd.List()
|
||||||
case "create":
|
case "create":
|
||||||
ccmd, err := NewCreateCmd(flag.Args()[1:])
|
ccmd, err := NewCreateCmd(flag.Args()[1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,6 @@ import (
|
||||||
"otremblay.com/jkl"
|
"otremblay.com/jkl"
|
||||||
)
|
)
|
||||||
|
|
||||||
var listTemplateStr string
|
|
||||||
var listTemplate *template.Template
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
flag.StringVar(&listTemplateStr, "listTemplate", "{{.Color}}{{.Key}}{{if .Color}}\x1b[39m{{end}}\t({{.Fields.IssueType.Name}}{{if .Fields.Parent}} of {{.Fields.Parent.Key}}{{end}})\t{{.Fields.Summary}}\t[{{.Fields.Assignee.Name}}]\n", "Go template used in list command")
|
|
||||||
listTemplate = template.Must(template.New("listTemplate").Parse(listTemplateStr))
|
|
||||||
}
|
|
||||||
|
|
||||||
type listissue jkl.Issue
|
type listissue jkl.Issue
|
||||||
|
|
||||||
func (l *listissue) Color() string {
|
func (l *listissue) Color() string {
|
||||||
|
|
@ -42,14 +34,37 @@ func (l *listissue) Color() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func List(args []string) error {
|
type ListCmd struct {
|
||||||
if issues, err := jkl.List(strings.Join(args, " ")); err != nil {
|
args []string
|
||||||
|
tmplstr string
|
||||||
|
tmpl *template.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewListCmd(args []string) (*ListCmd, error) {
|
||||||
|
ccmd := &ListCmd{}
|
||||||
|
f := flag.NewFlagSet("x", flag.ExitOnError)
|
||||||
|
f.StringVar(&ccmd.tmplstr, "listTemplate", "{{.Color}}{{.Key}}{{if .Color}}\x1b[39m{{end}}\t({{.Fields.IssueType.Name}}{{if .Fields.Parent}} of {{.Fields.Parent.Key}}{{end}})\t{{.Fields.Summary}}\t{{if .Fields.Assignee}}[{{.Fields.Assignee.Name}}]{{end}}\n", "Go template used in list command")
|
||||||
|
f.Parse(args)
|
||||||
|
ccmd.args = f.Args()
|
||||||
|
if len(ccmd.args) == 0 {
|
||||||
|
proj := os.Getenv("JIRA_PROJECT")
|
||||||
|
if proj != "" {
|
||||||
|
proj = fmt.Sprintf(" and project = %s ", proj)
|
||||||
|
}
|
||||||
|
ccmd.args = []string{fmt.Sprintf("sprint in openSprints() %s order by rank", proj)}
|
||||||
|
}
|
||||||
|
ccmd.tmpl = template.Must(template.New("listTemplate").Parse(ccmd.tmplstr))
|
||||||
|
return ccmd, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListCmd) List() error {
|
||||||
|
if issues, err := jkl.List(strings.Join(l.args, " ")); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
for _, issue := range issues {
|
for _, issue := range issues {
|
||||||
var li listissue
|
var li listissue
|
||||||
li = listissue(*issue)
|
li = listissue(*issue)
|
||||||
err := listTemplate.Execute(os.Stdout, &li)
|
err := l.tmpl.Execute(os.Stdout, &li)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
31
issue.go
31
issue.go
|
|
@ -2,6 +2,7 @@ package jkl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
@ -35,6 +36,11 @@ type Status struct {
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TimeTracking struct {
|
||||||
|
OriginalEstimateSeconds int
|
||||||
|
RemainingEstimateSeconds int
|
||||||
|
}
|
||||||
|
|
||||||
type Fields struct {
|
type Fields struct {
|
||||||
*IssueType `json:"issuetype,omitempty"`
|
*IssueType `json:"issuetype,omitempty"`
|
||||||
Assignee *Author `json:",omitempty"`
|
Assignee *Author `json:",omitempty"`
|
||||||
|
|
@ -44,7 +50,27 @@ type Fields struct {
|
||||||
Comment *CommentColl `json:"comment,omitempty"`
|
Comment *CommentColl `json:"comment,omitempty"`
|
||||||
Parent *Issue `json:",omitempty"`
|
Parent *Issue `json:",omitempty"`
|
||||||
Status *Status `json:",omitempty"`
|
Status *Status `json:",omitempty"`
|
||||||
|
TimeTracking *TimeTracking `json:"timetracking,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *Fields) PrettyRemaining() string {
|
||||||
|
return PrettySeconds(f.TimeTracking.RemainingEstimateSeconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Fields) PrettyOriginalEstimate() string {
|
||||||
|
return PrettySeconds(f.TimeTracking.OriginalEstimateSeconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
func PrettySeconds(seconds int) string {
|
||||||
|
//This works because it's an integer division.
|
||||||
|
days := seconds / 3600 / 8
|
||||||
|
hours := seconds/3600 - (days * 8)
|
||||||
|
minutes := (seconds - (hours * 3600) - (days * 8 * 3600)) / 60
|
||||||
|
seconds = (seconds - (hours * 3600) - (minutes * 60) - (days * 8 * 3600))
|
||||||
|
|
||||||
|
return fmt.Sprintf("%dd %2dh %2dm %2ds", days, hours, minutes, seconds)
|
||||||
|
}
|
||||||
|
|
||||||
type Issue struct {
|
type Issue struct {
|
||||||
Key string `json:"key,omitempty"`
|
Key string `json:"key,omitempty"`
|
||||||
Fields *Fields `json:"fields"`
|
Fields *Fields `json:"fields"`
|
||||||
|
|
@ -68,8 +94,9 @@ var commentTemplate = `{{if .Fields.Comment }}{{range .Fields.Comment.Comments}}
|
||||||
{{end}}{{end}}`
|
{{end}}{{end}}`
|
||||||
|
|
||||||
var issueTmplTxt = "\x1b[1m{{.Key}}\x1b[0m\t{{if .Fields.IssueType}}[{{.Fields.IssueType.Name}}]{{end}}\t{{.Fields.Summary}}\n\n" +
|
var issueTmplTxt = "\x1b[1m{{.Key}}\x1b[0m\t{{if .Fields.IssueType}}[{{.Fields.IssueType.Name}}]{{end}}\t{{.Fields.Summary}}\n\n" +
|
||||||
"\x1b[1mStatus\x1b[0m:\t {{.Fields.Status.Name}}\n" +
|
"{{if .Fields.Status}}\x1b[1mStatus\x1b[0m:\t {{.Fields.Status.Name}}\n{{end}}" +
|
||||||
"\x1b[1mAssignee:\x1b[0m\t{{.Fields.Assignee.Name}}\n\n" +
|
"{{if .Fields.Assignee}}\x1b[1mAssignee:\x1b[0m\t{{.Fields.Assignee.Name}}\n{{end}}\n" +
|
||||||
|
"\x1b[1mTime Remaining/Original Estimate:\x1b[0m\t{{.Fields.PrettyRemaining}} / {{.Fields.PrettyOriginalEstimate}}\n\n" +
|
||||||
"\x1b[1mDescription:\x1b[0m {{.Fields.Description}} \n\n" +
|
"\x1b[1mDescription:\x1b[0m {{.Fields.Description}} \n\n" +
|
||||||
"\x1b[1mComments:\x1b[0m\n\n" + commentTemplate
|
"\x1b[1mComments:\x1b[0m\n\n" + commentTemplate
|
||||||
|
|
||||||
|
|
|
||||||
2
jkl.go
2
jkl.go
|
|
@ -24,7 +24,7 @@ func Create(issue *Issue) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println(issue)
|
// fmt.Println(issue)
|
||||||
resp, err := httpClient.Post("api/2/issue", payload)
|
resp, err := httpClient.Post("api/2/issue", payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(resp.StatusCode)
|
fmt.Println(resp.StatusCode)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue