From ef22529620afbae3bfe4a398de4a2416a511a7b7 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 27 Sep 2024 12:36:50 +0200 Subject: [PATCH] [ADD] support for recursive tree to the test GH proxy --- conftest.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/conftest.py b/conftest.py index 3226d824..7163552f 100644 --- a/conftest.py +++ b/conftest.py @@ -773,19 +773,20 @@ class Repo: parents=[p['sha'] for p in gh_commit['parents']], ) - def read_tree(self, commit): + def read_tree(self, commit: Commit, *, recursive=False) -> dict[str, str]: """ read tree object from commit - - :param Commit commit: - :rtype: Dict[str, str] """ - r = self._session.get('https://api.github.com/repos/{}/git/trees/{}'.format(self.name, commit.tree)) + r = self._session.get( + 'https://api.github.com/repos/{}/git/trees/{}'.format(self.name, commit.tree), + params={'recursive': '1'} if recursive else None, + ) assert 200 <= r.status_code < 300, r.text # read tree's blobs tree = {} for t in r.json()['tree']: - assert t['type'] == 'blob', "we're *not* doing recursive trees in test cases" + 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()