import gitlab
gl = gitlab.Gitlab('http://gitlab.mycompany', private_token=access_token)
gl.auth()
projects = gl.projects.list()
pres = projects[0]
for project in projects:
if 'myprojectname' in str(project):
print(project)
pres = project
# do something with pres
I'm trying to use Gitlab library in Python. When I print str(project)
, it does not include info about who creates the repo. Also, when I run
for member in pres.members.list():
print(member)
It only prints the invited member, it doesn't print the owner or the people who own the repo group.
Is it possible to find who creates a Gitlab repo?
The ID of the project creator is exposed in the creator_id
attribute in the projects endpoint (see upstream API docs at https://docs.gitlab.com/ee/api/projects.html#list-all-projects).
You can then use the Users API to get more details on the creator user (as described in https://python-gitlab.readthedocs.io/en/stable/gl_objects/users.html):
import gitlab
gl = gitlab.Gitlab('http://gitlab.mycompany', private_token=access_token)
gl.auth()
projects = gl.projects.list(as_list=False)
for project in projects:
creator = gl.users.get(project.creator_id)
print(creator.username)