Skip to content

Commit

Permalink
Added support for the expand option for Issues
Browse files Browse the repository at this point in the history
The ```expand``` option is used to specify resource expansion in the
Jira REST API.

It's particularly useful for things like fetching the ```changelog``` of
an Issue.

This PR adds the support to the ```ListIssues``` and ```ViewIssue```
functions of the ```jira.Cli``` struct.

I'm happy to add tests, but there is currently no test suite in the
master branch, so I did not want to bog down the PR with tangential features.
  • Loading branch information
tobyjoe committed Feb 22, 2016
1 parent 7bfc6e8 commit fb4afc9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

var (
log = logging.MustGetLogger("jira")
log = logging.MustGetLogger("jira")
VERSION string
)

Expand Down Expand Up @@ -402,6 +402,10 @@ func (c *Cli) SaveData(data interface{}) error {

func (c *Cli) ViewIssue(issue string) (interface{}, error) {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s", c.endpoint, issue)
if x := c.expansions(); len(x) > 0 {
uri = fmt.Sprintf("%s?expand=%s", uri, strings.Join(x, ","))
}

data, err := responseToJson(c.get(uri))
if err != nil {
return nil, err
Expand Down Expand Up @@ -463,6 +467,7 @@ func (c *Cli) FindIssues() (interface{}, error) {
"startAt": "0",
"maxResults": c.opts["max_results"],
"fields": fields,
"expand": c.expansions(),
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -499,3 +504,12 @@ func (c *Cli) getOptBool(optName string, dflt bool) bool {
return dflt
}
}

// expansions returns a comma-separated list of values for field expansion
func (c *Cli) expansions() []string {
expansions := make([]string, 0)
if x, ok := c.opts["expand"].(string); ok {
expansions = strings.Split(x, ",")
}
return expansions
}
1 change: 1 addition & 0 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ Command Options:
"remove": setopt,
"r|reporter=s": setopt,
"f|queryfields=s": setopt,
"x|expand=s": setopt,
"s|sort=s": setopt,
"l|limit|max_results=i": setopt,
"o|override=s%": &opts,
Expand Down

0 comments on commit fb4afc9

Please sign in to comment.