Ejemplo n.º 1
0
async def test_fixture_recorder() -> None:
    async with github.AsyncGithubClient(
            auth=github_app.GithubBearerAuth()) as client:
        r = await client.get("/app")
        assert r.status_code == 200
        assert r.json()["owner"]["id"] == config.TESTING_ORGANIZATION_ID
        assert r.json()["owner"]["login"] == config.TESTING_ORGANIZATION_NAME
Ejemplo n.º 2
0
async def suspended(verb: typing.Literal["PUT", "DELETE"],
                    owner: github_types.GitHubLogin) -> None:
    async with github.AsyncGithubClient(
            auth=github_app.GithubBearerAuth()) as client:
        installation = typing.cast(
            github_types.GitHubInstallation,
            await client.item(f"/orgs/{owner}/installation"),
        )
        resp = await client.request(
            verb, f"/app/installations/{installation['id']}/suspended")
        print(resp)
Ejemplo n.º 3
0
 async def populate_with_collaborators_with_write_users_access(
         self) -> None:
     async with github.AsyncGithubClient(
             auth=github_app.GithubBearerAuth(), ) as app_client:
         async for installation in app_client.items(
                 "/app/installations",
                 resource_name="installations",
                 page_limit=100,
         ):
             installation = typing.cast(github_types.GitHubInstallation,
                                        installation)
             org = SeatAccount(installation["account"]["id"],
                               installation["account"]["login"])
             async with github.aget_client(installation) as client:
                 try:
                     async for repository in client.items(
                             "/installation/repositories",
                             list_items="repositories",
                             resource_name="repositories",
                             page_limit=100,
                     ):
                         repository = typing.cast(
                             github_types.GitHubRepository, repository)
                         repo = SeatRepository(repository["id"],
                                               repository["name"])
                         async for collaborator in client.items(
                                 f"{repository['url']}/collaborators",
                                 resource_name="collaborators",
                                 page_limit=100,
                         ):
                             if collaborator["permissions"]["push"]:
                                 seat = SeatAccount(collaborator["id"],
                                                    collaborator["login"])
                                 repo_seats = self.seats[org][repo]
                                 if repo_seats["write_users"] is None:
                                     repo_seats["write_users"] = {seat}
                                 else:
                                     repo_seats["write_users"].add(seat)
                 except exceptions.MergifyNotInstalled:
                     LOG.warning(
                         "can't retrieve collaborators with write users access",
                         account_id=installation["account"]["id"],
                         account_login=installation["account"]["login"],
                         suspended_at=installation["suspended_at"],
                         suspended_by=installation["suspended_by"],
                     )
Ejemplo n.º 4
0
async def get_installation_from_login(
    login: github_types.GitHubLogin, ) -> github_types.GitHubInstallation:
    async with AsyncGithubClient(auth=github_app.GithubBearerAuth()) as client:
        try:
            return typing.cast(
                github_types.GitHubInstallation,
                await client.item(
                    f"{config.GITHUB_REST_API_URL}/users/{login}/installation"
                ),
            )
        except http.HTTPNotFound as e:
            LOG.debug(
                "Mergify not installed",
                gh_owner=login,
                error_message=e.message,
            )
            raise exceptions.MergifyNotInstalled()