From 90ef56accdce0665e29ac7f1783a732b267da1d9 Mon Sep 17 00:00:00 2001 From: Cory Bennett Date: Thu, 3 Dec 2015 11:35:51 -0800 Subject: [PATCH] add abstract request wrapper to allow you to access/process random apis supported by Jira but not yet supported by go-jira --- jira/cli/commands.go | 22 ++++++++++++++++++++++ jira/cli/templates.go | 1 + jira/main.go | 12 ++++++++++++ 3 files changed, 35 insertions(+) diff --git a/jira/cli/commands.go b/jira/cli/commands.go index 410ad40d..d4c90cc8 100644 --- a/jira/cli/commands.go +++ b/jira/cli/commands.go @@ -585,3 +585,25 @@ func (c *Cli) CmdExportTemplates() error { } return nil } + +func (c *Cli) CmdRequest(uri, content string) (err error) { + log.Debug("request called") + + if ! strings.HasPrefix(uri, "http") { + uri = fmt.Sprintf("%s%s", c.endpoint, uri) + } + + method := strings.ToUpper(c.opts["method"].(string)) + var data interface{} + if method == "GET" { + data, err = responseToJson(c.get(uri)) + } else if method == "POST" { + data, err = responseToJson(c.post(uri, content)) + } else if method == "PUT" { + data, err = responseToJson(c.put(uri, content)) + } + if err != nil { + return err + } + return runTemplate(c.getTemplate("request"), data, nil) +} diff --git a/jira/cli/templates.go b/jira/cli/templates.go index 5b19d2d1..d74abc33 100644 --- a/jira/cli/templates.go +++ b/jira/cli/templates.go @@ -16,6 +16,7 @@ var all_templates = map[string]string{ "create": default_create_template, "comment": default_comment_template, "transition": default_transition_template, + "request": default_debug_template, } const default_debug_template = "{{ . | toJson}}\n" diff --git a/jira/main.go b/jira/main.go index cfb64d4b..2c70dd62 100644 --- a/jira/main.go +++ b/jira/main.go @@ -78,6 +78,7 @@ Usage: jira export-templates [-d DIR] [-t template] jira (b|browse) ISSUE jira login + jira request [-M METHOD] URI [DATA] jira ISSUE General Options: @@ -149,6 +150,8 @@ Command Options: "export-templates": "export-templates", "browse": "browse", "login": "login", + "req": "request", + "request": "request", } defaults := map[string]interface{}{ @@ -157,6 +160,7 @@ Command Options: "directory": fmt.Sprintf("%s/.jira.d/templates", home), "sort": defaultSort, "max_results": defaultMaxResults, + "method": "GET", } opts := make(map[string]interface{}) @@ -196,6 +200,7 @@ Command Options: "edit": setopt, "m|comment=s": setopt, "d|dir|directory=s": setopt, + "M|method=s": setopt, }) if err := op.ProcessAll(os.Args[1:]); err != nil { @@ -388,6 +393,13 @@ Command Options: case "view": requireArgs(1) err = c.CmdView(args[0]) + case "request": + requireArgs(1) + data := "" + if len(args) > 1 { + data = args[1] + } + err = c.CmdRequest(args[0], data) default: log.Error("Unknown command %s", command) os.Exit(1)