mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-18 20:23:28 +02:00
add "rank" command allow ordering backlog issues in agile projects
This commit is contained in:
@@ -538,6 +538,51 @@ func (c *Cli) FindIssues() (interface{}, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
type RankOrder int
|
||||
|
||||
const (
|
||||
RANKBEFORE RankOrder = iota
|
||||
RANKAFTER RankOrder = iota
|
||||
)
|
||||
|
||||
func (c *Cli) RankIssue(issue, target string, order RankOrder) error {
|
||||
type RankRequest struct {
|
||||
Issues []string `json:"issues"`
|
||||
Before string `json:"rankBeforeIssue,omitempty"`
|
||||
After string `json:"rankAfterIssue,omitempty"`
|
||||
}
|
||||
req := &RankRequest{
|
||||
Issues: []string{
|
||||
issue,
|
||||
},
|
||||
}
|
||||
if order == RANKBEFORE {
|
||||
req.Before = target
|
||||
} else {
|
||||
req.After = target
|
||||
}
|
||||
|
||||
json, err := jsonEncode(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
uri := fmt.Sprintf("%s/rest/agile/1.0/issue/rank", c.endpoint)
|
||||
if c.getOptBool("dryrun", false) {
|
||||
log.Debugf("PUT: %s", json)
|
||||
log.Debugf("Dryrun mode, skipping PUT")
|
||||
return nil
|
||||
}
|
||||
resp, err := c.put(uri, json)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.StatusCode != 204 {
|
||||
return fmt.Errorf("failed to modify issue rank: %s", resp.Status)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetOptString will extract the string from the Cli object options
|
||||
// otherwise return the provided default
|
||||
func (c *Cli) GetOptString(optName string, dflt string) string {
|
||||
|
||||
+24
-2
@@ -135,7 +135,7 @@ func (c *Cli) CmdWorklog(action string, issue string) error {
|
||||
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/worklog", c.endpoint, issue)
|
||||
|
||||
worklogData := map[string]interface{}{
|
||||
"issue": issue,
|
||||
"issue": issue,
|
||||
"comment": c.opts["comment"],
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ func (c *Cli) CmdWorklog(action string, issue string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
if resp.StatusCode == 201 {
|
||||
c.Browse(issue)
|
||||
if !c.opts["quiet"].(bool) {
|
||||
@@ -645,6 +645,28 @@ func (c *Cli) CmdVote(issue string, up bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cli) CmdRankAfter(issue, after string) error {
|
||||
err := c.RankIssue(issue, after, RANKAFTER)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if !c.opts["quiet"].(bool) {
|
||||
fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cli) CmdRankBefore(issue, before string) error {
|
||||
err := c.RankIssue(issue, before, RANKBEFORE)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if !c.opts["quiet"].(bool) {
|
||||
fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CmdTransition will move state of the given issue to the given transtion
|
||||
func (c *Cli) CmdTransition(issue string, trans string) error {
|
||||
log.Debugf("transition called")
|
||||
|
||||
@@ -63,6 +63,7 @@ Usage:
|
||||
jira DUPLICATE dups ISSUE
|
||||
jira BLOCKER blocks ISSUE
|
||||
jira vote ISSUE [--down]
|
||||
jira rank ISSUE (after|before) ISSUE
|
||||
jira watch ISSUE [-w WATCHER] [--remove]
|
||||
jira (trans|transition) TRANSITION ISSUE [--noedit] <Edit Options>
|
||||
jira ack ISSUE [--edit] <Edit Options>
|
||||
@@ -183,6 +184,7 @@ Command Options:
|
||||
"req": "request",
|
||||
"request": "request",
|
||||
"vote": "vote",
|
||||
"rank": "rank",
|
||||
"worklog": "worklog",
|
||||
"addworklog": "addworklog",
|
||||
}
|
||||
@@ -507,6 +509,13 @@ Command Options:
|
||||
} else {
|
||||
err = c.CmdVote(args[0], true)
|
||||
}
|
||||
case "rank":
|
||||
requireArgs(3)
|
||||
if args[1] == "after" {
|
||||
err = c.CmdRankAfter(args[0], args[2])
|
||||
} else {
|
||||
err = c.CmdRankBefore(args[0], args[2])
|
||||
}
|
||||
case "request":
|
||||
requireArgs(1)
|
||||
data := ""
|
||||
|
||||
Reference in New Issue
Block a user