mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
Add a trailing slash to URL when updating or deleting a file (tests fixed) (#931)
* Add a trailing slash to URL when updating or deleting a file. * Update test files to match new create/update/delete_file Repo methods * Add trailing slash to get_contents() method * update tests * add missing slash in get_dir_contents * add example usage * remove dup slashes in tests * clarify example comments
This commit is contained in:
@@ -27,13 +27,13 @@ Get list of open issues
|
||||
>>> repo = g.get_repo("PyGithub/PyGithub")
|
||||
>>> open_issues = repo.get_issues(state='open')
|
||||
>>> for issue in open_issues:
|
||||
... print(issue)
|
||||
... print(issue)
|
||||
...
|
||||
Issue(title="How to get public events?", number=913)
|
||||
Issue(title="Prevent .netrc from overwriting Auth header", number=910)
|
||||
Issue(title="Cache fetch responses", number=901)
|
||||
Issue(title="Is suspended_users for github enterprise implemented in NamedUser?", number=900)
|
||||
Issue(title="Adding migration api wrapper", number=899)
|
||||
Issue(title="How to get public events?", number=913)
|
||||
Issue(title="Prevent .netrc from overwriting Auth header", number=910)
|
||||
Issue(title="Cache fetch responses", number=901)
|
||||
Issue(title="Is suspended_users for github enterprise implemented in NamedUser?", number=900)
|
||||
Issue(title="Adding migration api wrapper", number=899)
|
||||
|
||||
Get all the labels of the repository
|
||||
------------------------------------
|
||||
@@ -43,9 +43,98 @@ Get all the labels of the repository
|
||||
>>> repo = g.get_repo("PyGithub/PyGithub")
|
||||
>>> labels = repo.get_labels()
|
||||
>>> for label in labels:
|
||||
... print(label)
|
||||
... print(label)
|
||||
...
|
||||
Label(name="Hacktoberfest")
|
||||
Label(name="WIP")
|
||||
Label(name="bug")
|
||||
Label(name="documentation")
|
||||
|
||||
Get all of the contents of the root directory of the repository
|
||||
---------------------------------------------------------------
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> repo = g.get_repo("PyGithub/PyGithub")
|
||||
>>> contents = repo.get_contents("")
|
||||
>>> for content_file in contents:
|
||||
... print(content_file)
|
||||
...
|
||||
ContentFile(path=".github")
|
||||
ContentFile(path=".gitignore")
|
||||
ContentFile(path=".travis.yml")
|
||||
ContentFile(path="CONTRIBUTING.md")
|
||||
ContentFile(path="COPYING")
|
||||
ContentFile(path="COPYING.LESSER")
|
||||
ContentFile(path="MAINTAINERS")
|
||||
ContentFile(path="MANIFEST.in")
|
||||
ContentFile(path="README.md")
|
||||
ContentFile(path="doc")
|
||||
ContentFile(path="github")
|
||||
ContentFile(path="manage.sh")
|
||||
ContentFile(path="requirements.txt")
|
||||
ContentFile(path="scripts")
|
||||
ContentFile(path="setup.py")
|
||||
|
||||
Get all of the contents of the repository recursively
|
||||
-----------------------------------------------------
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> repo = g.get_repo("PyGithub/PyGithub")
|
||||
>>> contents = repo.get_contents("")
|
||||
>>> while len(contents) > 1:
|
||||
... file_content = contents.pop(0)
|
||||
... if file_content.type == "dir":
|
||||
... contents.extend(repo.get_contents(file_content.path))
|
||||
... else:
|
||||
... print(file_content)
|
||||
...
|
||||
ContentFile(path=".gitignore")
|
||||
ContentFile(path=".travis.yml")
|
||||
ContentFile(path="CONTRIBUTING.md")
|
||||
...
|
||||
ContentFile(path="github/tests/ReplayData/Team.testRepoPermission.txt")
|
||||
ContentFile(path="github/tests/ReplayData/Team.testRepos.txt")
|
||||
ContentFile(path="github/tests/ReplayData/UserKey.setUp.txt")
|
||||
|
||||
Get a specific content file
|
||||
---------------------------
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> repo = g.get_repo("PyGithub/PyGithub")
|
||||
>>> contents = repo.get_contents("README.md")
|
||||
>>> print(contents)
|
||||
...
|
||||
ContentFile(path="README.md")
|
||||
|
||||
Create a new file in the repository
|
||||
-----------------------------------
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> repo = g.get_repo("PyGithub/PyGithub")
|
||||
>>> repo.create_file("test.txt", "test", "test", branch="test")
|
||||
{'content': ContentFile(path="test.txt"), 'commit': Commit(sha="5b584cf6d32d960bb7bee8ce94f161d939aec377")}
|
||||
|
||||
Update a file in the repository
|
||||
-------------------------------
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> repo = g.get_repo("PyGithub/PyGithub")
|
||||
>>> contents = repo.get_contents("test.txt", ref="test")
|
||||
>>> repo.update_file(contents.path, "more tests", "more tests", contents.sha, branch="test")
|
||||
{'commit': Commit(sha="b06e05400afd6baee13fff74e38553d135dca7dc"), 'content': ContentFile(path="test.txt")}
|
||||
|
||||
Delete a file in the repository
|
||||
-------------------------------
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> repo = g.get_repo("PyGithub/PyGithub")
|
||||
>>> contents = repo.get_contents("test.txt", ref="test")
|
||||
>>> repo.delete_file(contents.path, "remove test", contents.sha, branch="test")
|
||||
{'commit': Commit(sha="0f40b0b4f31f62454f1758d7e6b384795e48fd96"), 'content': NotSet}
|
||||
|
||||
|
||||
@@ -1449,7 +1449,7 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
url_parameters["ref"] = ref
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
self.url + "/contents" + urllib.quote(path),
|
||||
self.url + "/contents/" + urllib.quote(path),
|
||||
parameters=url_parameters
|
||||
)
|
||||
if isinstance(data, list):
|
||||
@@ -1530,7 +1530,7 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"PUT",
|
||||
self.url + "/contents" + urllib.quote(path),
|
||||
self.url + "/contents/" + urllib.quote(path),
|
||||
input=put_parameters
|
||||
)
|
||||
|
||||
@@ -1594,7 +1594,7 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"PUT",
|
||||
self.url + "/contents" + urllib.quote(path),
|
||||
self.url + "/contents/" + urllib.quote(path),
|
||||
input=put_parameters
|
||||
)
|
||||
|
||||
@@ -1644,7 +1644,7 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"DELETE",
|
||||
self.url + "/contents" + urllib.quote(path),
|
||||
self.url + "/contents/" + urllib.quote(path),
|
||||
input=url_parameters
|
||||
)
|
||||
|
||||
@@ -1665,7 +1665,7 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
url_parameters["ref"] = ref
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
self.url + "/contents" + urllib.quote(path),
|
||||
self.url + "/contents/" + urllib.quote(path),
|
||||
parameters=url_parameters
|
||||
)
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class Issue140(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issu
|
||||
self.repo = self.g.get_repo("twitter/bootstrap")
|
||||
|
||||
def testGetDirContentsThenLazyCompletionOfFile(self):
|
||||
contents = self.repo.get_dir_contents("/js")
|
||||
contents = self.repo.get_dir_contents("js")
|
||||
self.assertEqual(len(contents), 15)
|
||||
n = 0
|
||||
for content in contents:
|
||||
@@ -48,10 +48,10 @@ class Issue140(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issu
|
||||
self.assertEqual(n, 2)
|
||||
|
||||
def testGetFileContents(self):
|
||||
contents = self.repo.get_file_contents("/js/bootstrap-affix.js")
|
||||
contents = self.repo.get_file_contents("js/bootstrap-affix.js")
|
||||
self.assertEqual(contents.encoding, "base64")
|
||||
self.assertEqual(contents.url, "https://api.github.com/repos/twitter/bootstrap/contents/js/bootstrap-affix.js")
|
||||
self.assertEqual(len(contents.content), 4722)
|
||||
|
||||
def testGetDirContentsWithRef(self):
|
||||
self.assertEqual(len(self.repo.get_dir_contents("/js", "8c7f9c66a7d12f47f50618ef420868fe836d0c33")), 15)
|
||||
self.assertEqual(len(self.repo.get_dir_contents("js", "8c7f9c66a7d12f47f50618ef420868fe836d0c33")), 15)
|
||||
|
||||
@@ -35,5 +35,5 @@ class Issue174(Framework.TestCase):
|
||||
self.repo = self.g.get_repo("twitter/bootstrap")
|
||||
|
||||
def testGetDirContentsWhithHttpRedirect(self):
|
||||
contents = self.repo.get_dir_contents("/js/")
|
||||
contents = self.repo.get_dir_contents("js/")
|
||||
self.assertEqual(len(contents), 15)
|
||||
|
||||
@@ -332,7 +332,7 @@ https
|
||||
GET
|
||||
api.github.com
|
||||
None
|
||||
/repos/jacquev6/PyGithub/contentsREADME.rst
|
||||
/repos/jacquev6/PyGithub/contents/README.rst
|
||||
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
|
||||
None
|
||||
200
|
||||
|
||||
@@ -513,20 +513,20 @@ class Repository(Framework.TestCase):
|
||||
|
||||
def testGetContents(self):
|
||||
self.assertEqual(len(self.repo.get_readme().content), 10212)
|
||||
self.assertEqual(len(self.repo.get_contents("/doc/ReferenceOfClasses.md").content), 38121)
|
||||
self.assertEqual(len(self.repo.get_contents("doc/ReferenceOfClasses.md").content), 38121)
|
||||
|
||||
def testGetContentDir(self):
|
||||
|
||||
contents = self.repo.get_contents("/")
|
||||
contents = self.repo.get_contents("")
|
||||
self.assertTrue(isinstance(contents, list))
|
||||
self.assertEquals(len(contents), 14)
|
||||
|
||||
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)
|
||||
self.assertEqual(len(self.repo.get_contents("doc/ReferenceOfClasses.md", ref="refs/heads/topic/ExperimentOnDocumentation").content), 43929)
|
||||
|
||||
def testCreateFile(self):
|
||||
newFile = '/doc/testCreateUpdateDeleteFile.md'
|
||||
newFile = 'doc/testCreateUpdateDeleteFile.md'
|
||||
content = 'Hello world'
|
||||
self.repo.create_file(
|
||||
path=newFile, message='Create file for testCreateFile', content=content,
|
||||
@@ -534,7 +534,7 @@ class Repository(Framework.TestCase):
|
||||
author=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00"))
|
||||
|
||||
def testUpdateFile(self):
|
||||
updateFile = '/doc/testCreateUpdateDeleteFile.md'
|
||||
updateFile = 'doc/testCreateUpdateDeleteFile.md'
|
||||
content = 'Hello World'
|
||||
sha = self.repo.get_contents(updateFile).sha
|
||||
self.repo.update_file(
|
||||
@@ -543,7 +543,7 @@ class Repository(Framework.TestCase):
|
||||
author=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00"))
|
||||
|
||||
def testDeleteFile(self):
|
||||
deleteFile = '/doc/testCreateUpdateDeleteFile.md'
|
||||
deleteFile = 'doc/testCreateUpdateDeleteFile.md'
|
||||
sha = self.repo.get_contents(deleteFile).sha
|
||||
self.repo.delete_file(path=deleteFile, message='Delete file for testDeleteFile', sha=sha, branch="master")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user