Skip to content

Commit

Permalink
Merge pull request #419 from tobiasmicheler/master
Browse files Browse the repository at this point in the history
fixed the external data checker from stalling when git tag pattern is incorrect, this should fix the github actions run
  • Loading branch information
wjt authored May 3, 2024
2 parents 6ab69bc + 1a0e0c7 commit 6899aeb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 30 deletions.
23 changes: 23 additions & 0 deletions src/checkers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,29 @@ def _substitute_template(
except (KeyError, ValueError) as err:
raise CheckerMetadataError("Error substituting template") from err

@classmethod
def _get_pattern(
cls,
checker_data: t.Dict,
pattern_name: str,
expected_groups: int = 1,
) -> t.Optional[re.Pattern]:
try:
pattern_str = checker_data[pattern_name]
except KeyError:
return None

try:
pattern = re.compile(pattern_str)
except re.error as err:
raise CheckerMetadataError(f"Invalid regex '{pattern_str}'") from err
if pattern.groups != expected_groups:
raise CheckerMetadataError(
f"Pattern '{pattern.pattern}' contains {pattern.groups} group(s) "
f"instead of {expected_groups}"
)
return pattern

async def _complete_digests(
self, url: t.Union[str, URL], digests: MultiDigest
) -> MultiDigest:
Expand Down
14 changes: 6 additions & 8 deletions src/checkers/gitchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,11 @@ async def check(self, external_data: ExternalBase):
return await self._check_has_new(external_data)
return await self._check_still_valid(external_data)

@staticmethod
async def _check_has_new(external_data: ExternalGitRepo):
tag_pattern = external_data.checker_data.get(
"tag-pattern", r"^(?:[vV])?((?:\d+\.)+\d+)$"
)
tag_re = re.compile(tag_pattern)
assert tag_re.groups == 1
@classmethod
async def _check_has_new(cls, external_data: ExternalGitRepo):
tag_re = cls._get_pattern(external_data.checker_data, "tag-pattern", 1)
if tag_re is None:
tag_re = re.compile(r"^(?:[vV])?((?:\d+\.)+\d+)$")

version_scheme = external_data.checker_data.get("version-scheme", "loose")
tag_cls = TAG_VERSION_SCHEMES[version_scheme]
Expand Down Expand Up @@ -142,7 +140,7 @@ async def _check_has_new(external_data: ExternalGitRepo):
except IndexError as err:
raise CheckerQueryError(
f"{external_data.current_version.url} has no tags matching "
f"'{tag_pattern}'"
f"'{tag_re.pattern}'"
) from err

new_version = ExternalGitRef(
Expand Down
27 changes: 5 additions & 22 deletions src/checkers/htmlchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,13 @@

from ..lib import NETWORK_ERRORS, OPERATORS_SCHEMA
from ..lib.externaldata import ExternalBase, ExternalData
from ..lib.errors import CheckerMetadataError, CheckerQueryError, CheckerFetchError
from ..lib.errors import CheckerQueryError, CheckerFetchError
from . import Checker
from ..lib.utils import filter_versioned_items, FallbackVersion

log = logging.getLogger(__name__)


def _get_pattern(
checker_data: t.Dict, pattern_name: str, expected_groups: int = 1
) -> t.Optional[re.Pattern]:
try:
pattern_str = checker_data[pattern_name]
except KeyError:
return None
try:
pattern = re.compile(pattern_str)
except re.error as err:
raise CheckerMetadataError(f"Invalid regex '{pattern_str}'") from err
if pattern.groups != expected_groups:
raise CheckerMetadataError(
f"Pattern '{pattern.pattern}' contains {pattern.groups} group(s) "
f"instead of {expected_groups}"
)
return pattern


def _semantic_version(version: str) -> semver.VersionInfo:
try:
return semver.VersionInfo.parse(version)
Expand Down Expand Up @@ -157,8 +138,10 @@ async def check(self, external_data: ExternalBase):
{f"parent_{k}": v for k, v in parent_json.items() if v is not None},
)

combo_pattern = _get_pattern(external_data.checker_data, "pattern", 2)
version_pattern = _get_pattern(external_data.checker_data, "version-pattern", 1)
combo_pattern = self._get_pattern(external_data.checker_data, "pattern", 2)
version_pattern = self._get_pattern(
external_data.checker_data, "version-pattern", 1
)
url_template = external_data.checker_data.get("url-template")
sort_matches = external_data.checker_data.get("sort-matches", True)
version_cls = _VERSION_SCHEMES[
Expand Down

0 comments on commit 6899aeb

Please sign in to comment.