mirror of
https://github.com/CCOSTAN/Home-AssistantConfig.git
synced 2025-08-20 12:10:28 +00:00
#743 - Trying to fix this.
This commit is contained in:
@@ -26,7 +26,7 @@ def should_try_releases(repository):
|
||||
return False
|
||||
if repository.data.category not in ["plugin", "theme"]:
|
||||
return False
|
||||
if not repository.releases.releases:
|
||||
if not repository.data.releases:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@@ -1,11 +1,12 @@
|
||||
"""Helpers to get default repositories."""
|
||||
import json
|
||||
from aiogithubapi import AIOGitHub, AIOGitHubException
|
||||
from aiogithubapi import GitHub, AIOGitHubAPIException
|
||||
from integrationhelper import Logger
|
||||
from custom_components.hacs.hacsbase.exceptions import HacsException
|
||||
from custom_components.hacs.helpers.information import get_repository
|
||||
|
||||
|
||||
async def get_default_repos_orgs(github: type(AIOGitHub), category: str) -> dict:
|
||||
async def get_default_repos_orgs(github: type(GitHub), category: str) -> dict:
|
||||
"""Gets default org repositories."""
|
||||
repositories = []
|
||||
logger = Logger("hacs")
|
||||
@@ -22,7 +23,7 @@ async def get_default_repos_orgs(github: type(AIOGitHub), category: str) -> dict
|
||||
for repo in repos:
|
||||
repositories.append(repo.full_name)
|
||||
|
||||
except AIOGitHubException as exception:
|
||||
except AIOGitHubAPIException as exception:
|
||||
logger.error(exception)
|
||||
|
||||
return repositories
|
||||
@@ -38,7 +39,7 @@ async def get_default_repos_lists(session, token, default: str) -> dict:
|
||||
content = await repo.get_contents(default)
|
||||
repositories = json.loads(content.content)
|
||||
|
||||
except AIOGitHubException as exception:
|
||||
except (AIOGitHubAPIException, HacsException) as exception:
|
||||
logger.error(exception)
|
||||
|
||||
return repositories
|
||||
|
@@ -1,6 +1,6 @@
|
||||
"""Return repository information if any."""
|
||||
import json
|
||||
from aiogithubapi import AIOGitHubException, AIOGitHub
|
||||
from aiogithubapi import AIOGitHubAPIException, GitHub
|
||||
from custom_components.hacs.handler.template import render_template
|
||||
from custom_components.hacs.hacsbase.exceptions import HacsException
|
||||
|
||||
@@ -29,7 +29,7 @@ async def get_info_md_content(repository):
|
||||
return ""
|
||||
info = info.content.replace("<svg", "<disabled").replace("</svg", "</disabled")
|
||||
return render_template(info, repository)
|
||||
except (AIOGitHubException, Exception): # pylint: disable=broad-except
|
||||
except (AIOGitHubAPIException, Exception): # pylint: disable=broad-except
|
||||
if repository.hacs.action:
|
||||
raise HacsException("No info file found")
|
||||
return ""
|
||||
@@ -38,10 +38,10 @@ async def get_info_md_content(repository):
|
||||
async def get_repository(session, token, repository_full_name):
|
||||
"""Return a repository object or None."""
|
||||
try:
|
||||
github = AIOGitHub(token, session)
|
||||
github = GitHub(token, session)
|
||||
repository = await github.get_repo(repository_full_name)
|
||||
return repository
|
||||
except AIOGitHubException as exception:
|
||||
except (AIOGitHubAPIException, Exception) as exception:
|
||||
raise HacsException(exception)
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ async def get_tree(repository, ref):
|
||||
try:
|
||||
tree = await repository.get_tree(ref)
|
||||
return tree
|
||||
except AIOGitHubException as exception:
|
||||
except AIOGitHubAPIException as exception:
|
||||
raise HacsException(exception)
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ async def get_releases(repository, prerelease=False, returnlimit=5):
|
||||
try:
|
||||
releases = await repository.get_releases(prerelease, returnlimit)
|
||||
return releases
|
||||
except AIOGitHubException as exception:
|
||||
except AIOGitHubAPIException as exception:
|
||||
raise HacsException(exception)
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ async def get_integration_manifest(repository):
|
||||
repository.data.authors = manifest["codeowners"]
|
||||
repository.data.domain = manifest["domain"]
|
||||
repository.data.manifest_name = manifest["name"]
|
||||
repository.data.config_flow = manifest.get("config_flow", False)
|
||||
|
||||
if repository.hacs.action:
|
||||
if manifest.get("documentation") is None:
|
||||
@@ -115,6 +116,10 @@ def find_file_name(repository):
|
||||
elif repository.data.category == "python_script":
|
||||
get_file_name_python_script(repository)
|
||||
|
||||
if repository.hacs.action:
|
||||
repository.logger.info(f"filename {repository.data.file_name}")
|
||||
repository.logger.info(f"location {repository.content.path.remote}")
|
||||
|
||||
|
||||
def get_file_name_plugin(repository):
|
||||
"""Get the filename to target."""
|
||||
|
@@ -26,7 +26,7 @@ async def install_repository(repository):
|
||||
else:
|
||||
repository.ref = f"tags/{version}"
|
||||
|
||||
if repository.status.installed and repository.data.category == "netdaemon":
|
||||
if repository.data.installed and repository.data.category == "netdaemon":
|
||||
persistent_directory = BackupNetDaemon(repository)
|
||||
persistent_directory.create()
|
||||
|
||||
@@ -40,7 +40,7 @@ async def install_repository(repository):
|
||||
)
|
||||
persistent_directory.create()
|
||||
|
||||
if repository.status.installed and not repository.content.single:
|
||||
if repository.data.installed and not repository.content.single:
|
||||
backup = Backup(repository.content.path.local)
|
||||
backup.create()
|
||||
|
||||
@@ -52,10 +52,10 @@ async def install_repository(repository):
|
||||
if repository.validate.errors:
|
||||
for error in repository.validate.errors:
|
||||
repository.logger.error(error)
|
||||
if repository.status.installed and not repository.content.single:
|
||||
if repository.data.installed and not repository.content.single:
|
||||
backup.restore()
|
||||
|
||||
if repository.status.installed and not repository.content.single:
|
||||
if repository.data.installed and not repository.content.single:
|
||||
backup.cleanup()
|
||||
|
||||
if persistent_directory is not None:
|
||||
@@ -66,13 +66,13 @@ async def install_repository(repository):
|
||||
if repository.data.full_name not in repository.hacs.common.installed:
|
||||
if repository.data.full_name == "hacs/integration":
|
||||
repository.hacs.common.installed.append(repository.data.full_name)
|
||||
repository.status.installed = True
|
||||
repository.versions.installed_commit = repository.versions.available_commit
|
||||
repository.data.installed = True
|
||||
repository.data.installed_commit = repository.data.last_commit
|
||||
|
||||
if version == repository.data.default_branch:
|
||||
repository.versions.installed = None
|
||||
repository.data.installed_version = None
|
||||
else:
|
||||
repository.versions.installed = version
|
||||
repository.data.installed_version = version
|
||||
|
||||
await reload_after_install(repository)
|
||||
installation_complete(repository)
|
||||
@@ -81,7 +81,7 @@ async def install_repository(repository):
|
||||
async def reload_after_install(repository):
|
||||
"""Reload action after installation success."""
|
||||
if repository.data.category == "integration":
|
||||
if repository.config_flow:
|
||||
if repository.data.config_flow:
|
||||
if repository.data.full_name != "hacs/integration":
|
||||
await repository.reload_custom_components()
|
||||
repository.pending_restart = True
|
||||
@@ -113,18 +113,18 @@ def installation_complete(repository):
|
||||
|
||||
def version_to_install(repository):
|
||||
"""Determine which version to isntall."""
|
||||
if repository.versions.available is not None:
|
||||
if repository.status.selected_tag is not None:
|
||||
if repository.status.selected_tag == repository.versions.available:
|
||||
repository.status.selected_tag = None
|
||||
return repository.versions.available
|
||||
return repository.status.selected_tag
|
||||
return repository.versions.available
|
||||
if repository.status.selected_tag is not None:
|
||||
if repository.status.selected_tag == repository.data.default_branch:
|
||||
if repository.data.last_version is not None:
|
||||
if repository.data.selected_tag is not None:
|
||||
if repository.data.selected_tag == repository.data.last_version:
|
||||
repository.data.selected_tag = None
|
||||
return repository.data.last_version
|
||||
return repository.data.selected_tag
|
||||
return repository.data.last_version
|
||||
if repository.data.selected_tag is not None:
|
||||
if repository.data.selected_tag == repository.data.default_branch:
|
||||
return repository.data.default_branch
|
||||
if repository.status.selected_tag in repository.releases.published_tags:
|
||||
return repository.status.selected_tag
|
||||
if repository.data.selected_tag in repository.data.published_tags:
|
||||
return repository.data.selected_tag
|
||||
if repository.data.default_branch is None:
|
||||
return "master"
|
||||
return repository.data.default_branch
|
||||
|
@@ -1,5 +1,5 @@
|
||||
"""Register a repository."""
|
||||
from aiogithubapi import AIOGitHubException
|
||||
from aiogithubapi import AIOGitHubAPIException
|
||||
from custom_components.hacs.globals import get_hacs
|
||||
from custom_components.hacs.hacsbase.exceptions import (
|
||||
HacsException,
|
||||
@@ -29,7 +29,7 @@ async def register_repository(full_name, category, check=True, ref=None, action=
|
||||
try:
|
||||
await repository.registration(ref)
|
||||
if hacs.system.status.new:
|
||||
repository.status.new = False
|
||||
repository.data.new = False
|
||||
if repository.validate.errors:
|
||||
hacs.common.skip.append(repository.data.full_name)
|
||||
if not hacs.system.status.startup:
|
||||
@@ -41,18 +41,29 @@ async def register_repository(full_name, category, check=True, ref=None, action=
|
||||
repository.logger.info("Validation complete")
|
||||
else:
|
||||
repository.logger.info("Registration complete")
|
||||
except AIOGitHubException as exception:
|
||||
except AIOGitHubAPIException as exception:
|
||||
hacs.common.skip.append(repository.data.full_name)
|
||||
raise HacsException(f"Validation for {full_name} failed with {exception}.")
|
||||
|
||||
if hacs.hass is not None:
|
||||
hacs.hass.bus.async_fire(
|
||||
"hacs/repository",
|
||||
{
|
||||
"id": 1337,
|
||||
"action": "registration",
|
||||
"repository": repository.data.full_name,
|
||||
"repository_id": repository.information.uid,
|
||||
},
|
||||
)
|
||||
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:
|
||||
hacs.hass.bus.async_fire(
|
||||
"hacs/repository",
|
||||
{
|
||||
"id": 1337,
|
||||
"action": "registration",
|
||||
"repository": repository.data.full_name,
|
||||
"repository_id": repository.data.id,
|
||||
},
|
||||
)
|
||||
hacs.repositories.append(repository)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
"""Helper to do common validation for repositories."""
|
||||
from aiogithubapi import AIOGitHubException
|
||||
from aiogithubapi import AIOGitHubAPIException
|
||||
from custom_components.hacs.globals import get_hacs, is_removed
|
||||
from custom_components.hacs.hacsbase.exceptions import HacsException
|
||||
from custom_components.hacs.helpers.install import version_to_install
|
||||
@@ -10,19 +10,19 @@ from custom_components.hacs.helpers.information import (
|
||||
)
|
||||
|
||||
|
||||
async def common_validate(repository):
|
||||
async def common_validate(repository, ignore_issues=False):
|
||||
"""Common validation steps of the repository."""
|
||||
repository.validate.errors = []
|
||||
|
||||
# Make sure the repository exist.
|
||||
repository.logger.debug("Checking repository.")
|
||||
await common_update_data(repository)
|
||||
await common_update_data(repository, ignore_issues)
|
||||
|
||||
# Step 6: Get the content of hacs.json
|
||||
await repository.get_repository_manifest_content()
|
||||
|
||||
|
||||
async def common_update_data(repository):
|
||||
async def common_update_data(repository, ignore_issues=False):
|
||||
"""Common update data."""
|
||||
hacs = get_hacs()
|
||||
try:
|
||||
@@ -31,19 +31,19 @@ async def common_update_data(repository):
|
||||
)
|
||||
repository.repository_object = repository_object
|
||||
repository.data.update_data(repository_object.attributes)
|
||||
except (AIOGitHubException, HacsException) as exception:
|
||||
except (AIOGitHubAPIException, HacsException) as exception:
|
||||
if not hacs.system.status.startup:
|
||||
repository.logger.error(exception)
|
||||
repository.validate.errors.append("Repository does not exist.")
|
||||
raise HacsException(exception)
|
||||
|
||||
# Make sure the repository is not archived.
|
||||
if repository.data.archived:
|
||||
if repository.data.archived and not ignore_issues:
|
||||
repository.validate.errors.append("Repository is archived.")
|
||||
raise HacsException("Repository is archived.")
|
||||
|
||||
# Make sure the repository is not in the blacklist.
|
||||
if is_removed(repository.data.full_name):
|
||||
if is_removed(repository.data.full_name) and not ignore_issues:
|
||||
repository.validate.errors.append("Repository is in the blacklist.")
|
||||
raise HacsException("Repository is in the blacklist.")
|
||||
|
||||
@@ -51,29 +51,29 @@ async def common_update_data(repository):
|
||||
try:
|
||||
releases = await get_releases(
|
||||
repository.repository_object,
|
||||
repository.status.show_beta,
|
||||
repository.data.show_beta,
|
||||
hacs.configuration.release_limit,
|
||||
)
|
||||
if releases:
|
||||
repository.releases.releases = True
|
||||
repository.data.releases = True
|
||||
repository.releases.objects = releases
|
||||
repository.releases.published_tags = [
|
||||
repository.data.published_tags = [
|
||||
x.tag_name for x in releases if not x.draft
|
||||
]
|
||||
repository.versions.available = next(iter(releases)).tag_name
|
||||
repository.data.last_version = next(iter(releases)).tag_name
|
||||
|
||||
except (AIOGitHubException, HacsException):
|
||||
repository.releases.releases = False
|
||||
except (AIOGitHubAPIException, HacsException):
|
||||
repository.data.releases = False
|
||||
|
||||
if not repository.force_branch:
|
||||
repository.ref = version_to_install(repository)
|
||||
if repository.releases.releases:
|
||||
if repository.data.releases:
|
||||
for release in releases:
|
||||
if release.tag_name == repository.ref:
|
||||
assets = release.assets
|
||||
if assets:
|
||||
downloads = next(iter(assets)).attributes.get("download_count")
|
||||
repository.releases.downloads = downloads
|
||||
repository.data.downloads = downloads
|
||||
|
||||
repository.logger.debug(
|
||||
f"Running checks against {repository.ref.replace('tags/', '')}"
|
||||
@@ -86,7 +86,7 @@ async def common_update_data(repository):
|
||||
repository.treefiles = []
|
||||
for treefile in repository.tree:
|
||||
repository.treefiles.append(treefile.full_path)
|
||||
except (AIOGitHubException, HacsException) as exception:
|
||||
except (AIOGitHubAPIException, HacsException) as exception:
|
||||
if not hacs.system.status.startup:
|
||||
repository.logger.error(exception)
|
||||
raise HacsException(exception)
|
||||
|
Reference in New Issue
Block a user