mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
Complete "ref in Repository.get_contents and .get_readme" (pull #124)
Add documentation and automated tests
This commit is contained in:
@@ -590,11 +590,11 @@ class Repository(github.GithubObject.GithubObject):
|
||||
url_parameters
|
||||
)
|
||||
|
||||
def get_contents(self, path, ref=GithubObject.NotSet):
|
||||
def get_contents(self, path, ref=github.GithubObject.NotSet):
|
||||
assert isinstance(path, (str, unicode)), path
|
||||
assert ref is GithubObject.NotSet or isinstance(ref, (str, unicode)), ref
|
||||
assert ref is github.GithubObject.NotSet or isinstance(ref, (str, unicode)), ref
|
||||
url_parameters = dict()
|
||||
if ref is not GithubObject.NotSet:
|
||||
if ref is not github.GithubObject.NotSet:
|
||||
url_parameters["ref"] = ref
|
||||
headers, data = self._requester.requestAndCheck(
|
||||
"GET",
|
||||
@@ -899,11 +899,15 @@ class Repository(github.GithubObject.GithubObject):
|
||||
url_parameters
|
||||
)
|
||||
|
||||
def get_readme(self):
|
||||
def get_readme(self, ref=github.GithubObject.NotSet):
|
||||
assert ref is github.GithubObject.NotSet or isinstance(ref, (str, unicode)), ref
|
||||
url_parameters = dict()
|
||||
if ref is not github.GithubObject.NotSet:
|
||||
url_parameters["ref"] = ref
|
||||
headers, data = self._requester.requestAndCheck(
|
||||
"GET",
|
||||
self.url + "/readme",
|
||||
None,
|
||||
url_parameters,
|
||||
None
|
||||
)
|
||||
return github.ContentFile.ContentFile(self._requester, data, completed=True)
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -393,6 +393,10 @@ class Repository(Framework.TestCase):
|
||||
self.assertEqual(len(self.repo.get_readme().content), 10212)
|
||||
self.assertEqual(len(self.repo.get_contents("doc/ReferenceOfClasses.md").content), 38121)
|
||||
|
||||
def testGetContentsWithRef(self):
|
||||
self.assertEqual(len(self.repo.get_readme(ref="refs/heads/topic/ExperimentOnDocumentation").content), 6747)
|
||||
self.assertEqual(len(self.repo.get_contents("doc/ReferenceOfClasses.md", ref="refs/heads/topic/ExperimentOnDocumentation").content), 43929)
|
||||
|
||||
def testGetArchiveLink(self):
|
||||
self.assertEqual(self.repo.get_archive_link("tarball"), "https://nodeload.github.com/jacquev6/PyGithub/tarball/master")
|
||||
self.assertEqual(self.repo.get_archive_link("zipball"), "https://nodeload.github.com/jacquev6/PyGithub/zipball/master")
|
||||
|
||||
Reference in New Issue
Block a user