You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The help for gitlab.v4.objects.Project.repository_blob says:
| repository_blob(*args, **kwargs)
| Return a blob by blob SHA.
|
| Args:
| sha(str): ID of the blob
| **kwargs: Extra options to send to the server (e.g. sudo)
|
| Raises:
| GitlabAuthenticationError: If authentication is not correct
| GitlabGetError: If the server failed to perform the request
|
| Returns:
| str: The blob metadata
When I invoke this method, I get back a dict rather than a string:
Is there a method in v4 comparable to the v3 repository_blob?
My current code to grab the contents of a file in v4 is verbose and inefficient:
p = gl.projects.get(project_name)
items = p.repository_tree(dir_name)
match = [m for m in items if m['name']==file_name]
if len(match) == 1:
m = match[0]
content = p.repository_blob(m['id'])['content']
You can use the files API in v4 to get a file content:
f=p.files.get('README.rst', 'master') # retrieve the file metadata and content as base64print(f.decode()) # print the content# Orprint(p.files.raw('README.rst', 'master'))
The docs are probably not good enough, I'll update them. Thanks for reporting the issue!
Activity
gpocentek commentedon Sep 19, 2017
Hi,
You can use the
filesAPI in v4 to get a file content:The docs are probably not good enough, I'll update them. Thanks for reporting the issue!
mgoodhand commentedon Sep 20, 2017
Great. Thanks!