From 9defc30534046bc61e774e5f0998fff001c538a4 2013-09-04 21:52:15 From: MinRK Date: 2013-09-04 21:52:15 Subject: [PATCH] allow params in gh_api methods --- diff --git a/tools/gh_api.py b/tools/gh_api.py index 8cd798b..22d0bed 100644 --- a/tools/gh_api.py +++ b/tools/gh_api.py @@ -119,12 +119,13 @@ def get_pull_request_files(project, num, auth=False): element_pat = re.compile(r'<(.+?)>') rel_pat = re.compile(r'rel=[\'"](\w+)[\'"]') -def get_paged_request(url, headers=None): +def get_paged_request(url, headers=None, **params): """get a full list, handling APIv3's paging""" results = [] + params.setdefault("per_page", 100) while True: - print("fetching %s" % url, file=sys.stderr) - response = requests.get(url, headers=headers) + print("fetching %s with %s" % (url, params), file=sys.stderr) + response = requests.get(url, headers=headers, params=params) response.raise_for_status() results.extend(response.json()) if 'next' in response.links: @@ -133,28 +134,32 @@ def get_paged_request(url, headers=None): break return results -def get_pulls_list(project, state="closed", auth=False): - """get pull request list - """ - url = "https://api.github.com/repos/{project}/pulls?state={state}&per_page=100".format(project=project, state=state) +def get_pulls_list(project, auth=False, **params): + """get pull request list""" + params.setdefault("state", "closed") + url = "https://api.github.com/repos/{project}/pulls".format(project=project) if auth: headers = make_auth_header() else: headers = None - pages = get_paged_request(url, headers=headers) + pages = get_paged_request(url, headers=headers, params=params) return pages -def get_issues_list(project, state="closed", auth=False): - """get pull request list - """ - url = "https://api.github.com/repos/{project}/pulls?state={state}&per_page=100".format(project=project, state=state) +def get_issues_list(project, auth=False, **params): + """get issues list""" + params.setdefault("state", "closed") + url = "https://api.github.com/repos/{project}/issues".format(project=project) if auth: headers = make_auth_header() else: headers = None - pages = get_paged_request(url, headers=headers) + pages = get_paged_request(url, headers=headers, **params) return pages +def is_pull_request(issue): + """Return True if the given issue is a pull request.""" + return bool(issue.get('pull_request', {}).get('html_url', None)) + # encode_multipart_formdata is from urllib3.filepost # The only change is to iter_fields, to enforce S3's required key ordering diff --git a/tools/github_stats.py b/tools/github_stats.py index cc1072b..fdbcd90 100755 --- a/tools/github_stats.py +++ b/tools/github_stats.py @@ -13,7 +13,7 @@ import sys from datetime import datetime, timedelta from subprocess import check_output -from gh_api import get_paged_request, make_auth_header, get_pull_request +from gh_api import get_paged_request, make_auth_header, get_pull_request, is_pull_request #----------------------------------------------------------------------------- # Globals @@ -50,12 +50,6 @@ def issues2dict(issues): idict[i['number']] = i return idict - -def is_pull_request(issue): - """Return True if the given issue is a pull request.""" - return bool(issue.get('pull_request', {}).get('html_url', None)) - - def split_pulls(all_issues, project="ipython/ipython"): """split a list of closed issues into non-PR Issues and Pull Requests""" pulls = []