1

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

1 Answer 1

2

group.projects.list returns a list of GroupProject objects, which you can use to query a project from gitlab. For one of those group project objects group_project use:

project_id = group_project.get_id()
project = gl.projects.get(project_id)

The project object now contains the data of interest. You can use project.http_url_to_repo to get the http url (or project.ssh_url_to_repo for ssh). I found it by printing the project and looking for a url attribute.

Your code could look like this:

def get_group_full_url_by_id(new_group_id):
    group = gl.groups.get(new_group_id)
    group_projects = group.projects.list(get_all=True, iterator=True)
    projects_urls = [gl.projects.get(gp.get_id()).http_url_to_repo for gp in group_projects]
    return projects_urls
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.