Skip to content

Commit c9aedf2

Browse files
author
Gauvain Pocentek
committed
Implement Gitlab 6.1 new methods
- Project: tree, blob - ProjectCommit: diff, blob
1 parent 4006ab2 commit c9aedf2

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Version 0.4
33
* Fix strings encoding (Closes #6)
44
* Allow to get a project commit (GitLab 6.1)
55
* ProjectMergeRequest: fix Note() method
6+
* Gitlab 6.1 methods: diff, blob (commit), tree, blob (project)
67

78
Version 0.3
89

gitlab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def do_get(cls, d):
169169
die("%s objects can't be retrieved" % what)
170170

171171
id = None
172-
if cls not in [gitlab.CurrentUser]:
172+
if cls not in [gitlab.CurrentUser, gitlab.ProjectCommitDiff]:
173173
id = get_id()
174174

175175
try:

gitlab.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,25 @@ class ProjectCommit(GitlabObject):
651651
requiredListAttrs = ['project_id']
652652
shortPrintAttr = 'title'
653653

654+
def diff(self):
655+
url = '/projects/%(project_id)s/repository/commits/%(commit_id)s/diff' % \
656+
{'project_id': self.project_id, 'commit_id': self.id}
657+
r = self.gitlab.rawGet(url)
658+
if r.status_code == 200:
659+
return r.json()
660+
661+
raise GitlabGetError()
662+
663+
def blob(self, filepath):
664+
url = '/projects/%(project_id)s/repository/blobs/%(commit_id)s' % \
665+
{'project_id': self.project_id, 'commit_id': self.id}
666+
url += '?filepath=%s' % filepath
667+
r = self.gitlab.rawGet(url)
668+
if r.status_code == 200:
669+
return r.content
670+
671+
raise GitlabGetError()
672+
654673

655674
class ProjectKey(GitlabObject):
656675
_url = '/projects/%(project_id)s/keys'
@@ -865,6 +884,24 @@ def Tag(self, id=None, **kwargs):
865884
project_id=self.id,
866885
**kwargs)
867886

887+
def tree(self, path='', ref_name=''):
888+
url = "%s/%s/repository/tree" % (self._url, self.id)
889+
url += '?path=%s&ref_name=%s' % (path, ref_name)
890+
r = self.gitlab.rawGet(url)
891+
if r.status_code == 200:
892+
return r.json()
893+
894+
raise GitlabGetError()
895+
896+
def blob(self, sha, filepath):
897+
url = "%s/%s/repository/blobs/%s" % (self._url, self.id, sha)
898+
url += '?filepath=%s' % (filepath)
899+
r = self.gitlab.rawGet(url)
900+
if r.status_code == 200:
901+
return r.content
902+
903+
raise GitlabGetError()
904+
868905

869906
class TeamMember(GitlabObject):
870907
_url = '/user_teams/%(team_id)s/members'

0 commit comments

Comments
 (0)