How to get the projects url by project id by using gitlab library in python

53 Views Asked by At

I'm writing some script for gitlab and i wanna get urls of projects in gitlab by using only project ID so i read all docs about library python-gitlab but couldn't find some attributes for it.

this is my code

import gitlab
import time

from gitlab.exceptions import GitlabCreateError


gitlab_url = 'gitlab.com'
new_gitlab_url = 'gitlab.com'
private_token = 'something in token'
new_private_token = 'something in token'
group_id = 1804
new_group_id = 4178 



gl = gitlab.Gitlab(new_gitlab_url, private_token=new_private_token)
gl.auth()
print("Authentication to NEW is successful!")

new_group = gl.groups.get(new_group_id)
new_projects = new_group.projects.list(get_all=True, iterator=True)
new_projects_ids = [(project.id, project.name) for project in new_projects]
print(new_projects_ids)


def get_group_full_url_by_id(new_group_id):
    group = gl.groups.get(new_group_id)
    projects = group.projects.list(get_all=True, iterator=True)
    projects_urls = [project.full_path for project in projects]
    # print(projects_ids)
    return projects_urls

project_urls = get_group_full_url_by_id(new_group_id)
print(project_urls)

this is the error im getting (yes i got it that there is no full_path for project)

Exception has occurred: AttributeError
'GroupProject' object has no attribute 'full_path'

<class 'gitlab.v4.objects.projects.GroupProject'> was created via a
list() call and only a subset of the data may be present. To ensure
all data is present get the object using a get(object.id) call. For
more details, see:

https://python-gitlab.readthedocs.io/en/v4.2.0/faq.html#attribute-error-list
  File "C:\Users\KAMBAROK\Desktop\bot\testing verions\test.py", line 30, in get_group_full_url_by_id
    projects_urls = [project.full_path for project in projects]
                     ^^^^^^^^^^^^^^^^^
  File "C:\Users\KAMBAROK\Desktop\bot\testing verions\test.py", line 34, in <module>
    project_urls = get_group_full_url_by_id(new_group_id)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'GroupProject' object has no attribute 'full_path'

<class 'gitlab.v4.objects.projects.GroupProject'> was created via a
list() call and only a subset of the data may be present. To ensure
all data is present get the object using a get(object.id) call. For
more details, see:

https://python-gitlab.readthedocs.io/en/v4.2.0/faq.html#attribute-error-list

hope someone will help with this

0

There are 0 best solutions below