|
18 | 18 | github_url = os.environ.get('GITHUB_SERVER_URL', 'https://github.com')
|
19 | 19 | github_api_url = os.environ.get('GITHUB_API_URL', 'https://api.github.com')
|
20 | 20 |
|
21 |
| -def github_api_request(method, *args, **kw_args): |
22 |
| - response = github.request(method, *args, **kw_args) |
| 21 | +def github_api_request(method, *args, **kwargs): |
| 22 | + response = github.request(method, *args, **kwargs) |
23 | 23 |
|
24 | 24 | if 400 <= response.status_code < 500:
|
25 | 25 | debug(str(response.headers))
|
@@ -49,21 +49,23 @@ def debug(msg: str) -> None:
|
49 | 49 | sys.stderr.write(msg)
|
50 | 50 | sys.stderr.write('\n')
|
51 | 51 |
|
52 |
| -def prs(repo: str) -> Iterable[Dict]: |
53 |
| - url = f'{github_api_url}/repos/{repo}/pulls' |
| 52 | +def paginate(url, *args, **kwargs) -> Iterable[Dict]: |
54 | 53 |
|
55 | 54 | while True:
|
56 |
| - response = github_api_request('get', url, params={'state': 'all'}) |
| 55 | + response = github_api_request('get', url, *args, **kwargs) |
57 | 56 | response.raise_for_status()
|
58 | 57 |
|
59 |
| - for pr in response.json(): |
60 |
| - yield pr |
| 58 | + yield from response.json() |
61 | 59 |
|
62 | 60 | if 'next' in response.links:
|
63 | 61 | url = response.links['next']['url']
|
64 | 62 | else:
|
65 | 63 | return
|
66 | 64 |
|
| 65 | +def prs(repo: str) -> Iterable[Dict]: |
| 66 | + url = f'{github_api_url}/repos/{repo}/pulls' |
| 67 | + yield from paginate(url, params={'state': 'all'}) |
| 68 | + |
67 | 69 |
|
68 | 70 | def find_pr() -> str:
|
69 | 71 | """
|
@@ -152,13 +154,12 @@ def __init__(self, pr_url: str=None):
|
152 | 154 | response.raise_for_status()
|
153 | 155 |
|
154 | 156 | self._issue_url = response.json()['_links']['issue']['href'] + '/comments'
|
155 |
| - response = github_api_request('get', self._issue_url) |
156 |
| - response.raise_for_status() |
157 | 157 |
|
158 | 158 | username = current_user()
|
159 | 159 |
|
160 | 160 | debug('Looking for an existing comment:')
|
161 |
| - for comment in response.json(): |
| 161 | + |
| 162 | + for comment in paginate(self._issue_url): |
162 | 163 | debug(json.dumps(comment))
|
163 | 164 | if comment['user']['login'] == username:
|
164 | 165 | match = re.match(rf'{re.escape(self._comment_identifier)}.*```(?:hcl)?(.*?)```.*', comment['body'], re.DOTALL)
|
|
0 commit comments