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 48ee9ae8ba
commit 60e4925fe4
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 { func (c *Cli) CmdList() error {
log.Debug("list called") log.Debug("list called")
if query, ok := c.opts["query"]; !ok { var query string
log.Error("No query argument found, either use --query or set query attribute in .jira file") var ok bool
return fmt.Errorf("Missing query") // project = BAKERY and status not in (Resolved, Closed)
} else { if query, ok = c.opts["query"]; !ok {
json, err := jsonEncode(map[string]string{ qbuff := bytes.NewBufferString("status not in (Resolved, Closed)")
"jql": query, if project, ok := c.opts["project"]; !ok {
"startAt": "0", err := fmt.Errorf("Missing required arguments, either 'query' or 'project' are required")
"maxResults": "500", log.Error("%s", err)
}); if err != nil {
return err return err
} else {
qbuff.WriteString(fmt.Sprintf(" AND project = '%s'", project))
} }
uri := fmt.Sprintf("%s/rest/api/2/search", c.endpoint) if component, ok := c.opts["component"]; ok {
data, err := responseToJson(c.post(uri, json)); if err != nil { qbuff.WriteString(fmt.Sprintf(" AND component = '%s'", component))
return err
} }
return runTemplate(c.getTemplate(".jira.d/templates/list", default_list_template), data, nil) if assignee, ok := c.opts["assignee"]; ok {
qbuff.WriteString(fmt.Sprintf(" AND assignee = '%s'", assignee))
}
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 { func (c *Cli) CmdView(issue string) error {
+10 -12
View File
@@ -20,7 +20,7 @@ func main() {
Usage: Usage:
jira [-v ...] [-u USER] [-e URI] [-t FILE] fields 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] 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] view ISSUE
jira [-v ...] [-u USER] [-e URI] [-t FILE] issuelinktypes jira [-v ...] [-u USER] [-e URI] [-t FILE] issuelinktypes
jira [-v ...] [-u USER] [-e URI] [-t FILE] transmeta ISSUE 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) -e --endpoint=URI URI to use for jira (default: https://jira)
-t --template=FILE Template file to use for output/editing -t --template=FILE Template file to use for output/editing
List Options: Command Options:
-q --query=JQL Jira Query Language expression for the search -a --assignee=USER Username assigned the issue
-q --query=JQL Jira Query Language expression for the search
Create Options: -c --component=COMPONENT Component to Search for
-p --project=PROJECT Jira Project Name -p --project=PROJECT Project to Search for
-i --issuetype=ISSUETYPE Jira Issue Type (default: Bug) -i --issuetype=ISSUETYPE Jira Issue Type (default: Bug)
-o --override=KEY:VAL Set custom key/value pairs -o --override=KEY:VAL Set custom key/value pairs
Watch Options:
-w --watcher=USER Watcher to add to issue (default: %s) -w --watcher=USER Watcher to add to issue (default: %s)
Transition Options:
-m --comment=COMMENT Comment message for transition -m --comment=COMMENT Comment message for transition
`, user, user) `, 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) logBackend := logging.NewLogBackend(os.Stderr, "", 0)
logging.SetBackend( logging.SetBackend(
logging.NewBackendFormatter( logging.NewBackendFormatter(
@@ -152,7 +151,6 @@ Transition Options:
return dflt return dflt
} }
var err error
if validCommand("login") { if validCommand("login") {
err = c.CmdLogin() err = c.CmdLogin()
} else if validCommand("fields") { } else if validCommand("fields") {