add "rank" command allow ordering backlog issues in agile projects

This commit is contained in:
Cory Bennett
2016-08-26 19:44:38 -07:00
parent 6d23899dd5
commit e4cc9c6967
3 changed files with 78 additions and 2 deletions
+45
View File
@@ -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 {