[IMP] tests: better tree-reading support

- add support for reading commit entries
- add support for reading tree entries in non-recursive mode

Previously the helper would only return blob entries, which does not
allow testing submodule support.
This commit is contained in:
Xavier Morel 2024-12-16 08:58:04 +01:00
parent a0e237fbfc
commit 5210cfb59f

View File

@ -760,11 +760,15 @@ class Repo:
# read tree's blobs
tree = {}
for t in r.json()['tree']:
if t['type'] != 'blob':
continue # only keep blobs
r = self._session.get('https://api.github.com/repos/{}/git/blobs/{}'.format(self.name, t['sha']))
assert 200 <= r.status_code < 300, r.text
tree[t['path']] = base64.b64decode(r.json()['content']).decode()
match t['type']:
case 'commit':
tree[t['path']] = f"@{t['sha']}"
case 'blob':
r = self._session.get('https://api.github.com/repos/{}/git/blobs/{}'.format(self.name, t['sha']))
assert 200 <= r.status_code < 300, r.text
tree[t['path']] = base64.b64decode(r.json()['content']).decode()
case 'tree' if not recursive:
tree[t['path']] = t['sha']
return tree