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

Remove helpers.misc #2376

Merged
merged 2 commits into from
Dec 25, 2021
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
11 changes: 9 additions & 2 deletions custom_components/hacs/helpers/classes/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
get_repository,
)
from custom_components.hacs.helpers.functions.download import download_content
from custom_components.hacs.helpers.functions.misc import get_repository_name
from custom_components.hacs.helpers.functions.store import async_remove_store
from custom_components.hacs.helpers.functions.validate_repository import (
common_update_data,
Expand Down Expand Up @@ -146,7 +145,15 @@ def __str__(self) -> str:
@property
def display_name(self):
"""Return display name."""
return get_repository_name(self)
if self.repository_manifest.name is not None:
return self.repository_manifest.name

if self.data.category == "integration":
if self.integration_manifest:
if "name" in self.integration_manifest:
return self.integration_manifest["name"]

return self.data.full_name.split("/")[-1].replace("-", " ").replace("_", " ").title()

@property
def ignored_by_country_configuration(self) -> bool:
Expand Down
28 changes: 0 additions & 28 deletions custom_components/hacs/helpers/functions/misc.py

This file was deleted.

5 changes: 3 additions & 2 deletions custom_components/hacs/tasks/setup_websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import homeassistant.helpers.config_validation as cv
import voluptuous as vol

from custom_components.hacs.utils import regex

from ..base import HacsBase
from ..enums import HacsStage
from ..exceptions import HacsException
from ..helpers.functions.misc import extract_repository_from_url
from ..helpers.functions.register_repository import register_repository
from ..helpers.functions.store import async_load_from_store, async_save_to_store
from ..share import get_hacs
Expand Down Expand Up @@ -210,7 +211,7 @@ async def hacs_repository_data(hass, connection, msg):
return

if action == "add":
repo_id = extract_repository_from_url(repo_id)
repo_id = regex.extract_repository_from_url(repo_id)
if repo_id is None:
return

Expand Down
15 changes: 15 additions & 0 deletions custom_components/hacs/utils/regex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Regex utils"""
from __future__ import annotations
import re

RE_REPOSITORY = re.compile(
r"(?:(?:.*github.com.)|^)([A-Za-z0-9-]+\/[\w.-]+?)(?:(?:\.git)?|(?:[^\w.-].*)?)$"
)


def extract_repository_from_url(url: str) -> str | None:
"""Extract the owner/repo part form a URL."""
match = re.match(RE_REPOSITORY, url)
if not match:
return None
return match.group(1).lower()
18 changes: 9 additions & 9 deletions tests/helpers/functions/test_extract_repository_from_url.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""Tests for repository extraction."""
from custom_components.hacs.helpers.functions.misc import extract_repository_from_url
from custom_components.hacs.utils import regex


def test_extract_repository_from_url():
"""Tests for repository extraction."""
assert extract_repository_from_url("https://github.com/user/repo") == "user/repo"
assert extract_repository_from_url("user/repo/") == "user/repo"
assert extract_repository_from_url("user/repo") == "user/repo"
assert extract_repository_from_url("USER/REPO") == "user/repo"
assert extract_repository_from_url("user/repo.git") == "user/repo"
assert extract_repository_from_url("user/repo.repo") == "user/repo.repo"
assert extract_repository_from_url("git@github.com:user/repo.git") == "user/repo"
assert not extract_repository_from_url("https://google.com/user/repo")
assert regex.extract_repository_from_url("https://github.com/user/repo") == "user/repo"
assert regex.extract_repository_from_url("user/repo/") == "user/repo"
assert regex.extract_repository_from_url("user/repo") == "user/repo"
assert regex.extract_repository_from_url("USER/REPO") == "user/repo"
assert regex.extract_repository_from_url("user/repo.git") == "user/repo"
assert regex.extract_repository_from_url("user/repo.repo") == "user/repo.repo"
assert regex.extract_repository_from_url("git@github.com:user/repo.git") == "user/repo"
assert not regex.extract_repository_from_url("https://google.com/user/repo")
44 changes: 0 additions & 44 deletions tests/helpers/misc/test_get_repository_name.py

This file was deleted.