Skip to content

Commit

Permalink
add "rank" command allow ordering backlog issues in agile projects
Browse files Browse the repository at this point in the history
  • Loading branch information
coryb committed Aug 27, 2016
1 parent 6d23899 commit e4cc9c6
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
45 changes: 45 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 24 additions & 2 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -183,6 +184,7 @@ Command Options:
"req": "request",
"request": "request",
"vote": "vote",
"rank": "rank",
"worklog": "worklog",
"addworklog": "addworklog",
}
Expand Down Expand Up @@ -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 := ""
Expand Down

0 comments on commit e4cc9c6

Please sign in to comment.