mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-18 20:23:28 +02:00
add options to ls to allow for dynamically creating some simple JQL
This commit is contained in:
+35
-13
@@ -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
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user