diff --git a/jiradata/SearchResults.go b/jiradata/SearchResults.go index ace22136..a5077da6 100644 --- a/jiradata/SearchResults.go +++ b/jiradata/SearchResults.go @@ -777,5 +777,6 @@ type SearchResults struct { Schema JSONTypeMap `json:"schema,omitempty" yaml:"schema,omitempty"` StartAt int `json:"startAt,omitempty" yaml:"startAt,omitempty"` Total int `json:"total,omitempty" yaml:"total,omitempty"` + IsLast bool `json:"isLast,omitempty" yaml:"isLast,omitempty"` WarningMessages WarningMessages `json:"warningMessages,omitempty" yaml:"warningMessages,omitempty"` } diff --git a/search.go b/search.go index 76cde75b..8983c3d2 100644 --- a/search.go +++ b/search.go @@ -79,20 +79,36 @@ func (j *Jira) Search(sp SearchProvider) (*jiradata.SearchResults, error) { func Search(ua HttpClient, endpoint string, sp SearchProvider) (*jiradata.SearchResults, error) { req := sp.ProvideSearchRequest() - encoded, err := json.Marshal(req) - if err != nil { - return nil, err - } - uri := URLJoin(endpoint, "rest/api/2/search") - resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded)) - if err != nil { - return nil, err - } - defer resp.Body.Close() + results := &jiradata.SearchResults{} + issues := jiradata.Issues{} + for { + encoded, err := json.Marshal(req) + if err != nil { + return nil, err + } + uri := URLJoin(endpoint, "rest/api/2/search") + resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded)) + if err != nil { + return nil, err + } + + if resp.StatusCode != 200 { + return nil, responseError(resp) + } + + err = readJSON(resp.Body, results) + if err != nil { + return nil, err + } - if resp.StatusCode == 200 { - results := &jiradata.SearchResults{} - return results, readJSON(resp.Body, results) + issues = append(issues, results.Issues...) + req.StartAt = len(issues) + + if len(issues) == results.Total || results.Total == 0 { + break + } + resp.Body.Close() } - return nil, responseError(resp) + results.Issues = issues + return results, nil }