Skip to content

Commit

Permalink
Handle if registry toml is larger than 1MB (#356)
Browse files Browse the repository at this point in the history
* Try fixing #350

!!! This is untested!

This is according to PyGithub/PyGithub#2345 (comment)

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
  • Loading branch information
simeonschaub authored Sep 23, 2024
1 parent 220ae9d commit beecfc8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
13 changes: 3 additions & 10 deletions tagbot/action/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down
11 changes: 7 additions & 4 deletions test/action/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit beecfc8

Please sign in to comment.