add options to ls to allow for dynamically creating some simple JQL

This commit is contained in:
Cory Bennett
2015-02-13 13:16:18 -08:00
parent e433c536c0
commit 618af1a6e1
2 changed files with 45 additions and 25 deletions
+35 -13
View File
@@ -57,25 +57,47 @@ func (c *Cli) CmdFields() error {
func (c *Cli) CmdList() error {
log.Debug("list called")
if query, ok := c.opts["query"]; !ok {
log.Error("No query argument found, either use --query or set query attribute in .jira file")
return fmt.Errorf("Missing query")
} else {
json, err := jsonEncode(map[string]string{
"jql": query,
"startAt": "0",
"maxResults": "500",
}); if err != nil {
var query string
var ok bool
// project = BAKERY and status not in (Resolved, Closed)
if query, ok = c.opts["query"]; !ok {
qbuff := bytes.NewBufferString("status not in (Resolved, Closed)")
if project, ok := c.opts["project"]; !ok {
err := fmt.Errorf("Missing required arguments, either 'query' or 'project' are required")
log.Error("%s", err)
return err
} else {
qbuff.WriteString(fmt.Sprintf(" AND project = '%s'", project))
}
if component, ok := c.opts["component"]; ok {
qbuff.WriteString(fmt.Sprintf(" AND component = '%s'", component))
}
uri := fmt.Sprintf("%s/rest/api/2/search", c.endpoint)
data, err := responseToJson(c.post(uri, json)); if err != nil {
return err
if assignee, ok := c.opts["assignee"]; ok {
qbuff.WriteString(fmt.Sprintf(" AND assignee = '%s'", assignee))
}
return runTemplate(c.getTemplate(".jira.d/templates/list", default_list_template), data, nil)
if issuetype, ok := c.opts["issuetype"]; ok {
qbuff.WriteString(fmt.Sprintf(" AND issuetype = '%s'", issuetype))
}
query = qbuff.String()
}
json, err := jsonEncode(map[string]string{
"jql": query,
"startAt": "0",
"maxResults": "500",
}); if err != nil {
return err
}
uri := fmt.Sprintf("%s/rest/api/2/search", c.endpoint)
data, err := responseToJson(c.post(uri, json)); if err != nil {
return err
}
return runTemplate(c.getTemplate(".jira.d/templates/list", default_list_template), data, nil)
}
func (c *Cli) CmdView(issue string) error {
+10 -12
View File
@@ -20,7 +20,7 @@ func main() {
Usage:
jira [-v ...] [-u USER] [-e URI] [-t FILE] fields
jira [-v ...] [-u USER] [-e URI] [-t FILE] login
jira [-v ...] [-u USER] [-e URI] [-t FILE] (ls|list) [-q JQL]
jira [-v ...] [-u USER] [-e URI] [-t FILE] (ls|list) ( [-q JQL] | [-p PROJECT] [-c COMPONENT] [-a ASSIGNEE] [-i ISSUETYPE])
jira [-v ...] [-u USER] [-e URI] [-t FILE] view ISSUE
jira [-v ...] [-u USER] [-e URI] [-t FILE] issuelinktypes
jira [-v ...] [-u USER] [-e URI] [-t FILE] transmeta ISSUE
@@ -53,23 +53,22 @@ General Options:
-e --endpoint=URI URI to use for jira (default: https://jira)
-t --template=FILE Template file to use for output/editing
List Options:
-q --query=JQL Jira Query Language expression for the search
Create Options:
-p --project=PROJECT Jira Project Name
Command Options:
-a --assignee=USER Username assigned the issue
-q --query=JQL Jira Query Language expression for the search
-c --component=COMPONENT Component to Search for
-p --project=PROJECT Project to Search for
-i --issuetype=ISSUETYPE Jira Issue Type (default: Bug)
-o --override=KEY:VAL Set custom key/value pairs
Watch Options:
-w --watcher=USER Watcher to add to issue (default: %s)
Transition Options:
-m --comment=COMMENT Comment message for transition
`, user, user)
args, _ := docopt.Parse(usage, nil, true, "0.0.1", false, false)
args, err := docopt.Parse(usage, nil, true, "0.0.1", false, false); if err != nil {
log.Error("Failed to parse options: %s", err)
os.Exit(1)
}
logBackend := logging.NewLogBackend(os.Stderr, "", 0)
logging.SetBackend(
logging.NewBackendFormatter(
@@ -152,7 +151,6 @@ Transition Options:
return dflt
}
var err error
if validCommand("login") {
err = c.CmdLogin()
} else if validCommand("fields") {