mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-06 21:20:48 +02:00
add "table" template to be used with "list" command
This commit is contained in:
@@ -8,6 +8,7 @@ var all_templates = map[string]string{
|
|||||||
"createmeta": default_debug_template,
|
"createmeta": default_debug_template,
|
||||||
"issuelinktypes": default_debug_template,
|
"issuelinktypes": default_debug_template,
|
||||||
"list": default_list_template,
|
"list": default_list_template,
|
||||||
|
"table": default_table_template,
|
||||||
"view": default_view_template,
|
"view": default_view_template,
|
||||||
"edit": default_edit_template,
|
"edit": default_edit_template,
|
||||||
"transitions": default_transitions_template,
|
"transitions": default_transitions_template,
|
||||||
@@ -21,6 +22,13 @@ const default_debug_template = "{{ . | toJson}}\n"
|
|||||||
|
|
||||||
const default_list_template = "{{ range .issues }}{{ .key | append \":\" | printf \"%-12s\"}} {{ .fields.summary }}\n{{ end }}"
|
const default_list_template = "{{ range .issues }}{{ .key | append \":\" | printf \"%-12s\"}} {{ .fields.summary }}\n{{ end }}"
|
||||||
|
|
||||||
|
const default_table_template =`+{{ "-" | rep 16 }}+{{ "-" | rep 57 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+
|
||||||
|
| {{ "Issue" | printf "%-14s" }} | {{ "Summary" | printf "%-55s" }} | {{ "Priority" | printf "%-12s" }} | {{ "Status" | printf "%-12s" }} | {{ "Age" | printf "%-10s" }} | {{ "Reporter" | printf "%-12s" }} | {{ "Assignee" | printf "%-12s" }} |
|
||||||
|
+{{ "-" | rep 16 }}+{{ "-" | rep 57 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+
|
||||||
|
{{ range .issues }}| {{ .key | printf "%-14s"}} | {{ .fields.summary | abbrev 55 | printf "%-55s" }} | {{.fields.priority.name | printf "%-12s" }} | {{.fields.status.name | printf "%-12s" }} | {{.fields.created | age | printf "%-10s" }} | {{.fields.reporter.name | printf "%-12s"}} | {{if .fields.assignee }}{{.fields.assignee.name | printf "%-12s" }}{{else}}<unassigned>{{end}} |
|
||||||
|
{{ end }}+{{ "-" | rep 16 }}+{{ "-" | rep 57 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+
|
||||||
|
`
|
||||||
|
|
||||||
const default_view_template = `issue: {{ .key }}
|
const default_view_template = `issue: {{ .key }}
|
||||||
created: {{ .fields.created }}
|
created: {{ .fields.created }}
|
||||||
status: {{ .fields.status.name }}
|
status: {{ .fields.status.name }}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func FindParentPaths(fileName string) []string {
|
func FindParentPaths(fileName string) []string {
|
||||||
@@ -62,6 +63,28 @@ func readFile(file string) string {
|
|||||||
return string(bytes)
|
return string(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fuzzyAge(start string) (string, error) {
|
||||||
|
if t, err := time.Parse("2006-01-02T15:04:05.000-0700", start); err != nil {
|
||||||
|
return "", err
|
||||||
|
} else {
|
||||||
|
delta := time.Now().Sub(t)
|
||||||
|
if delta.Minutes() < 2 {
|
||||||
|
return "a minute", nil
|
||||||
|
} else if dm := delta.Minutes(); dm < 45 {
|
||||||
|
return fmt.Sprintf("%d minutes", int(dm)), nil
|
||||||
|
} else if dm := delta.Minutes(); dm < 90 {
|
||||||
|
return "an hour", nil
|
||||||
|
} else if dh := delta.Hours(); dh < 24 {
|
||||||
|
return fmt.Sprintf("%d hours", int(dh)), nil
|
||||||
|
} else if dh := delta.Hours(); dh < 48 {
|
||||||
|
return "a day", nil
|
||||||
|
} else {
|
||||||
|
return fmt.Sprintf("%d days", int(delta.Hours() / 24)), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "unknown", nil
|
||||||
|
}
|
||||||
|
|
||||||
func runTemplate(templateContent string, data interface{}, out io.Writer) error {
|
func runTemplate(templateContent string, data interface{}, out io.Writer) error {
|
||||||
|
|
||||||
if out == nil {
|
if out == nil {
|
||||||
@@ -100,6 +123,25 @@ func runTemplate(templateContent string, data interface{}, out io.Writer) error
|
|||||||
"split": func(sep string, content string) []string {
|
"split": func(sep string, content string) []string {
|
||||||
return strings.Split(content, sep)
|
return strings.Split(content, sep)
|
||||||
},
|
},
|
||||||
|
"abbrev": func(max int, content string) string {
|
||||||
|
if len(content) > max {
|
||||||
|
var buffer bytes.Buffer
|
||||||
|
buffer.WriteString(content[:max-3])
|
||||||
|
buffer.WriteString("...")
|
||||||
|
return buffer.String()
|
||||||
|
}
|
||||||
|
return content
|
||||||
|
},
|
||||||
|
"rep": func(count int, content string) string {
|
||||||
|
var buffer bytes.Buffer
|
||||||
|
for i := 0; i < count; i += 1 {
|
||||||
|
buffer.WriteString(content)
|
||||||
|
}
|
||||||
|
return buffer.String()
|
||||||
|
},
|
||||||
|
"age": func(content string) (string, error) {
|
||||||
|
return fuzzyAge(content)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
if tmpl, err := template.New("template").Funcs(funcs).Parse(templateContent); err != nil {
|
if tmpl, err := template.New("template").Funcs(funcs).Parse(templateContent); err != nil {
|
||||||
log.Error("Failed to parse template: %s", err)
|
log.Error("Failed to parse template: %s", err)
|
||||||
|
|||||||
+3
-3
@@ -19,7 +19,7 @@ func main() {
|
|||||||
home := os.Getenv("HOME")
|
home := os.Getenv("HOME")
|
||||||
usage := fmt.Sprintf(`
|
usage := fmt.Sprintf(`
|
||||||
Usage:
|
Usage:
|
||||||
jira [-v ...] [-u USER] [-e URI] [-t FILE] (ls|list) ( [-q JQL] | [-p PROJECT] [-c COMPONENT] [-a ASSIGNEE] [-i ISSUETYPE] [-w WATCHER] [-r REPORTER])
|
jira [-v ...] [-u USER] [-e URI] [-t FILE] (ls|list) ( [-q JQL] | [-p PROJECT] [-c COMPONENT] [-a ASSIGNEE] [-i ISSUETYPE] [-w WATCHER] [-r REPORTER]) [-f FIELDS]
|
||||||
jira [-v ...] [-u USER] [-e URI] [-b] [-t FILE] view ISSUE
|
jira [-v ...] [-u USER] [-e URI] [-b] [-t FILE] view ISSUE
|
||||||
jira [-v ...] [-u USER] [-e URI] [-b] [-t FILE] edit ISSUE [--noedit] [-m COMMENT] [-o KEY=VAL]...
|
jira [-v ...] [-u USER] [-e URI] [-b] [-t FILE] edit ISSUE [--noedit] [-m COMMENT] [-o KEY=VAL]...
|
||||||
jira [-v ...] [-u USER] [-e URI] [-b] [-t FILE] create [--noedit] [-p PROJECT] [-i ISSUETYPE] [-o KEY=VAL]...
|
jira [-v ...] [-u USER] [-e URI] [-b] [-t FILE] create [--noedit] [-p PROJECT] [-i ISSUETYPE] [-o KEY=VAL]...
|
||||||
@@ -61,7 +61,7 @@ Command Options:
|
|||||||
-b --browse Open your browser to the Jira issue
|
-b --browse Open your browser to the Jira issue
|
||||||
-c --component=COMPONENT Component to Search for
|
-c --component=COMPONENT Component to Search for
|
||||||
-d --directory=DIR Directory to export templates to (default: %s)
|
-d --directory=DIR Directory to export templates to (default: %s)
|
||||||
-f --queryfields Fields that are used in "list" template: (default: summary)
|
-f --queryfields=FIELDS Fields that are used in "list" template: (default: summary,created,priority,status,reporter,assignee)
|
||||||
-i --issuetype=ISSUETYPE Jira Issue Type (default: Bug)
|
-i --issuetype=ISSUETYPE Jira Issue Type (default: Bug)
|
||||||
-m --comment=COMMENT Comment message for transition
|
-m --comment=COMMENT Comment message for transition
|
||||||
-o --override=KEY:VAL Set custom key/value pairs
|
-o --override=KEY:VAL Set custom key/value pairs
|
||||||
@@ -133,7 +133,7 @@ Command Options:
|
|||||||
opts["user"] = user
|
opts["user"] = user
|
||||||
}
|
}
|
||||||
if _, ok := opts["queryfields"]; !ok {
|
if _, ok := opts["queryfields"]; !ok {
|
||||||
opts["queryfields"] = "summary"
|
opts["queryfields"] = "summary,created,priority,status,reporter,assignee"
|
||||||
}
|
}
|
||||||
if _, ok := opts["directory"]; !ok {
|
if _, ok := opts["directory"]; !ok {
|
||||||
opts["directory"] = fmt.Sprintf("%s/.jira.d/templates", home)
|
opts["directory"] = fmt.Sprintf("%s/.jira.d/templates", home)
|
||||||
|
|||||||
Reference in New Issue
Block a user