Implement optional revert of #102 (issue #104)

This commit is contained in:
Vincent Jacques
2012-10-28 10:12:25 +01:00
parent cc6d7f1ec3
commit af98e6d1d4
6 changed files with 34 additions and 1 deletions
+8
View File
@@ -33,6 +33,14 @@ class Github(object):
def __init__(self, login_or_token=None, password=None, base_url=DEFAULT_BASE_URL, timeout=DEFAULT_TIMEOUT):
self.__requester = Requester(login_or_token, password, base_url, timeout)
@property
def FIX_REPO_GET_GIT_REF(self):
return self.__requester.FIX_REPO_GET_GIT_REF
@FIX_REPO_GET_GIT_REF.setter
def FIX_REPO_GET_GIT_REF(self, value):
self.__requester.FIX_REPO_GET_GIT_REF = value
@property
def rate_limiting(self):
return self.__requester.rate_limiting
+4 -1
View File
@@ -660,10 +660,13 @@ class Repository(GithubObject.GithubObject):
return GitCommit.GitCommit(self._requester, data, completed=True)
def get_git_ref(self, ref):
prefix = "/git/refs/"
if not self._requester.FIX_REPO_GET_GIT_REF:
prefix = "/git/"
assert isinstance(ref, (str, unicode)), ref
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/git/refs/" + ref,
self.url + prefix + ref,
None,
None
)
+1
View File
@@ -61,6 +61,7 @@ class Requester:
else:
assert(False) # pragma no cover
self.rate_limiting = (5000, 5000)
self.FIX_REPO_GET_GIT_REF = True
def requestAndCheck(self, verb, url, parameters, input):
status, headers, output = self.requestRaw(verb, url, parameters, input)
@@ -0,0 +1,5 @@
https GET api.github.com None /repos/jacquev6/PyGithub/git/refs/heads/master {'Authorization': 'Basic login_and_password_removed'} null
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4987'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('x-ratelimit-limit', '5000'), ('vary', 'Accept, Authorization, Cookie'), ('content-length', '288'), ('server', 'nginx'), ('last-modified', 'Sun, 28 Oct 2012 01:48:38 GMT'), ('connection', 'keep-alive'), ('etag', '"d7478b9ae7e3c0de496ede43edd2fdfc"'), ('cache-control', 'private, max-age=60, s-maxage=60'), ('date', 'Sun, 28 Oct 2012 08:58:25 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"url":"https://api.github.com/repos/jacquev6/PyGithub/git/refs/heads/master","object":{"url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/31110327ec45f3138e58ed247b2cf420fee481ec","type":"commit","sha":"31110327ec45f3138e58ed247b2cf420fee481ec"},"ref":"refs/heads/master"}
@@ -0,0 +1,5 @@
https GET api.github.com None /repos/jacquev6/PyGithub/git/refs/heads/master {'Authorization': 'Basic login_and_password_removed'} null
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4987'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('x-ratelimit-limit', '5000'), ('vary', 'Accept, Authorization, Cookie'), ('content-length', '288'), ('server', 'nginx'), ('last-modified', 'Sun, 28 Oct 2012 01:48:38 GMT'), ('connection', 'keep-alive'), ('etag', '"d7478b9ae7e3c0de496ede43edd2fdfc"'), ('cache-control', 'private, max-age=60, s-maxage=60'), ('date', 'Sun, 28 Oct 2012 08:58:25 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"url":"https://api.github.com/repos/jacquev6/PyGithub/git/refs/heads/master","object":{"url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/31110327ec45f3138e58ed247b2cf420fee481ec","type":"commit","sha":"31110327ec45f3138e58ed247b2cf420fee481ec"},"ref":"refs/heads/master"}
+11
View File
@@ -267,6 +267,17 @@ class Repository(Framework.TestCase):
def testGetGitRefs(self):
self.assertListKeyEqual(self.repo.get_git_refs(), lambda r: r.ref, ["refs/heads/develop", "refs/heads/master", "refs/heads/topic/DependencyGraph", "refs/heads/topic/RewriteWithGeneratedCode", "refs/tags/v0.1", "refs/tags/v0.2", "refs/tags/v0.3", "refs/tags/v0.4", "refs/tags/v0.5", "refs/tags/v0.6", "refs/tags/v0.7"])
def testGetGitRef( self ):
self.assertTrue(self.g.FIX_REPO_GET_GIT_REF)
self.assertEqual(self.repo.get_git_ref( "heads/master" ).object.sha, "31110327ec45f3138e58ed247b2cf420fee481ec" )
def testGetGitRefWithIssue102Reverted( self ):
self.g.FIX_REPO_GET_GIT_REF = False
self.assertFalse(self.g.FIX_REPO_GET_GIT_REF)
self.assertEqual(self.repo.get_git_ref( "refs/heads/master" ).object.sha, "31110327ec45f3138e58ed247b2cf420fee481ec" )
self.g.FIX_REPO_GET_GIT_REF = True
self.assertTrue(self.g.FIX_REPO_GET_GIT_REF)
def testGetGitTreeWithRecursive(self):
tree = self.repo.get_git_tree("f492784d8ca837779650d1fb406a1a3587a764ad", True)
self.assertEqual(len(tree.tree), 90)