mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-07 13:33:32 +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 {
|
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
@@ -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") {
|
||||||
|
|||||||
Reference in New Issue
Block a user