From beecfc853f4c7471635a40a78deed0238dd9c489 Mon Sep 17 00:00:00 2001 From: Simeon David Schaub Date: Mon, 23 Sep 2024 13:02:26 +0200 Subject: [PATCH] Handle if registry toml is larger than 1MB (#356) * Try fixing #350 !!! This is untested! This is according to https://github.com/PyGithub/PyGithub/issues/2345#issuecomment-1835376705 Locally I tested that the following works correctly: ```python In [24]: from github import Github, Auth In [25]: auth = Auth.Token(token) In [26]: g = Github(auth=auth) In [27]: repo = g.get_repo("JuliaRegistries/General") In [28]: registry_toml = repo.get_contents("Registry.toml") In [39]: blob = repo.get_git_blob(registry_toml.sha) In [40]: b64 = base64.b64decode(blob.content) In [41]: b64.decode("utf8") ``` * Update test_repo.py * fix formatting --- tagbot/action/repo.py | 13 +++---------- test/action/test_repo.py | 11 +++++++---- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/tagbot/action/repo.py b/tagbot/action/repo.py index 92c3037..4b9d5d6 100644 --- a/tagbot/action/repo.py +++ b/tagbot/action/repo.py @@ -156,16 +156,9 @@ def _registry_path(self) -> Optional[str]: registry = toml.load(f) else: contents = self._only(self._registry.get_contents("Registry.toml")) - # show file contents if cannot be decoded - try: - string_contents = contents.decoded_content.decode() - except AssertionError: - logger.info( - f"Registry.toml could not be decoded. Raw contents: {contents}" - ) - # rethrow now we've logged info - raise - + blob = self._registry.get_git_blob(contents.sha) + b64 = b64decode(blob.content) + string_contents = b64.decode("utf8") registry = toml.loads(string_contents) if uuid in registry["packages"]: diff --git a/test/action/test_repo.py b/test/action/test_repo.py index ceb30a5..d5d2396 100644 --- a/test/action/test_repo.py +++ b/test/action/test_repo.py @@ -101,10 +101,13 @@ def test_project_subdir(): def test_registry_path(): r = _repo() r._registry = Mock() - r._registry.get_contents.return_value.decoded_content = b""" - [packages] - abc-def = { path = "B/Bar" } - """ + r._registry.get_contents.return_value.sha = "123" + r._registry.get_git_blob.return_value.content = b64encode( + b""" + [packages] + abc-def = { path = "B/Bar" } + """ + ) r._project = lambda _k: "abc-ddd" assert r._registry_path is None r._project = lambda _k: "abc-def"