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

Commit

Permalink
Merge pull request #4332 from golemfactory/mwu/page-slow-argument
Browse files Browse the repository at this point in the history
Add paging to get-slow-argument.py
  • Loading branch information
maaktweluit authored Jun 13, 2019
2 parents 096ae71 + 9607ea7 commit 28f453e
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions scripts/get-slow-argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# - input: pull_id from CI ( argv )
# - output: argument to use for this test ( stdout )

import os
import sys
import requests

Expand All @@ -13,35 +14,60 @@
# config vars
required_approvals = 1

_logging = os.environ.get('LOGGING', False)


class ApprovalError(Exception):
pass


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


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"]:
base_url = "https://api.github.com/" \
"repos/golemfactory/golem/pulls/{}/reviews"
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)
_log("len json_data: {}", len(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 28f453e

Please sign in to comment.