From 50251a550436ddd0c993570f1ea1169f1d1ada06 Mon Sep 17 00:00:00 2001 From: Kyle Dewey Date: Fri, 23 Jun 2017 23:00:45 -0700 Subject: [PATCH 1/5] added pagination for comments --- gh-issues-import.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/gh-issues-import.py b/gh-issues-import.py index ee354e0..34c0aff 100755 --- a/gh-issues-import.py +++ b/gh-issues-import.py @@ -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 len(current_result) > 0: + 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: @@ -252,7 +272,7 @@ def get_issues_by_state(which, 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 [] From 29c2c0b3125027279758bc3c986bf2033813fdf0 Mon Sep 17 00:00:00 2001 From: Kyle Dewey Date: Fri, 23 Jun 2017 23:11:23 -0700 Subject: [PATCH 2/5] using pagination for labels --- gh-issues-import.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gh-issues-import.py b/gh-issues-import.py index 34c0aff..f5b5d99 100755 --- a/gh-issues-import.py +++ b/gh-issues-import.py @@ -200,7 +200,7 @@ def send_request_paginate(which, url): while should_run: current_url = url + ("page=%s" % page_num) current_result = send_request(which, current_url) - if len(current_result) > 0: + if current_result: retval.extend(current_result) page_num += 1 else: @@ -245,7 +245,7 @@ def get_milestones(which): return send_request(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) From 3e6eae2af9bd9faec7bb313142f488883aa3dd0f Mon Sep 17 00:00:00 2001 From: Kyle Dewey Date: Fri, 23 Jun 2017 23:12:32 -0700 Subject: [PATCH 3/5] paging for milestones --- gh-issues-import.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gh-issues-import.py b/gh-issues-import.py index f5b5d99..760d2a5 100755 --- a/gh-issues-import.py +++ b/gh-issues-import.py @@ -242,7 +242,7 @@ 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_paginate(which, "labels") From 7f73c23c7d9a6b0e4a47ad70269e4a1479368781 Mon Sep 17 00:00:00 2001 From: Kyle Dewey Date: Fri, 23 Jun 2017 23:25:59 -0700 Subject: [PATCH 4/5] reimplemented get_issues_by_state in terms of send_request_paginate --- gh-issues-import.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/gh-issues-import.py b/gh-issues-import.py index 760d2a5..e6daf56 100755 --- a/gh-issues-import.py +++ b/gh-issues-import.py @@ -260,15 +260,7 @@ 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: From ce5e2b68230e28ad111e5a8ffec7613e3c047721 Mon Sep 17 00:00:00 2001 From: Kyle Dewey Date: Fri, 23 Jun 2017 23:30:11 -0700 Subject: [PATCH 5/5] tabs instead of spaces --- gh-issues-import.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gh-issues-import.py b/gh-issues-import.py index e6daf56..99ac190 100755 --- a/gh-issues-import.py +++ b/gh-issues-import.py @@ -260,7 +260,7 @@ def get_issues_by_id(which, issue_ids): # Allowed values for state are 'open' and 'closed' def get_issues_by_state(which, state): - return send_request_paginate(which, "issues?state=%s&direction=asc" % state) + return send_request_paginate(which, "issues?state=%s&direction=asc" % state) def get_comments_on_issue(which, issue): if issue['comments'] != 0: