Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
repository = os.getenv("GITHUB_REPOSITORY")
print(f"Category: {category}")
print(f"Repository: {repository}")
if TOKEN is None:
exit("No GitHub token found, use env GITHUB_TOKEN to set this.")
if repository is None:
exit("No repository found, use env REPOSITORY to set this.")
if category is None:
exit("No category found, use env CATEGORY to set this.")
async with aiohttp.ClientSession() as session:
github = GitHub(TOKEN, session)
repo = await github.get_repo(repository)
if not pr and repo.description is None:
exit("Repository is missing description")
if not pr and not repo.attributes["has_issues"]:
exit("Repository does not have issues enabled")
if ref is None and os.getenv("GITHUB_REPOSITORY") != "hacs/default":
ref = repo.default_branch
await validate_repository(repository, category, ref)
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 = GitHub(hacs.configuration.token, hacs.session)
try:
await register_repository(repository, category, ref=ref, action=True)
except HacsException as exception:
exit(exception)
print("All good!")
async def get_repository(session, token, repository_full_name):
"""Return a repository object or None."""
try:
github = GitHub(token, session)
repository = await github.get_repo(repository_full_name)
return repository
except (AIOGitHubAPIException, Exception) as exception:
raise HacsException(exception)
async def get_repository(session, token, repository_full_name):
"""Return a repository object or None."""
try:
github = GitHub(token, session)
repository = await github.get_repo(repository_full_name)
return repository
except (AIOGitHubAPIException, Exception) as exception:
raise HacsException(exception)
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
await hacs.hass.async_add_executor_job(clear_storage)
hacs.system.lovelace_mode = lovelace_info.get("mode", "yaml")
hacs.system.disabled = False
hacs.github = GitHub(
hacs.configuration.token, async_create_clientsession(hacs.hass)
)
hacs.data = HacsData()
can_update = await get_fetch_updates_for(hacs.github)
if can_update == 0:
hacs.logger.info("HACS is ratelimited, repository updates will resume in 1h.")
else:
hacs.logger.debug(f"Can update {can_update} repositories")
# Check HACS Constrains
if not await hacs.hass.async_add_executor_job(check_constrains):
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
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
# Clear old storage files
await async_clear_storage()
# Setup websocket API
await async_setup_hacs_websockt_api()
hacs.system.lovelace_mode = lovelace_info.get("mode", "yaml")
hacs.system.disabled = False
hacs.github = GitHub(
hacs.configuration.token, async_create_clientsession(hacs.hass)
)
hacs.data = HacsData()
can_update = await get_fetch_updates_for(hacs.github)
if can_update is None:
hacs.logger.critical("Your GitHub token is not valid")
return False
elif can_update != 0:
hacs.logger.debug(f"Can update {can_update} repositories")
else:
hacs.logger.info(
"HACS is ratelimited, repository updates will resume when the limit is cleared, this can take up to 1 hour"
)
return False