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']
Is there a better way?
The text was updated successfully, but these errors were encountered:
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!
I'm using python-gitlab (1.0.0) to grab the contents of a text file in a repository.
The introductory sections recommend the use of the v4 API, but the Projects examples still appear to use v3:
The help for gitlab.v4.objects.Project.repository_blob says:
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:
Is there a better way?
The text was updated successfully, but these errors were encountered: