Skip to content

Commit

Permalink
support for fetching all JQL results by way of pagination (#3304)
Browse files Browse the repository at this point in the history
  • Loading branch information
justmiles authored and arikfr committed Jan 22, 2019
1 parent c4bf446 commit ff6b20b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions redash/query_runner/jql.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def add_column(self, column, column_type=TYPE_STRING):
def to_json(self):
return json_dumps({'rows': self.rows, 'columns': self.columns.values()})

def merge(self, set):
self.rows = self.rows + set.rows

def parse_issue(issue, field_mapping):
result = OrderedDict()
Expand Down Expand Up @@ -179,6 +181,19 @@ def run_query(self, query, user):
results = parse_count(data)
else:
results = parse_issues(data, field_mapping)
index = data['startAt'] + data['maxResults']

while data['total'] > index:
query['startAt'] = index
response, error = self.get_response(jql_url, params=query)
if error is not None:
return None, error

data = response.json()
index = data['startAt'] + data['maxResults']

addl_results = parse_issues(data, field_mapping)
results.merge(addl_results)

return results.to_json(), None
except KeyboardInterrupt:
Expand Down

0 comments on commit ff6b20b

Please sign in to comment.