Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Add paging to
Browse files Browse the repository at this point in the history
  • Loading branch information
maaktweluit committed Jun 13, 2019
1 parent 04bf424 commit b605b70
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions scripts/get-slow-argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,30 @@
# config vars
required_approvals = 1

_logging = False


def _log(msg, *args):
if _logging:
sys.stderr.write(msg.format(*args) + '\n')


class ApprovalError(Exception):
pass

def _get_json_data(link):
_log("_get_json_data: {}", link)
# Github API requires user agent.
req = requests.get(url, headers={'User-Agent': 'build-bot'})
json_data = req.json()

if "message" in json_data \
and json_data["message"].startswith("API rate"):

sys.stderr.write("Raw reply:{}".format(json_data))
raise ApprovalError

return req, json_data

# When build is not a PR the input is: "" or "false"
if pull_request_id not in ["", "false"]:
Expand All @@ -25,23 +45,25 @@ class ApprovalError(Exception):
url = base_url.format(pull_request_id)

try:
# Github API requires user agent.
req = requests.get(url, headers={'User-Agent': 'build-bot'})

json_data = req.json()
req, json_data = _get_json_data(url)

if "message" in json_data \
and json_data["message"].startswith("API rate"):
while 'next' in req.links:
_log("got link: {}", req.links)
url = req.links['next']['url']
req, new_json_data = _get_json_data(url)
json_data += new_json_data

sys.stderr.write("Raw reply:{}".format(json_data))
raise ApprovalError
# _log("Raw json_data: {}", json_data)

check_states = ["APPROVED", "CHANGES_REQUESTED"]
review_states = [a for a in json_data if a["state"] in check_states]
unique_reviews = {x['user']['login']: x for x in review_states}.values()
_log("unique_reviews: {}", unique_reviews)

result = [a for a in unique_reviews if a["state"] == "APPROVED"]
_log("result: {}", result)
approvals = len(result)
_log("approvals: {}", approvals)
run_slow = approvals >= required_approvals
except(requests.HTTPError, requests.Timeout, ApprovalError) as e:
sys.stderr.write("Error calling github, run all tests. {}".format(url))
Expand Down

0 comments on commit b605b70

Please # to comment.