Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ignoring repositories #2519

Merged
merged 1 commit into from
Feb 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions custom_components/hacs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class HacsCommon:
categories: set[str] = field(default_factory=set)
renamed_repositories: dict[str, str] = field(default_factory=dict)
archived_repositories: list[str] = field(default_factory=list)
ignored_repositories: list[str] = field(default_factory=list)
skip: list[str] = field(default_factory=list)


Expand Down
1 change: 1 addition & 0 deletions custom_components/hacs/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async def async_get_config_entry_diagnostics(
"categories": hacs.common.categories,
"renamed_repositories": hacs.common.renamed_repositories,
"archived_repositories": hacs.common.archived_repositories,
"ignored_repositories": hacs.common.ignored_repositories,
"lovelace_mode": hacs.core.lovelace_mode,
"configuration": {},
},
Expand Down
14 changes: 10 additions & 4 deletions custom_components/hacs/repositories/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from typing import TYPE_CHECKING, Any, List, Optional
import zipfile

from aiogithubapi import AIOGitHubAPIException, AIOGitHubAPINotModifiedException, GitHubReleaseModel
from aiogithubapi import (
AIOGitHubAPIException,
AIOGitHubAPINotModifiedException,
GitHubReleaseModel,
)
from aiogithubapi.objects.repository import AIOGitHubAPIRepository
import attr
from homeassistant.helpers.json import JSONEncoder
Expand Down Expand Up @@ -958,9 +962,11 @@ async def common_update_data(self, ignore_issues: bool = False, force: bool = Fa
raise HacsRepositoryArchivedException(f"{self} Repository is archived.")

# Make sure the repository is not in the blacklist.
if self.hacs.repositories.is_removed(self.data.full_name) and not ignore_issues:
self.validate.errors.append("Repository has been requested to be removed.")
raise HacsException(f"{self} Repository has been requested to be removed.")
if self.hacs.repositories.is_removed(self.data.full_name):
removed = self.hacs.repositories.removed_repository(self.data.full_name)
if removed.removal_type != "remove" and not ignore_issues:
self.validate.errors.append("Repository has been requested to be removed.")
raise HacsException(f"{self} Repository has been requested to be removed.")

# Get releases.
try:
Expand Down
19 changes: 18 additions & 1 deletion custom_components/hacs/tasks/setup_websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async def async_execute(self) -> None:
async_register_command(self.hass, hacs_removed)
async_register_command(self.hass, acknowledge_critical_repository)
async_register_command(self.hass, get_critical_repositories)
async_register_command(self.hass, hacs_repository_ignore)


@websocket_api.websocket_command(
Expand Down Expand Up @@ -120,7 +121,8 @@ async def hacs_removed(hass, connection, msg):
hacs: HacsBase = hass.data.get(DOMAIN)
content = []
for repo in hacs.repositories.list_removed:
content.append(repo.to_json())
if repo.repository not in hacs.common.ignored_repositories:
content.append(repo.to_json())
connection.send_message(websocket_api.result_message(msg["id"], content))


Expand Down Expand Up @@ -469,3 +471,18 @@ async def hacs_status(hass, connection, msg):
},
)
)


@websocket_api.websocket_command(
{
vol.Required("type"): "hacs/repository/ignore",
vol.Required("repository"): str,
}
)
@websocket_api.require_admin
@websocket_api.async_response
async def hacs_repository_ignore(hass, connection, msg):
"""Ignore a repository."""
hacs: HacsBase = hass.data.get(DOMAIN)
hacs.common.ignored_repositories.append(msg["repository"])
connection.send_message(websocket_api.result_message(msg["id"]))
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""""Hacs base setup task."""
from __future__ import annotations
import asyncio

import asyncio
from datetime import timedelta

from homeassistant.core import HomeAssistant
Expand Down
2 changes: 2 additions & 0 deletions custom_components/hacs/tasks/update_removed_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ async def async_execute(self) -> None:
for removed in self.hacs.repositories.list_removed:
if (repository := self.hacs.repositories.get_by_full_name(removed.repository)) is None:
continue
if repository.data.full_name in self.hacs.common.ignored_repositories:
continue
if repository.data.installed and removed.removal_type != "critical":
self.hacs.log.warning(
"You have '%s' installed with HACS "
Expand Down
7 changes: 7 additions & 0 deletions custom_components/hacs/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async def async_write(self, force: bool = False) -> None:
"onboarding_done": self.hacs.configuration.onboarding_done,
"archived_repositories": self.hacs.common.archived_repositories,
"renamed_repositories": self.hacs.common.renamed_repositories,
"ignored_repositories": self.hacs.common.ignored_repositories,
},
)
await self._async_store_content_and_repos()
Expand Down Expand Up @@ -142,6 +143,7 @@ async def restore(self):
self.hacs.configuration.frontend_compact = hacs.get("compact", False)
self.hacs.configuration.onboarding_done = hacs.get("onboarding_done", False)
self.hacs.common.archived_repositories = []
self.hacs.common.ignored_repositories = []
self.hacs.common.renamed_repositories = {}

# Clear out doubble renamed values
Expand All @@ -156,6 +158,11 @@ async def restore(self):
if entry not in self.hacs.common.archived_repositories:
self.hacs.common.archived_repositories.append(entry)

# Clear out doubble ignored values
for entry in hacs.get("ignored_repositories", []):
if entry not in self.hacs.common.ignored_repositories:
self.hacs.common.ignored_repositories.append(entry)

hass = self.hacs.hass
stores = {}

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pathlib import Path
from unittest.mock import AsyncMock

from aiogithubapi import GitHubAPI, GitHub
from aiogithubapi import GitHub, GitHubAPI
from aiogithubapi.const import ACCEPT_HEADERS
from awesomeversion import AwesomeVersion
from homeassistant.config_entries import ConfigEntry
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/information/test_find_file_name.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Helpers: Install: find_file_name."""
# pylint: disable=missing-docstring
from aiogithubapi.objects.repository.content import AIOGitHubAPIRepositoryTreeContent
from aiogithubapi.models.release import GitHubReleaseModel
from aiogithubapi.objects.repository.content import AIOGitHubAPIRepositoryTreeContent


def test_find_file_name_base(repository_plugin):
Expand Down
2 changes: 1 addition & 1 deletion tests/tasks/test_setup_websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ async def test_setup_websocket_api(hacs: HacsBase):
"custom_components.hacs.tasks.setup_websocket_api.async_register_command"
) as mock_async_register_command:
await task.execute_task()
assert mock_async_register_command.call_count == 9
assert mock_async_register_command.call_count == 10