Skip to content

Instantly share code, notes, and snippets.

@ahplummer
Created May 8, 2017 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahplummer/9a3fd1db7cba57fb07f0f56678fd27b5 to your computer and use it in GitHub Desktop.
Save ahplummer/9a3fd1db7cba57fb07f0f56678fd27b5 to your computer and use it in GitHub Desktop.
Paginates the JIRA API for issue retrieval
def RetrieveJiraIssuesPaginate(baseurl, key, user, password, maxper):
retval = []
base64string = base64.encodestring('%s:%s' % (user, password)).replace('\n', '')
maxResults = maxper
startAt = 0
total = 0
keepgoing = True
while keepgoing:
url = baseurl + '/rest/api/2/search?jql=project=' + key + '&maxResults=' + str(maxResults) + '&startAt=' + str(startAt)
request = urllib2.Request(url)
request.add_header("Authorization", "Basic %s" % base64string)
response = urllib2.urlopen(request)
rs = json.load(response)
totalrecs = rs['total']
for issue in rs['issues']:
total += 1
retval.append(issue['key'])
print issue['key']
startAt += maxResults
if total >= totalrecs:
keepgoing = False
return retval
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment