Esempio n. 1
0
    async def execute(self):
        self.aiogithub = AIOGitHub(self.token, self.session)
        self.repository = await self.aiogithub.get_repo(
            self.event_data["repository"]["full_name"])

        self.submitter = self.event_data["sender"]["login"]
        self.action = self.event_data["action"]

        if self.event_data.get("pull_request") is not None:
            print("We now know that this is a PR.")
            self.issue_type = "pr"
            self.submitter = self.event_data["pull_request"]["user"]["login"]
            self.issue_number = self.event_data["pull_request"]["number"]

        elif self.event_data.get("issue") is not None:
            print("We now know that this is a issue.")
            self.issue_type = "issue"
            self.issue_number = self.event_data["issue"]["number"]

        self.issue_comment = IssueComment(self.issue_number, self.repository)
        self.issue_update = IssueUpdate(self.issue_number, self.repository)

        if self.issue_type == "pr":
            self.status = Status(self.event_data, self.session, self.token)
            await handle_pull_request(self)
        elif self.issue_type == "issue":
            await handle_issue(self)

        await self.issue_update.update()
Esempio n. 2
0
async def get_repository(session, token, repository_full_name):
    """Return a repository object or None."""
    try:
        github = AIOGitHub(token, session)
        repository = await github.get_repo(repository_full_name)
        return repository
    except AIOGitHubException as exception:
        raise HacsException(exception)
Esempio n. 3
0
async def example():
    """Example usage of pyhaversion."""
    async with aiohttp.ClientSession() as session:
        aiogithub = AIOGitHub(TOKEN, session)
        repository = await aiogithub.get_repo("ludeeus/aiogithubapi")

        print("Ratelimit remaining:", aiogithub.ratelimits.remaining)
        print("Ratelimit reset UTC:", aiogithub.ratelimits.reset_utc)
        print("Repository description:", repository.description)
Esempio n. 4
0
 async def _test_token(self, token):
     """Return true if token is valid."""
     try:
         session = aiohttp_client.async_get_clientsession(self.hass)
         client = AIOGitHub(token, session)
         await client.get_repo("hacs/org")
         return True
     except (AIOGitHubException, AIOGitHubAuthentication) as exception:
         _LOGGER.error(exception)
     return False
Esempio n. 5
0
 async def _test_token(self, token):
     """Return true if token is valid."""
     try:
         session = aiohttp_client.async_get_clientsession(self.hass)
         client = AIOGitHub(token, session)
         await client.get_repo("custom-components/hacs")
         return True
     except (AIOGitHubException, AIOGitHubAuthentication):
         pass
     return False
Esempio n. 6
0
async def validate_repository(repository, category, ref=None):
    """Validate."""
    async with aiohttp.ClientSession() as session:
        hacs = get_hacs()
        hacs.session = session
        hacs.configuration = Configuration()
        hacs.configuration.token = TOKEN
        hacs.github = AIOGitHub(hacs.configuration.token, hacs.session)
        await register_repository(repository, category, ref=ref)
        print("All good!")
Esempio n. 7
0
async def preflight():
    """Preflight cheks."""
    ref = None
    if os.getenv("GITHUB_REPOSITORY") == "hacs/default":
        categoty = chose_category()
        repository = chose_repository(category)
        print(f"Actor: {GITHUB_ACTOR}")
    else:
        category = os.getenv("INPUT_CATEGORY")
        event_data = get_event_data()
        pr = True if event_data.get("pull_request") is not None else False
        if not pr:
            repository = os.getenv("GITHUB_REPOSITORY")
        else:
            head = event_data["pull_request"]["head"]
            ref = head["ref"]
            repository = head["repo"]["full_name"]

    print(f"Category: {category}")
    print(f"Repository: {repository}")

    if TOKEN is None:
        print("No GitHub token found, use env GITHUB_TOKEN to set this.")
        exit(1)

    if repository is None:
        print("No repository found, use env REPOSITORY to set this.")
        exit(1)

    if category is None:
        print("No category found, use env CATEGORY to set this.")
        exit(1)

    async with aiohttp.ClientSession() as session:
        github = AIOGitHub(TOKEN, session)
        repo = await github.get_repo(repository)
        if not pr and repo.description is None:
            print("Repository is missing description")
            exit(1)
        if not pr and not repo.attributes["has_issues"]:
            print("Repository does not have issues enabled")
            exit(1)

    await validate_repository(repository, category, ref)
async def hacs_startup(hacs):
    """HACS startup tasks."""
    lovelace_info = await system_health_info(hacs.hass)
    hacs.logger.debug(f"Configuration type: {hacs.configuration.config_type}")
    hacs.version = VERSION
    hacs.logger.info(STARTUP)
    hacs.system.config_path = hacs.hass.config.path()
    hacs.system.ha_version = HAVERSION

    hacs.system.lovelace_mode = lovelace_info.get("mode", "yaml")
    hacs.system.disabled = False
    hacs.github = AIOGitHub(hacs.configuration.token,
                            async_create_clientsession(hacs.hass))
    hacs.data = HacsData()

    # Check HACS Constrains
    if not check_constans(hacs):
        if hacs.configuration.config_type == "flow":
            if hacs.configuration.config_entry is not None:
                await async_remove_entry(hacs.hass,
                                         hacs.configuration.config_entry)
        return False

    # Set up frontend
    await setup_frontend(hacs)

    # Set up sensor
    add_sensor(hacs)

    # Load HACS
    if not await load_hacs_repository(hacs):
        if hacs.configuration.config_type == "flow":
            if hacs.configuration.config_entry is not None:
                await async_remove_entry(hacs.hass,
                                         hacs.configuration.config_entry)
        return False

    # Restore from storefiles
    if not await hacs.data.restore():
        hacs_repo = hacs().get_by_name("hacs/integration")
        hacs_repo.pending_restart = True
        if hacs.configuration.config_type == "flow":
            if hacs.configuration.config_entry is not None:
                await async_remove_entry(hacs.hass,
                                         hacs.configuration.config_entry)
        return False

    # Add aditional categories
    if hacs.configuration.appdaemon:
        ELEMENT_TYPES.append("appdaemon")
    if hacs.configuration.python_script:
        ELEMENT_TYPES.append("python_script")
    if hacs.configuration.theme:
        ELEMENT_TYPES.append("theme")
    hacs.common.categories = sorted(ELEMENT_TYPES)

    # Setup startup tasks
    if hacs.configuration.config_type == "yaml":
        hacs.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START,
                                        hacs().startup_tasks())
    else:
        async_call_later(hacs.hass, 5, hacs().startup_tasks())

    # Mischief managed!
    return True
Esempio n. 9
0
async def hacs_startup(hacs):
    """HACS startup tasks."""
    if hacs.configuration.debug:
        try:
            await hacs.hass.services.async_call(
                "logger", "set_level", {"hacs": "debug"}
            )
        except ServiceNotFound:
            hacs.logger.error(
                "Could not set logging level to debug, logger is not enabled"
            )

    lovelace_info = await system_health_info(hacs.hass)
    hacs.logger.debug(f"Configuration type: {hacs.configuration.config_type}")
    hacs.version = VERSION
    hacs.logger.info(STARTUP)
    hacs.system.config_path = hacs.hass.config.path()
    hacs.system.ha_version = HAVERSION

    hacs.system.lovelace_mode = lovelace_info.get("mode", "yaml")
    hacs.system.disabled = False
    hacs.github = AIOGitHub(
        hacs.configuration.token, async_create_clientsession(hacs.hass)
    )
    hacs.data = HacsData()

    # Check HACS Constrains
    if not await hacs.hass.async_add_executor_job(check_constans, hacs):
        if hacs.configuration.config_type == "flow":
            if hacs.configuration.config_entry is not None:
                await async_remove_entry(hacs.hass, hacs.configuration.config_entry)
        return False

    # Set up frontend
    await setup_frontend(hacs)

    # Set up sensor
    await hacs.hass.async_add_executor_job(add_sensor, hacs)

    # Load HACS
    if not await load_hacs_repository(hacs):
        if hacs.configuration.config_type == "flow":
            if hacs.configuration.config_entry is not None:
                await async_remove_entry(hacs.hass, hacs.configuration.config_entry)
        return False

    # Restore from storefiles
    if not await hacs.data.restore():
        hacs_repo = hacs().get_by_name("hacs/integration")
        hacs_repo.pending_restart = True
        if hacs.configuration.config_type == "flow":
            if hacs.configuration.config_entry is not None:
                await async_remove_entry(hacs.hass, hacs.configuration.config_entry)
        return False

    # Add aditional categories
    hacs.common.categories = ELEMENT_TYPES
    if hacs.configuration.appdaemon:
        hacs.common.categories.append("appdaemon")
    if hacs.configuration.python_script:
        hacs.configuration.python_script = False
        if hacs.configuration.config_type == "yaml":
            hacs.logger.warning(
                "Configuration option 'python_script' is deprecated and you should remove it from your configuration, HACS will know if you use 'python_script' in your Home Assistant configuration, this option will be removed in a future release."
            )
    if hacs.configuration.theme:
        hacs.configuration.theme = False
        if hacs.configuration.config_type == "yaml":
            hacs.logger.warning(
                "Configuration option 'theme' is deprecated and you should remove it from your configuration, HACS will know if you use 'theme' in your Home Assistant configuration, this option will be removed in a future release."
            )

    await hacs.hass.async_add_executor_job(setup_extra_stores, hacs)

    # Setup startup tasks
    if hacs.configuration.config_type == "yaml":
        hacs.hass.bus.async_listen_once(
            EVENT_HOMEASSISTANT_START, hacs().startup_tasks()
        )
    else:
        async_call_later(hacs.hass, 5, hacs().startup_tasks())

    # Mischief managed!
    return True
Esempio n. 10
0
async def hacs_startup(hacs):
    """HACS startup tasks."""
    hacs.logger.debug(f"Configuration type: {hacs.configuration.config_type}")
    hacs.version = const.VERSION
    hacs.logger.info(const.STARTUP)
    hacs.system.config_path = hacs.hass.config.path()
    hacs.system.ha_version = HAVERSION
    hacs.system.disabled = False
    hacs.github = AIOGitHub(
        hacs.configuration.token, async_create_clientsession(hacs.hass)
    )
    hacs.data = HacsData()

    # Check minimum version
    if not check_version(hacs):
        if hacs.configuration.config_type == "flow":
            if hacs.configuration.config_entry is not None:
                await async_remove_entry(hacs.hass, hacs.configuration.config_entry)
        return False

    # Check custom_updater
    if not check_custom_updater(hacs):
        if hacs.configuration.config_type == "flow":
            if hacs.configuration.config_entry is not None:
                await async_remove_entry(hacs.hass, hacs.configuration.config_entry)
        return False

    # Set up frontend
    await setup_frontend(hacs)

    # Load HACS
    if not await load_hacs_repository(hacs):
        if hacs.configuration.config_type == "flow":
            if hacs.configuration.config_entry is not None:
                await async_remove_entry(hacs.hass, hacs.configuration.config_entry)
        return False

    val = ValidateData()
    if not val.validate_local_data_file():
        if hacs.configuration.config_type == "flow":
            if hacs.configuration.config_entry is not None:
                await async_remove_entry(hacs.hass, hacs.configuration.config_entry)
        return False
    else:
        if os.path.exists(f"{hacs.system.config_path}/.storage/hacs"):
            os.remove(f"{hacs.system.config_path}/.storage/hacs")

    # Restore from storefiles
    if not await hacs.data.restore():
        hacs_repo = hacs().get_by_name("custom-components/hacs")
        hacs_repo.pending_restart = True
        if hacs.configuration.config_type == "flow":
            if hacs.configuration.config_entry is not None:
                await async_remove_entry(hacs.hass, hacs.configuration.config_entry)
        return False

    # Add aditional categories
    if hacs.configuration.appdaemon:
        const.ELEMENT_TYPES.append("appdaemon")
    if hacs.configuration.python_script:
        const.ELEMENT_TYPES.append("python_script")
    if hacs.configuration.theme:
        const.ELEMENT_TYPES.append("theme")
    hacs.common.categories = sorted(const.ELEMENT_TYPES)

    # Setup startup tasks
    if hacs.configuration.config_type == "yaml":
        hacs.hass.bus.async_listen_once(
            EVENT_HOMEASSISTANT_START, hacs().startup_tasks()
        )
    else:
        async_call_later(hacs.hass, 5, hacs().startup_tasks())

    # Print DEV warning
    if hacs.configuration.dev:
        hacs.logger.error(const.DEV_MODE)
        hacs.hass.components.persistent_notification.create(
            title="HACS DEV MODE",
            message=const.DEV_MODE,
            notification_id="hacs_dev_mode",
        )

    # Add sensor
    add_sensor(hacs)

    # Set up services
    await add_services(hacs)

    # Mischief managed!
    return True