summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2016-05-12 21:03:51 +0200
committerGauvain Pocentek <gauvain@pocentek.net>2016-05-12 21:04:21 +0200
commit45adb6e4dbe7667376639d68078754d6d72cb55c (patch)
tree60edab495b18a7580c9f3a8d9f385f45ebc1fd28
parent8ce8218e2fb155c933946d9959a9b53f6a905d21 (diff)
downloadgitlab-45adb6e4dbe7667376639d68078754d6d72cb55c.tar.gz
Rename some methods to better match the API URLs
Also deprecate the file_* methods in favor of the files manager.
-rw-r--r--gitlab/objects.py25
-rw-r--r--tools/python_test.py6
2 files changed, 26 insertions, 5 deletions
diff --git a/gitlab/objects.py b/gitlab/objects.py
index df97157..6aa44d1 100644
--- a/gitlab/objects.py
+++ b/gitlab/objects.py
@@ -1448,6 +1448,11 @@ class Project(GitlabObject):
**kwargs)
def tree(self, path='', ref_name='', **kwargs):
+ warnings.warn("`tree` is deprecated, use `repository_tree` instead",
+ DeprecationWarning)
+ return self.repository_tree(path, ref_name, **kwargs)
+
+ def repository_tree(self, path='', ref_name='', **kwargs):
"""Return a list of files in the repository.
Args:
@@ -1474,6 +1479,11 @@ class Project(GitlabObject):
return r.json()
def blob(self, sha, filepath, **kwargs):
+ warnings.warn("`blob` is deprecated, use `repository_blob` instead",
+ DeprecationWarning)
+ return self.repository_blob(sha, filepath, **kwargs)
+
+ def repository_blob(self, sha, filepath, **kwargs):
"""Return the content of a file for a commit.
Args:
@@ -1493,7 +1503,7 @@ class Project(GitlabObject):
raise_error_from_response(r, GitlabGetError)
return r.content
- def raw_blob(self, sha, **kwargs):
+ def repository_raw_blob(self, sha, **kwargs):
"""Returns the raw file contents for a blob by blob SHA.
Args:
@@ -1511,7 +1521,7 @@ class Project(GitlabObject):
raise_error_from_response(r, GitlabGetError)
return r.content
- def compare(self, from_, to, **kwargs):
+ def repository_compare(self, from_, to, **kwargs):
"""Returns a diff between two branches/commits.
Args:
@@ -1531,7 +1541,7 @@ class Project(GitlabObject):
raise_error_from_response(r, GitlabGetError)
return r.json()
- def contributors(self):
+ def repository_contributors(self):
"""Returns a list of contributors for the project.
Returns:
@@ -1580,6 +1590,9 @@ class Project(GitlabObject):
GitlabConnectionError: If the server cannot be reached.
GitlabCreateError: If the server fails to perform the request.
"""
+ warnings.warn("`create_file` is deprecated, "
+ "use `files.create()` instead",
+ DeprecationWarning)
url = "/projects/%s/repository/files" % self.id
url += ("?file_path=%s&branch_name=%s&content=%s&commit_message=%s" %
(path, branch, content, message))
@@ -1587,6 +1600,9 @@ class Project(GitlabObject):
raise_error_from_response(r, GitlabCreateError, 201)
def update_file(self, path, branch, content, message, **kwargs):
+ warnings.warn("`update_file` is deprecated, "
+ "use `files.update()` instead",
+ DeprecationWarning)
url = "/projects/%s/repository/files" % self.id
url += ("?file_path=%s&branch_name=%s&content=%s&commit_message=%s" %
(path, branch, content, message))
@@ -1594,6 +1610,9 @@ class Project(GitlabObject):
raise_error_from_response(r, GitlabUpdateError)
def delete_file(self, path, branch, message, **kwargs):
+ warnings.warn("`delete_file` is deprecated, "
+ "use `files.delete()` instead",
+ DeprecationWarning)
url = "/projects/%s/repository/files" % self.id
url += ("?file_path=%s&branch_name=%s&commit_message=%s" %
(path, branch, message))
diff --git a/tools/python_test.py b/tools/python_test.py
index c5e955e..df8de23 100644
--- a/tools/python_test.py
+++ b/tools/python_test.py
@@ -1,4 +1,5 @@
import base64
+import time
import gitlab
@@ -135,6 +136,7 @@ admin_project.files.create({'file_path': 'README',
'commit_message': 'Initial commit'})
readme = admin_project.files.get(file_path='README', ref='master')
readme.content = base64.b64encode("Improved README")
+time.sleep(2)
readme.save(branch_name="master", commit_message="new commit")
readme.delete(commit_message="Removing README")
@@ -145,10 +147,10 @@ admin_project.files.create({'file_path': 'README.rst',
readme = admin_project.files.get(file_path='README.rst', ref='master')
assert(readme.decode() == 'Initial content')
-tree = admin_project.tree()
+tree = admin_project.repository_tree()
assert(len(tree) == 1)
assert(tree[0]['name'] == 'README.rst')
-blob = admin_project.blob('master', 'README.rst')
+blob = admin_project.repository_blob('master', 'README.rst')
assert(blob == 'Initial content')
archive1 = admin_project.archive()
archive2 = admin_project.archive('master')