How to use the aiogithubapi.AIOGitHubAPIException function in aiogithubapi

To help you get started, we’ve selected a few aiogithubapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hacs / integration / custom_components / hacs / helpers / get_defaults.py View on Github external
async def get_default_repos_lists(session, token, default: str) -> dict:
    """Gets repositories from default list."""
    repositories = []
    logger = Logger("hacs")

    try:
        repo = await get_repository(session, token, "hacs/default")
        content = await repo.get_contents(default)
        repositories = json.loads(content.content)

    except (AIOGitHubAPIException, HacsException) as exception:
        logger.error(exception)

    return repositories
github ikifar2012 / Home-AssistantConfig / custom_components / hacs / helpers / information.py View on Github external
async def get_info_md_content(repository):
    """Get the content of info.md"""
    filename = info_file(repository)
    if not filename:
        return ""
    try:
        info = await repository.repository_object.get_contents(filename, repository.ref)
        if info is None:
            return ""
        info = info.content.replace("
github hacs / integration / custom_components / hacs / ws_api_handlers.py View on Github external
elif action == "set_version":
            if msg["version"] == repository.data.default_branch:
                repository.data.selected_tag = None
            else:
                repository.data.selected_tag = msg["version"]
            await repository.update_repository()

            hass.bus.async_fire("hacs/reload", {"force": True})

        else:
            hacs.logger.error(f"WS action '{action}' is not valid")

        await hacs.data.async_write()
        message = None
    except AIOGitHubAPIException as exception:
        message = exception
    except AttributeError as exception:
        message = f"Could not use repository with ID {repo_id} ({exception})"
    except Exception as exception:  # pylint: disable=broad-except
        message = exception

    if message is not None:
        hacs.logger.error(message)
        hass.bus.async_fire("hacs/error", {"message": str(message)})

    repository.state = None
    connection.send_message(websocket_api.result_message(msg["id"], data))
github hacs / integration / custom_components / hacs / repositories / appdaemon.py View on Github external
async def validate_repository(self):
        """Validate."""
        await self.common_validate()

        # Custom step 1: Validate content.
        try:
            addir = await self.repository_object.get_contents("apps", self.ref)
        except AIOGitHubAPIException:
            raise HacsException(
                f"Repostitory structure for {self.ref.replace('tags/','')} is not compliant"
            )

        if not isinstance(addir, list):
            self.validate.errors.append("Repostitory structure not compliant")

        self.content.path.remote = addir[0].path
        self.content.objects = await self.repository_object.get_contents(
            self.content.path.remote, self.ref
        )

        # Handle potential errors
        if self.validate.errors:
            for error in self.validate.errors:
                if not self.hacs.system.status.startup:
github hacs / integration / custom_components / hacs / helpers / functions / register_repository.py View on Github external
try:
            await repository.async_registration(ref)
            if hacs.system.status.new:
                repository.data.new = False
            if repository.validate.errors:
                hacs.common.skip.append(repository.data.full_name)
                if not hacs.system.status.startup:
                    hacs.logger.error(f"Validation for {full_name} failed.")
                if hacs.action:
                    raise HacsException(f"::error:: Validation for {full_name} failed.")
                return repository.validate.errors
            if hacs.action:
                repository.logger.info("Validation complete")
            else:
                repository.logger.info("Registration complete")
        except AIOGitHubAPIException as exception:
            hacs.common.skip.append(repository.data.full_name)
            raise HacsException(f"Validation for {full_name} failed with {exception}.")

    exists = (
        False
        if str(repository.data.id) == "0"
        else [x for x in hacs.repositories if str(x.data.id) == str(repository.data.id)]
    )

    if exists:
        if exists[0] in hacs.repositories:
            hacs.repositories.remove(exists[0])

    else:
        if hacs.hass is not None and (
            (check and repository.data.new) or hacs.system.status.new
github hacs / integration / custom_components / hacs / helpers / functions / validate_repository.py View on Github external
# Get releases.
    try:
        releases = await get_releases(
            repository.repository_object,
            repository.data.show_beta,
            hacs.configuration.release_limit,
        )
        if releases:
            repository.data.releases = True
            repository.releases.objects = releases
            repository.data.published_tags = [
                x.tag_name for x in releases if not x.draft
            ]
            repository.data.last_version = next(iter(releases)).tag_name

    except (AIOGitHubAPIException, HacsException):
        repository.data.releases = False

    if not repository.force_branch:
        repository.ref = version_to_install(repository)
    if repository.data.releases:
        for release in releases or []:
            if release.tag_name == repository.ref:
                assets = release.assets
                if assets:
                    downloads = next(iter(assets)).attributes.get("download_count")
                    repository.data.downloads = downloads

    repository.logger.debug(
        f"Running checks against {repository.ref.replace('tags/', '')}"
    )
github hacs / integration / custom_components / hacs / helpers / functions / information.py View on Github external
async def get_info_md_content(repository):
    """Get the content of info.md"""
    filename = info_file(repository)
    if not filename:
        return ""
    try:
        info = await repository.repository_object.get_contents(filename, repository.ref)
        if info is None:
            return ""
        info = info.content.replace("
github eifinger / homeassistant-config / custom_components / hacs / ws_api_handlers.py View on Github external
repository.data.selected_tag = data
            await repository.update_repository()
            await repository.install()
            repository.state = None
            if not was_installed:
                hass.bus.async_fire("hacs/reload", {"force": True})

        elif action == "add":
            repository.state = None

        else:
            repository.state = None
            hacs.logger.error(f"WS action '{action}' is not valid")

        message = None
    except AIOGitHubAPIException as exception:
        message = exception
    except AttributeError as exception:
        message = f"Could not use repository with ID {repo_id} ({exception})"
    except Exception as exception:  # pylint: disable=broad-except
        message = exception

    if message is not None:
        hacs.logger.error(message)
        hass.bus.async_fire("hacs/error", {"message": str(exception)})

    await hacs.data.async_write()
    connection.send_message(websocket_api.result_message(msg["id"], {}))
github hacs / integration / custom_components / hacs / operational / setup.py View on Github external
async def async_startup_wrapper_for_yaml():
    """Startup wrapper for yaml config."""
    hacs = get_hacs()
    try:
        startup_result = await async_hacs_startup()
    except AIOGitHubAPIException:
        startup_result = False
    if not startup_result:
        hacs.system.disabled = True
        hacs.hass.components.frontend.async_remove_panel(
            hacs.configuration.sidepanel_title.lower()
            .replace(" ", "_")
            .replace("-", "_")
        )
        hacs.logger.info("Could not setup HACS, trying again in 15 min")
        async_call_later(hacs.hass, 900, async_startup_wrapper_for_yaml())
        return
    hacs.system.disabled = False
github hacs / integration / custom_components / hacs / operational / factory.py View on Github external
async def safe_update(self, repository):
        async with max_concurrent_tasks:
            try:
                await repository.update_repository()
            except (AIOGitHubAPIException, HacsException) as exception:
                logger.error("%s - %s", repository.data.full_name, exception)

            # Due to GitHub ratelimits we need to sleep a bit
            await asyncio.sleep(sleeper)