From 8645ef11f124c84f1d7a3e34abfe163379f28e28 Mon Sep 17 00:00:00 2001 From: Mike Pountney Date: Thu, 31 Dec 2015 11:52:55 -0800 Subject: [PATCH 1/3] go fmt --- cli.go | 2 +- main/main.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli.go b/cli.go index 9331ffd..e5de4e9 100644 --- a/cli.go +++ b/cli.go @@ -19,7 +19,7 @@ import ( ) var ( - log = logging.MustGetLogger("jira") + log = logging.MustGetLogger("jira") VERSION string ) diff --git a/main/main.go b/main/main.go index 17f6f5c..8d446d0 100644 --- a/main/main.go +++ b/main/main.go @@ -14,8 +14,8 @@ import ( ) var ( - log = logging.MustGetLogger("jira") - format = "%{color}%{time:2006-01-02T15:04:05.000Z07:00} %{level:-5s} [%{shortfile}]%{color:reset} %{message}" + log = logging.MustGetLogger("jira") + format = "%{color}%{time:2006-01-02T15:04:05.000Z07:00} %{level:-5s} [%{shortfile}]%{color:reset} %{message}" ) func main() { From a92a93b282e235df0e5b5a472bde736fed06abc5 Mon Sep 17 00:00:00 2001 From: Mike Pountney Date: Thu, 31 Dec 2015 12:03:22 -0800 Subject: [PATCH 2/3] Add exposed versions of getTemplate and runTemplate GetTemplate and RunTemplate allow external users to access the template system, and in particular allow them to provide their own Buffer to write the output to. I've implemented exposed versions calling the private functions, rather than breaking the internal API. If this isn't a concern, we should remove getTemplate and runTemplate in a future commit. --- cli.go | 4 ++++ util.go | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cli.go b/cli.go index e5de4e9..312dfea 100644 --- a/cli.go +++ b/cli.go @@ -177,6 +177,10 @@ func (c *Cli) makeRequest(req *http.Request) (resp *http.Response, err error) { return resp, nil } +func (c *Cli) GetTemplate(name string) string { + return c.getTemplate(name) +} + func (c *Cli) getTemplate(name string) string { if override, ok := c.opts["template"].(string); ok { if _, err := os.Stat(override); err == nil { diff --git a/util.go b/util.go index 4c76c05..382e4c7 100644 --- a/util.go +++ b/util.go @@ -109,8 +109,11 @@ func dateFormat(format string, content string) (string, error) { } } -func runTemplate(templateContent string, data interface{}, out io.Writer) error { +func RunTemplate(templateContent string, data interface{}, out io.Writer) error { + return runTemplate(templateContent, data, out) +} +func runTemplate(templateContent string, data interface{}, out io.Writer) error { if out == nil { out = os.Stdout } From f349e25bb92b3e7b8159e6ac5647e078a3f0a69e Mon Sep 17 00:00:00 2001 From: Mike Pountney Date: Thu, 31 Dec 2015 12:06:04 -0800 Subject: [PATCH 3/3] Expose ViewTicket as per FindIssues This allows external users of the API to retreive issue details, in the same manner that FindIssues provides for lists of issues. --- cli.go | 10 ++++++++++ commands.go | 4 +--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cli.go b/cli.go index 312dfea..54d0fb7 100644 --- a/cli.go +++ b/cli.go @@ -368,6 +368,16 @@ func (c *Cli) SaveData(data interface{}) error { return nil } +func (c *Cli) ViewIssue(issue string) (interface{}, error) { + uri := fmt.Sprintf("%s/rest/api/2/issue/%s", c.endpoint, issue) + data, err := responseToJson(c.get(uri)) + if err != nil { + return nil, err + } else { + return data, nil + } +} + func (c *Cli) FindIssues() (interface{}, error) { var query string var ok bool diff --git a/commands.go b/commands.go index 64d25df..5a85581 100644 --- a/commands.go +++ b/commands.go @@ -80,12 +80,10 @@ func (c *Cli) CmdList() error { func (c *Cli) CmdView(issue string) error { log.Debug("view called") c.Browse(issue) - uri := fmt.Sprintf("%s/rest/api/2/issue/%s", c.endpoint, issue) - data, err := responseToJson(c.get(uri)) + data, err := c.ViewIssue(issue) if err != nil { return err } - return runTemplate(c.getTemplate("view"), data, nil) }