Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b8d3cbb
Update repo.py
arnavk23 Dec 11, 2025
bbed1dc
Update test_repo.py
arnavk23 Dec 11, 2025
3f3f406
Apply suggestions from code review
arnavk23 Dec 11, 2025
05a8fd6
Refine exception handling in TOML parsing to catch specific exceptions
arnavk23 Dec 11, 2025
772b3b3
Add test coverage for malformed Registry.toml in _registry_path
arnavk23 Dec 11, 2025
e508418
Fix code formatting: split long warning message to comply with line l…
arnavk23 Dec 11, 2025
020ffc3
Apply suggestions from code review
arnavk23 Dec 11, 2025
b9b4f47
Add test coverage for UnicodeDecodeError in _registry_url
arnavk23 Dec 11, 2025
30b2002
Add comprehensive test coverage for _registry_path error handling
arnavk23 Dec 11, 2025
6dbe5a8
Fix black code formatting in repo.py
arnavk23 Dec 11, 2025
5451adc
Fix flake8 line length in registry_path_invalid_encoding docstring
arnavk23 Dec 11, 2025
2db6668
Add test for Registry.toml missing packages key
arnavk23 Dec 11, 2025
2099da5
Add test for missing repo key in Package.toml
arnavk23 Dec 11, 2025
8446a31
Update tagbot/action/repo.py
arnavk23 Dec 11, 2025
4e81eb4
Handle UnicodeDecodeError in Project.toml and add test
arnavk23 Dec 11, 2025
7195750
Format repo.py and tests with black
arnavk23 Dec 11, 2025
774f58d
Apply suggestions from code review
arnavk23 Dec 11, 2025
33ebf0a
Update tagbot/action/repo.py
arnavk23 Dec 11, 2025
16191ef
Standardize test match pattern for _project encoding error
arnavk23 Dec 11, 2025
71f7944
Fix test assertions to match actual error messages
arnavk23 Dec 11, 2025
226689b
Standardize test_registry_url_invalid_encoding match pattern
arnavk23 Dec 11, 2025
8eb7fd3
Merge branch 'master' into master
arnavk23 Dec 14, 2025
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
41 changes: 29 additions & 12 deletions tagbot/action/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ def _project(self, k: str) -> str:
pass # Try the next filename
else:
raise InvalidProject("Project file was not found")
self.__project = toml.loads(contents.decoded_content.decode())
try:
self.__project = toml.loads(contents.decoded_content.decode())
except Exception as e:
raise InvalidProject(
f"Failed to parse Project.toml: {type(e).__name__}: {e}"
)
return str(self.__project[k])

@property
Expand All @@ -194,17 +199,24 @@ def _registry_path(self) -> Optional[str]:
uuid = self._project("uuid").lower()
except KeyError:
raise InvalidProject("Project file has no UUID")
if self._clone_registry:
with open(os.path.join(self._registry_clone_dir, "Registry.toml")) as f:
registry = toml.load(f)
else:
contents = self._only(self._registry.get_contents("Registry.toml"))
blob = self._registry.get_git_blob(contents.sha)
b64 = b64decode(blob.content)
string_contents = b64.decode("utf8")
registry = toml.loads(string_contents)
try:
if self._clone_registry:
with open(os.path.join(self._registry_clone_dir, "Registry.toml")) as f:
registry = toml.load(f)
else:
contents = self._only(self._registry.get_contents("Registry.toml"))
blob = self._registry.get_git_blob(contents.sha)
b64 = b64decode(blob.content)
string_contents = b64.decode("utf8")
registry = toml.loads(string_contents)
except Exception as e:
logger.warning(
f"Failed to load Registry.toml: {type(e).__name__}: {e}. "
"This may indicate a temporary issue with the registry file."
)
return None

if uuid in registry["packages"]:
if uuid in registry.get("packages", {}):
self.__registry_path = registry["packages"][uuid]["path"]
return self.__registry_path
return None
Expand All @@ -219,7 +231,12 @@ def _registry_url(self) -> Optional[str]:
contents = self._only(self._registry.get_contents(f"{root}/Package.toml"))
except UnknownObjectExceptions:
raise InvalidProject("Package.toml was not found")
package = toml.loads(contents.decoded_content.decode())
try:
package = toml.loads(contents.decoded_content.decode())
except Exception as e:
raise InvalidProject(
f"Failed to parse Package.toml: {type(e).__name__}: {e}"
)
self.__registry_url = package["repo"]
return self.__registry_url

Expand Down
22 changes: 22 additions & 0 deletions test/action/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ def test_project():
r._project("name")


def test_project_malformed_toml():
"""Test that malformed Project.toml raises InvalidProject."""
r = _repo()
r._repo.get_contents = Mock(
return_value=Mock(decoded_content=b"""name = "FooBar"\nuuid""")
)
r._Repo__project = None
with pytest.raises(InvalidProject, match="Failed to parse Project.toml"):
r._project("name")


def test_project_subdir():
r = _repo(subdir="path/to/FooBar.jl")
r._repo.get_contents = Mock(
Expand Down Expand Up @@ -159,6 +170,17 @@ def test_registry_url():
assert r._registry.get_contents.call_count == 1


def test_registry_url_malformed_toml():
"""Test that malformed Package.toml raises InvalidProject."""
r = _repo()
r._Repo__registry_path = "E/Example"
r._registry = Mock()
# Malformed TOML content
r._registry.get_contents.return_value.decoded_content = b"name = "
with pytest.raises(InvalidProject, match="Failed to parse Package.toml"):
_ = r._registry_url


def test_release_branch():
r = _repo()
r._repo = Mock(default_branch="a")
Expand Down