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:
@@ -19,6 +19,7 @@ Next version
|
||||
* Major improvement: support Python 3! PyGithub is automaticaly tested on [Travis](http://travis-ci.org/jacquev6/PyGithub) with versions 2.5, 2.6, 2.7, 3.1 and 3.2 of Python
|
||||
* Add a shortcut function `Github.get_repo` to get a repo directly from its full name. thank you [lwc](https://github.com/lwc) for the contribution
|
||||
* `Github.get_gitignore_templates` and `Github.get_gitignore_template` for APIs `/gitignore/templates`
|
||||
* Add the optional `ref` parameter to `Repository.get_contents` and `get_readme`. Thank you [fixxxeruk](https://github.com/fixxxeruk) for the contribution
|
||||
|
||||
[Version 1.9.1](https://github.com/jacquev6/PyGithub/issues?milestone=17&state=closed) (November 20th, 2012)
|
||||
------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -1226,9 +1226,11 @@ Commits
|
||||
|
||||
Contents
|
||||
--------
|
||||
* `get_readme()`: `ContentFile`
|
||||
* `get_contents( path )`: `ContentFile`
|
||||
* `get_readme( [ref] )`: `ContentFile`
|
||||
* `ref`: string
|
||||
* `get_contents( path, [ref] )`: `ContentFile`
|
||||
* `path`: string
|
||||
* `ref`: string
|
||||
* `get_archive_link( archive_format, [ref] )`: string
|
||||
* `archive_format`: string
|
||||
* `ref`: string
|
||||
|
||||
@@ -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