def add_deploy_key(key_name, repo_owner, repo_name, access_token):
    url = "https://api.github.com/repos/{owner}/{repo}/keys?access_token={token}".format(owner=repo_owner, repo=repo_name, token=access_token)
    data = { 'title': os.path.basename(key_name), 'key': open(key_name+".pub").read() }
    r = requests.post(url, data=json.dumps(data))
    if r.status_code >= 300:
        raise Exception(str(json.loads(r.content.decode('utf-8'))))
dataset/ETHPy150Open RalfJung/git-mirror/github-add-hooks.py/add_deploy_key/original