def travis():
signature = base64.b64decode(request.headers.get('Signature'))
try:
public_key = _get_travis_public_key()
except requests.Timeout:
print("Timed out when attempting to retrieve Travis CI public key")
abort(500)
except requests.RequestException as e:
print("Failed to retrieve Travis CI public key")
abort(500)
try:
check_authorized(signature, public_key, request.form["payload"])
except SignatureError:
abort(401)
data = json.loads(request.form["payload"])
repo = data["repository"]["owner_name"] + "/" + data["repository"]["name"]
build_number = data["id"]
sha = data["commit"]
if data["type"] == "pull_request":
sha = data["head_commit"]
tag = None
if data["type"] == "push" and data["tag"] != None:
tag = data["tag"]
print(data)
key = sha
if tag is not None:
key = tag
upload_lock = "upload-lock:" + sha
if data["state"] in ("started", ):
print("travis started", key)
# Handle pulls differently.
if data["pull_request"]:
load_code.delay(repo, "pull/" + str(data["pull_request_number"]) + "/head")
elif data["tag"]:
load_code.delay(repo, "refs/tags/" + tag)
else:
load_code.delay(repo, "refs/heads/" + data["branch"])
redis.setex(upload_lock, 20 * 60, "locked")
set_status(repo, sha, "pending", data["build_url"], "Waiting on Travis to complete.")
elif data["state"] in ("passed", "failed"):
print("travis finished")
key = repo + "/" + key
set_status(repo, sha, "pending", "https://rosie-ci.ngrok.io/log/" + key, "Queueing Rosie test.")
redis.delete(upload_lock)
test_commit(repo, sha, tag)
elif data["state"] is ("cancelled", ):
print("travis cancelled")
redis.delete(upload_lock)
set_status(repo, sha, "error", data["build_url"], "Travis cancelled.")
elif data["status"] is None:
set_status(repo, sha, "error", data["build_url"], "Travis error.")
else:
print("unhandled state:", data["state"])
print(data)
return jsonify({'status': 'received'})
评论列表
文章目录