From bd0cf30970f283136f6beb26319982dbdd9fa88c Mon Sep 17 00:00:00 2001 From: Steve Kowalik Date: Wed, 25 Apr 2018 19:21:17 +1000 Subject: [PATCH] Correct Repository.get_git_tree recursive use (#767) The API docs for Repository.get_git_tree specify that the URL parameter for fetching a tree recursively should be ?recursive=1, not a truthy value. To not change the API we present, check if it is True before setting it to 1. Change another callsite of Repository.get_git_tree to specify recursive=False to make sure it doesn't appear in the query string. Fixes #560 --- github/Repository.py | 5 +++-- .../ReplayData/Repository.testGetGitTreeWithRecursive.txt | 2 +- github/tests/Repository.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/github/Repository.py b/github/Repository.py index b25cb815..cbf4ba47 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -1727,8 +1727,9 @@ class Repository(github.GithubObject.CompletableGithubObject): assert isinstance(sha, (str, unicode)), sha assert recursive is github.GithubObject.NotSet or isinstance(recursive, bool), recursive url_parameters = dict() - if recursive is not github.GithubObject.NotSet: - url_parameters["recursive"] = recursive + if recursive is not github.GithubObject.NotSet and recursive: + # GitHub API requires the recursive parameter be set to 1. + url_parameters["recursive"] = 1 headers, data = self._requester.requestJsonAndCheck( "GET", self.url + "/git/trees/" + sha, diff --git a/github/tests/ReplayData/Repository.testGetGitTreeWithRecursive.txt b/github/tests/ReplayData/Repository.testGetGitTreeWithRecursive.txt index e0378202..60c98e20 100644 --- a/github/tests/ReplayData/Repository.testGetGitTreeWithRecursive.txt +++ b/github/tests/ReplayData/Repository.testGetGitTreeWithRecursive.txt @@ -2,7 +2,7 @@ https GET api.github.com None -/repos/jacquev6/PyGithub/git/trees/f492784d8ca837779650d1fb406a1a3587a764ad?recursive=True +/repos/jacquev6/PyGithub/git/trees/f492784d8ca837779650d1fb406a1a3587a764ad?recursive=1 {'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} None 200 diff --git a/github/tests/Repository.py b/github/tests/Repository.py index 5c3e3d69..d868ce98 100644 --- a/github/tests/Repository.py +++ b/github/tests/Repository.py @@ -267,7 +267,7 @@ class Repository(Framework.TestCase): self.assertEqual(tree.sha, "41cf8c178c636a018d537cb20daae09391efd70b") def testCreateGitTreeWithBaseTree(self): - base_tree = self.repo.get_git_tree("41cf8c178c636a018d537cb20daae09391efd70b") + base_tree = self.repo.get_git_tree("41cf8c178c636a018d537cb20daae09391efd70b", recursive=False) tree = self.repo.create_git_tree( [github.InputGitTreeElement( "Barbaz.txt",