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