Skip to content

Commit

Permalink
add abstract request wrapper to allow you to access/process random apis
Browse files Browse the repository at this point in the history
supported by Jira but not yet supported by go-jira
  • Loading branch information
coryb committed Dec 3, 2015
1 parent 228d7d0 commit 90ef56a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
22 changes: 22 additions & 0 deletions jira/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions jira/cli/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions jira/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -149,6 +150,8 @@ Command Options:
"export-templates": "export-templates",
"browse": "browse",
"login": "login",
"req": "request",
"request": "request",
}

defaults := map[string]interface{}{
Expand All @@ -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{})

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 90ef56a

Please sign in to comment.