Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comment label milestone paging #63

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions gh-issues-import.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ def format_comment(template_data):
template = config.get('format', 'comment_template', fallback=default_template)
return format_from_template(template, template_data)

def send_request_paginate(which, url):
if "?" not in url:
url += "?"
else:
url += "&"

retval = []
page_num = 1
should_run = True

while should_run:
current_url = url + ("page=%s" % page_num)
current_result = send_request(which, current_url)
if current_result:
retval.extend(current_result)
page_num += 1
else:
should_run = False
return retval

def send_request(which, url, post_data=None):

if post_data is not None:
Expand Down Expand Up @@ -222,10 +242,10 @@ def send_request(which, url, post_data=None):
return json.loads(json_data.decode("utf-8"))

def get_milestones(which):
return send_request(which, "milestones?state=open")
return send_request_paginate(which, "milestones?state=open")

def get_labels(which):
return send_request(which, "labels")
return send_request_paginate(which, "labels")

def get_issue_by_id(which, issue_id):
return send_request(which, "issues/%d" % issue_id)
Expand All @@ -240,19 +260,11 @@ def get_issues_by_id(which, issue_ids):

# Allowed values for state are 'open' and 'closed'
def get_issues_by_state(which, state):
issues = []
page = 1
while True:
new_issues = send_request(which, "issues?state=%s&direction=asc&page=%d" % (state, page))
if not new_issues:
break
issues.extend(new_issues)
page += 1
return issues
return send_request_paginate(which, "issues?state=%s&direction=asc" % state)

def get_comments_on_issue(which, issue):
if issue['comments'] != 0:
return send_request(which, "issues/%s/comments" % issue['number'])
return send_request_paginate(which, "issues/%s/comments" % issue['number'])
else :
return []

Expand Down