Example #1
0
async def on_startup():
    """issues that do not have a project will be added to Master Backlog
    \nruns for any installation that the authorized app has access to"""
    print("Firing up.")
    await update_installations(app_installations)
    for installation in app_installations:
        token = app_installations[installation].get("token")
        headers = set_headers(token)
        await try_add_issues_to_project(headers)
        await try_add_labels_to_issues("status: in-review", headers)
Example #2
0
async def find_org_installation(org, token):
    "find all installations of the app in the particular organization"
    uri = f"https://api.github.com/orgs{org}/installation"
    headers = util.set_headers(jwt, accept_headers["machine_man_preview"],
                               True)
    response = requests.get(uri, params=None, headers=headers)
    return {
        "jwt": token,
        "status": response.reason,
        "body": response.content.decode()
    }
Example #3
0
async def get_single_installation(installation_id):
    "returns a particular installation for the application"
    gh_app = await auth_app()
    jwt = gh_app["jwt"]
    uri = f"https://api.github.com/app/installations/{installation_id}"
    headers = util.set_headers(jwt, accept_headers["machine_man_preview"],
                               True)
    response = requests.get(uri, params=None, headers=headers)
    return {
        "jwt": jwt,
        "status": response.reason,
        "body": response.content.decode()
    }
Example #4
0
async def auth_installation(installation_id):
    "authenticate as a GitHub Installation to access more advanced API"
    # for an application to authenticate as a GitHub Installation, it first must authenticate as a GitHub App
    gh_installation = await get_single_installation(installation_id)
    jwt = gh_installation["jwt"]
    app_body = json.loads(gh_installation["body"])
    uri = app_body["access_tokens_url"]
    headers = util.set_headers(jwt, accept_headers["machine_man_preview"],
                               True)
    response = requests.post(uri, data=None, headers=headers)
    # status is Created if the app was authorized successfully
    # return the installation token that can be used to access more advanced endpoints
    return {"status": response.reason, "body": response.content.decode()}
Example #5
0
async def find_all_installations():
    "find all installations for the authenticated application"
    gh_app = await auth_app()
    jwt = gh_app["jwt"]
    uri = "https://api.github.com/app/installations"
    headers = util.set_headers(jwt, accept_headers["machine_man_preview"],
                               True)
    response = requests.get(uri, params=None, headers=headers)
    # return the token and the response body
    # the token may be needed for additional authentication
    return {
        "jwt": jwt,
        "status": response.reason,
        "body": response.content.decode()
    }
Example #6
0
async def auth_app():
    "authenticate as a GitHub application to access high level API"
    token = get_jwt_token_bytes().decode()
    uri = "https://api.github.com/app"
    headers = util.set_headers(token, accept_headers["machine_man_preview"],
                               True)
    response = requests.get(uri, params=None, headers=headers)
    # status is OK if the app is authenticated and Not Found if something went wrong
    # return the token and the response body
    # the token may be needed for additional authentication
    return {
        "jwt": token,
        "status": response.reason,
        "body": response.content.decode()
    }
Example #7
0
async def laebelled_issue_evt(event, token, *args, **kwargs):
    headers = set_headers(token)
    await labelled_issue(event, headers)
Example #8
0
async def opened_issue_evt(event, token, *args, **kwargs):
    headers = set_headers(token)
    await opened_issue(event, headers)