(url, headers=None)
| 60 | |
| 61 | |
| 62 | def get_json(url, headers=None): |
| 63 | response = requests.get(url, headers=headers) |
| 64 | if response.status_code != 200: |
| 65 | raise ValueError(response.json()) |
| 66 | # GitHub returns a link header with the next, previous, last |
| 67 | # page if there is pagination on the response. See: |
| 68 | # https://docs.github.com/en/rest/guides/using-pagination-in-the-rest-api#using-link-headers |
| 69 | next_responses = None |
| 70 | if "link" in response.headers: |
| 71 | links = response.headers['link'].split(', ') |
| 72 | for link in links: |
| 73 | if 'rel="next"' in link: |
| 74 | # Format: '<url>; rel="next"' |
| 75 | next_url = link.split(";")[0][1:-1] |
| 76 | next_responses = get_json(next_url, headers) |
| 77 | responses = response.json() |
| 78 | if next_responses: |
| 79 | if isinstance(responses, list): |
| 80 | responses.extend(next_responses) |
| 81 | else: |
| 82 | raise ValueError('GitHub response was paginated and is not a list') |
| 83 | return responses |
| 84 | |
| 85 | |
| 86 | def run_cmd(cmd): |
no test coverage detected