Skip to content
Open
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
25 changes: 12 additions & 13 deletions bowtie/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,23 +549,22 @@ async def get_versions(self) -> Iterable[str]:
url = CONTAINER_PACKAGES_API / self.id / "versions"

gh = github()
pages: list[GitHubCore] = []
with suppress(GitHubError):
pages = gh._iter(count=-1, url=str(url), cls=GitHubCore) # type: ignore[reportPrivateUsage]

versions: Set[str] = (
{self.info.version} if self.info.version else set()
)
for page in pages:
try:
tags = cast(
"Iterable[str]",
page.as_dict()["metadata"]["container"]["tags"],
)
except KeyError:
continue
else:
versions.update([tag for tag in tags if "." in tag])

with suppress(GitHubError):
for page in gh._iter(count=-1, url=str(url), cls=GitHubCore): # type: ignore[reportPrivateUsage]
try:
tags = cast(
"Iterable[str]",
page.as_dict()["metadata"]["container"]["tags"], # type: ignore[reportUnknownMemberType]
)
except KeyError:
continue
else:
versions.update([tag for tag in tags if "." in tag])

return sorted(versions, key=sortable_version_key, reverse=True)

Expand Down
38 changes: 38 additions & 0 deletions bowtie/tests/test_info_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from unittest.mock import Mock, patch

from github3.exceptions import GitHubError
import pytest

from bowtie._core import Implementation, ImplementationInfo


@pytest.mark.asyncio
async def test_get_versions_suppresses_github_error():
"""
Test that get_versions() catches GitHub API errors (like rate limits)
and returns the local fallback version instead of crashing.
"""
info = ImplementationInfo.from_dict(
name="fake-runner",
language="python",
homepage="https://example.com",
issues="https://example.com/issues",
source="https://example.com/source",
dialects=["http://json-schema.org/draft-07/schema#"],
version="1.2.3",
)

impl = Implementation(
id="python-fake-runner",
info=info,
harness=Mock(),
reporter=Mock(),
)

with patch("bowtie._core.github") as mock_github_func:
mock_gh_client = Mock()
mock_github_func.return_value = mock_gh_client
mock_gh_client._iter.side_effect = GitHubError(resp=Mock())
versions = await impl.get_versions()

assert versions == ["1.2.3"]
Loading