Beispiel #1
0
async def reconcile_labels(repo: dict):
    """Reconcile Labels of the given Repository."""
    global endpoint
    global token

    _LOGGER.info("reconciling labels of {0}".format(repo["name"]))

    _LOGGER.debug(
        "total number of labels: '{0}', hasNextPage: {1}".format(
            repo["labels"]["totalCount"],
            repo["labels"]["pageInfo"]["hasNextPage"],
        ), )

    if repo["labels"]["pageInfo"]["hasNextPage"]:
        _LOGGER.error("for {0} we didnt get all labels!".format(repo["name"]))

    expectedLabels = {l["name"] for l in DEFAULT_LABELS}
    presentLabels = {l["name"] for l in repo["labels"]["nodes"]}
    _LOGGER.debug("expected labels: {0}".format(expectedLabels))
    _LOGGER.debug("labels present: {0}".format(presentLabels))

    missingLabels = expectedLabels - presentLabels
    _LOGGER.debug("missing labels: {0}".format(missingLabels))

    if len(missingLabels) == 0:
        _LOGGER.info("{0} does not need label reconciliation".format(
            repo["name"]))

    client = GraphQLClient(
        endpoint=f"{endpoint}/graphql",
        headers={
            "Authorization": f"Bearer {token}",
            "Accept": "application/vnd.github.bane-preview+json"
        },
    )

    for label in DEFAULT_LABELS:
        if label["name"] in missingLabels:
            mutation = CREATE_LABEL.substitute(
                id=repo["id"],
                name=label["name"],
                color=label["color"],
                desc=label["description"],
            )
            _LOGGER.debug("updating {0} in {1}, mutation: {2}".format(
                label["name"], repo["name"], mutation))

            request = GraphQLRequest(query=mutation, operation="AddLabel")
            _LOGGER.debug(request)

            response = await client.query(request=request)
            _LOGGER.debug(response)
Beispiel #2
0
async def main():
    """Call this to run the main method."""
    client = GraphQLClient(
        endpoint="https://api.github.com/graphql",
        headers={"Authorization": f"Bearer {os.environ['GITHUB_TOKEN']}"},
    )

    resp: GraphQLResponse = await client.query(request=request)
    _LOGGER.debug(resp.data)
    _LOGGER.info(f"we have fund {resp.data['search']['issueCount']} issues needing attention!")

    for issue in resp.data["search"]["edges"]:
        _LOGGER.info(issue["node"])
async def _get_repositories(login: str, cursor: str = None) -> GraphQLResponse:
    """Get Repositories and their labels based on a cursor."""
    token = os.getenv("GITHUB_ACCESS_TOKEN")
    client = GraphQLClient(endpoint="https://api.github.com/graphql",
                           headers={"Authorization": f"Bearer {token}"})

    if cursor is not None:
        request = GraphQLRequest(
            query=ALL_REPOSITORIES_INCLUDING_LABELS_CURSOR.substitute(
                login=login, cursor=cursor))
    else:
        request = GraphQLRequest(
            query=ALL_REPOSITORIES_INCLUDING_LABELS.substitute(login=login))

    return await client.query(request=request)
Beispiel #4
0
    async def v4_request(self,
                         token_type,
                         request_string,
                         installation_id=None):

        client = GraphQLClient(
            endpoint='https://api.github.com/graphql',
            headers={
                'Authorization':
                f'Bearer {await self._get_token_for_request(token_type, installation_id)}'
            },
            schema=_V4_SCHEMA,
        )
        request = GraphQLRequest(query=request_string)
        return (await client.query(request=request)).data
Beispiel #5
0
async def _get_repositories(login: str, cursor: str = None) -> GraphQLResponse:
    """Get Repositories and their labels based on a cursor."""
    global endpoint
    global token

    client = GraphQLClient(endpoint=f"{endpoint}/graphql",
                           headers={"Authorization": f"Bearer {token}"})

    if cursor is not None:
        request = GraphQLRequest(
            query=ALL_REPOSITORIES_INCLUDING_LABELS_CURSOR.substitute(
                login=login, cursor=cursor))
    else:
        request = GraphQLRequest(
            query=ALL_REPOSITORIES_INCLUDING_LABELS.substitute(login=login))

    return await client.query(request=request)
async def test_request_headers(server, headers, post, query_city):
    client = GraphQLClient(endpoint=server)
    graphql_request = GraphQLRequest(query=query_city, headers=headers)
    response = await post(client, graphql_request)
    assert isinstance(response, GraphQLResponse)
def client(server) -> GraphQLClient:
    return GraphQLClient(endpoint=server)