Skip to content

Commit 72e097d

Browse files
author
Gauvain Pocentek
committed
provide a ProjectSnippet.Content() method
1 parent abf1b0d commit 72e097d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

gitlab.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ def setCredentials(self, email, password):
129129
self.email = email
130130
self.password = password
131131

132+
def rawGet(self, path, with_token=False):
133+
url = '%s%s' % (self._url, path)
134+
if with_token:
135+
url += "?private_token=%s" % self.private_token
136+
137+
try:
138+
r = requests.get(url)
139+
except:
140+
raise GitlabConnectionError(
141+
"Can't connect to GitLab server (%s)" % self._url)
142+
143+
return r
144+
132145
def rawPost(self, path, data):
133146
url = '%s%s' % (self._url, path)
134147
try:
@@ -658,6 +671,16 @@ class ProjectSnippet(GitlabObject):
658671
requiredCreateAttrs = ['project_id', 'title', 'file_name', 'code']
659672
optionalCreateAttrs = ['lifetime']
660673

674+
def Content(self):
675+
url = "/projects/%(project_id)s/snippets/%(snippet_id)s/raw" % \
676+
{'project_id': self.project_id, 'snippet_id': self.id}
677+
r = self.gitlab.rawGet(url, True)
678+
679+
if r.status_code == 200:
680+
return r.content
681+
else:
682+
raise GitlabGetError
683+
661684
def Note(self, id=None, **kwargs):
662685
return self._getListOrObject(ProjectSnippetNote, id,
663686
project_id=self.project_id,

0 commit comments

Comments
 (0)