##// END OF EJS Templates
allow params in gh_api methods
MinRK -
Show More
@@ -119,12 +119,13 b' def get_pull_request_files(project, num, auth=False):'
119 element_pat = re.compile(r'<(.+?)>')
119 element_pat = re.compile(r'<(.+?)>')
120 rel_pat = re.compile(r'rel=[\'"](\w+)[\'"]')
120 rel_pat = re.compile(r'rel=[\'"](\w+)[\'"]')
121
121
122 def get_paged_request(url, headers=None):
122 def get_paged_request(url, headers=None, **params):
123 """get a full list, handling APIv3's paging"""
123 """get a full list, handling APIv3's paging"""
124 results = []
124 results = []
125 params.setdefault("per_page", 100)
125 while True:
126 while True:
126 print("fetching %s" % url, file=sys.stderr)
127 print("fetching %s with %s" % (url, params), file=sys.stderr)
127 response = requests.get(url, headers=headers)
128 response = requests.get(url, headers=headers, params=params)
128 response.raise_for_status()
129 response.raise_for_status()
129 results.extend(response.json())
130 results.extend(response.json())
130 if 'next' in response.links:
131 if 'next' in response.links:
@@ -133,28 +134,32 b' def get_paged_request(url, headers=None):'
133 break
134 break
134 return results
135 return results
135
136
136 def get_pulls_list(project, state="closed", auth=False):
137 def get_pulls_list(project, auth=False, **params):
137 """get pull request list
138 """get pull request list"""
138 """
139 params.setdefault("state", "closed")
139 url = "https://api.github.com/repos/{project}/pulls?state={state}&per_page=100".format(project=project, state=state)
140 url = "https://api.github.com/repos/{project}/pulls".format(project=project)
140 if auth:
141 if auth:
141 headers = make_auth_header()
142 headers = make_auth_header()
142 else:
143 else:
143 headers = None
144 headers = None
144 pages = get_paged_request(url, headers=headers)
145 pages = get_paged_request(url, headers=headers, params=params)
145 return pages
146 return pages
146
147
147 def get_issues_list(project, state="closed", auth=False):
148 def get_issues_list(project, auth=False, **params):
148 """get pull request list
149 """get issues list"""
149 """
150 params.setdefault("state", "closed")
150 url = "https://api.github.com/repos/{project}/pulls?state={state}&per_page=100".format(project=project, state=state)
151 url = "https://api.github.com/repos/{project}/issues".format(project=project)
151 if auth:
152 if auth:
152 headers = make_auth_header()
153 headers = make_auth_header()
153 else:
154 else:
154 headers = None
155 headers = None
155 pages = get_paged_request(url, headers=headers)
156 pages = get_paged_request(url, headers=headers, **params)
156 return pages
157 return pages
157
158
159 def is_pull_request(issue):
160 """Return True if the given issue is a pull request."""
161 return bool(issue.get('pull_request', {}).get('html_url', None))
162
158 # encode_multipart_formdata is from urllib3.filepost
163 # encode_multipart_formdata is from urllib3.filepost
159 # The only change is to iter_fields, to enforce S3's required key ordering
164 # The only change is to iter_fields, to enforce S3's required key ordering
160
165
@@ -13,7 +13,7 b' import sys'
13
13
14 from datetime import datetime, timedelta
14 from datetime import datetime, timedelta
15 from subprocess import check_output
15 from subprocess import check_output
16 from gh_api import get_paged_request, make_auth_header, get_pull_request
16 from gh_api import get_paged_request, make_auth_header, get_pull_request, is_pull_request
17
17
18 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
19 # Globals
19 # Globals
@@ -50,12 +50,6 b' def issues2dict(issues):'
50 idict[i['number']] = i
50 idict[i['number']] = i
51 return idict
51 return idict
52
52
53
54 def is_pull_request(issue):
55 """Return True if the given issue is a pull request."""
56 return bool(issue.get('pull_request', {}).get('html_url', None))
57
58
59 def split_pulls(all_issues, project="ipython/ipython"):
53 def split_pulls(all_issues, project="ipython/ipython"):
60 """split a list of closed issues into non-PR Issues and Pull Requests"""
54 """split a list of closed issues into non-PR Issues and Pull Requests"""
61 pulls = []
55 pulls = []
General Comments 0
You need to be logged in to leave comments. Login now