Skip to content

Commit

Permalink
Implement Gitlab 6.1 new methods
Browse files Browse the repository at this point in the history
 - Project: tree, blob
 - ProjectCommit: diff, blob
  • Loading branch information
Gauvain Pocentek committed Sep 14, 2013
1 parent 4006ab2 commit c9aedf2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -3,6 +3,7 @@ Version 0.4
* Fix strings encoding (Closes #6)
* Allow to get a project commit (GitLab 6.1)
* ProjectMergeRequest: fix Note() method
* Gitlab 6.1 methods: diff, blob (commit), tree, blob (project)

Version 0.3

Expand Down
2 changes: 1 addition & 1 deletion gitlab
Expand Up @@ -169,7 +169,7 @@ def do_get(cls, d):
die("%s objects can't be retrieved" % what)

id = None
if cls not in [gitlab.CurrentUser]:
if cls not in [gitlab.CurrentUser, gitlab.ProjectCommitDiff]:
id = get_id()

try:
Expand Down
37 changes: 37 additions & 0 deletions gitlab.py
Expand Up @@ -651,6 +651,25 @@ class ProjectCommit(GitlabObject):
requiredListAttrs = ['project_id']
shortPrintAttr = 'title'

def diff(self):
url = '/projects/%(project_id)s/repository/commits/%(commit_id)s/diff' % \
{'project_id': self.project_id, 'commit_id': self.id}
r = self.gitlab.rawGet(url)
if r.status_code == 200:
return r.json()

raise GitlabGetError()

def blob(self, filepath):
url = '/projects/%(project_id)s/repository/blobs/%(commit_id)s' % \
{'project_id': self.project_id, 'commit_id': self.id}
url += '?filepath=%s' % filepath
r = self.gitlab.rawGet(url)
if r.status_code == 200:
return r.content

raise GitlabGetError()


class ProjectKey(GitlabObject):
_url = '/projects/%(project_id)s/keys'
Expand Down Expand Up @@ -865,6 +884,24 @@ def Tag(self, id=None, **kwargs):
project_id=self.id,
**kwargs)

def tree(self, path='', ref_name=''):
url = "%s/%s/repository/tree" % (self._url, self.id)
url += '?path=%s&ref_name=%s' % (path, ref_name)
r = self.gitlab.rawGet(url)
if r.status_code == 200:
return r.json()

raise GitlabGetError()

def blob(self, sha, filepath):
url = "%s/%s/repository/blobs/%s" % (self._url, self.id, sha)
url += '?filepath=%s' % (filepath)
r = self.gitlab.rawGet(url)
if r.status_code == 200:
return r.content

raise GitlabGetError()


class TeamMember(GitlabObject):
_url = '/user_teams/%(team_id)s/members'
Expand Down

0 comments on commit c9aedf2

Please sign in to comment.