Skip to content

Commit 45adb6e

Browse files
author
Gauvain Pocentek
committed
Rename some methods to better match the API URLs
Also deprecate the file_* methods in favor of the files manager.
1 parent 8ce8218 commit 45adb6e

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

gitlab/objects.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,11 @@ def Tag(self, id=None, **kwargs):
14481448
**kwargs)
14491449

14501450
def tree(self, path='', ref_name='', **kwargs):
1451+
warnings.warn("`tree` is deprecated, use `repository_tree` instead",
1452+
DeprecationWarning)
1453+
return self.repository_tree(path, ref_name, **kwargs)
1454+
1455+
def repository_tree(self, path='', ref_name='', **kwargs):
14511456
"""Return a list of files in the repository.
14521457
14531458
Args:
@@ -1474,6 +1479,11 @@ def tree(self, path='', ref_name='', **kwargs):
14741479
return r.json()
14751480

14761481
def blob(self, sha, filepath, **kwargs):
1482+
warnings.warn("`blob` is deprecated, use `repository_blob` instead",
1483+
DeprecationWarning)
1484+
return self.repository_blob(sha, filepath, **kwargs)
1485+
1486+
def repository_blob(self, sha, filepath, **kwargs):
14771487
"""Return the content of a file for a commit.
14781488
14791489
Args:
@@ -1493,7 +1503,7 @@ def blob(self, sha, filepath, **kwargs):
14931503
raise_error_from_response(r, GitlabGetError)
14941504
return r.content
14951505

1496-
def raw_blob(self, sha, **kwargs):
1506+
def repository_raw_blob(self, sha, **kwargs):
14971507
"""Returns the raw file contents for a blob by blob SHA.
14981508
14991509
Args:
@@ -1511,7 +1521,7 @@ def raw_blob(self, sha, **kwargs):
15111521
raise_error_from_response(r, GitlabGetError)
15121522
return r.content
15131523

1514-
def compare(self, from_, to, **kwargs):
1524+
def repository_compare(self, from_, to, **kwargs):
15151525
"""Returns a diff between two branches/commits.
15161526
15171527
Args:
@@ -1531,7 +1541,7 @@ def compare(self, from_, to, **kwargs):
15311541
raise_error_from_response(r, GitlabGetError)
15321542
return r.json()
15331543

1534-
def contributors(self):
1544+
def repository_contributors(self):
15351545
"""Returns a list of contributors for the project.
15361546
15371547
Returns:
@@ -1580,20 +1590,29 @@ def create_file(self, path, branch, content, message, **kwargs):
15801590
GitlabConnectionError: If the server cannot be reached.
15811591
GitlabCreateError: If the server fails to perform the request.
15821592
"""
1593+
warnings.warn("`create_file` is deprecated, "
1594+
"use `files.create()` instead",
1595+
DeprecationWarning)
15831596
url = "/projects/%s/repository/files" % self.id
15841597
url += ("?file_path=%s&branch_name=%s&content=%s&commit_message=%s" %
15851598
(path, branch, content, message))
15861599
r = self.gitlab._raw_post(url, data=None, content_type=None, **kwargs)
15871600
raise_error_from_response(r, GitlabCreateError, 201)
15881601

15891602
def update_file(self, path, branch, content, message, **kwargs):
1603+
warnings.warn("`update_file` is deprecated, "
1604+
"use `files.update()` instead",
1605+
DeprecationWarning)
15901606
url = "/projects/%s/repository/files" % self.id
15911607
url += ("?file_path=%s&branch_name=%s&content=%s&commit_message=%s" %
15921608
(path, branch, content, message))
15931609
r = self.gitlab._raw_put(url, data=None, content_type=None, **kwargs)
15941610
raise_error_from_response(r, GitlabUpdateError)
15951611

15961612
def delete_file(self, path, branch, message, **kwargs):
1613+
warnings.warn("`delete_file` is deprecated, "
1614+
"use `files.delete()` instead",
1615+
DeprecationWarning)
15971616
url = "/projects/%s/repository/files" % self.id
15981617
url += ("?file_path=%s&branch_name=%s&commit_message=%s" %
15991618
(path, branch, message))

tools/python_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import base64
2+
import time
23

34
import gitlab
45

@@ -135,6 +136,7 @@
135136
'commit_message': 'Initial commit'})
136137
readme = admin_project.files.get(file_path='README', ref='master')
137138
readme.content = base64.b64encode("Improved README")
139+
time.sleep(2)
138140
readme.save(branch_name="master", commit_message="new commit")
139141
readme.delete(commit_message="Removing README")
140142

@@ -145,10 +147,10 @@
145147
readme = admin_project.files.get(file_path='README.rst', ref='master')
146148
assert(readme.decode() == 'Initial content')
147149

148-
tree = admin_project.tree()
150+
tree = admin_project.repository_tree()
149151
assert(len(tree) == 1)
150152
assert(tree[0]['name'] == 'README.rst')
151-
blob = admin_project.blob('master', 'README.rst')
153+
blob = admin_project.repository_blob('master', 'README.rst')
152154
assert(blob == 'Initial content')
153155
archive1 = admin_project.archive()
154156
archive2 = admin_project.archive('master')

0 commit comments

Comments
 (0)