Closed szpak closed 1 month ago
I took a closer look at that problem and there seem to be more than one place to enhance.
department1/teamA/projectX
, department2/teamT/projectY
:In my case it tried to get a project based on the subgroup name.
Configuration check successful, starting to fetch Renovate PRs (this may take a few minutes) ...
Traceback (most recent call last):
File "/app/main.py", line 13, in <module>
renovate_prs = get_renovate_prs(configuration)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/renovate_parser.py", line 78, in get_renovate_prs
for pr in git_repo.get_pull_requests(pr_author_username=config.renovate_scm_user, renovate_pr_label=config.renovate_pr_label):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/client_impl/gitlab_client.py", line 88, in get_pull_requests
for mr in self._gl_project.mergerequests.list(**mr_params):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/gitlab/base.py", line 134, in __getattr__
raise AttributeError(message)
AttributeError: 'GroupProject' object has no attribute 'mergerequests'
<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.6.0/faq.html#attribute-error-list
A group is fetched which obviously doesn't have merge requests.
There could be some extra logic in get_repository()
to recursively fetch projects from group subgroups, but I didn't like the scratchy implementation I did (I'm not a Python developer), so I paste here only pseudo code:
def get_repositories(self, owner_or_username: str) -> List[GitRepository]:
if owner_or_username.startswith("user:"):
owner_or_username = owner_or_username[5:]
if self.get_username().lower() == owner_or_username.lower():
projects = self._gitlab_client.projects.list(owned=True)
else:
user = self._gitlab_client.users.list(username=owner_or_username)[0]
projects = self._gitlab_client.projects.list(user_id=user.id)
else:
group = self._gitlab_client.groups.get(owner_or_username)
projects = self.get_repositories_from_subgroup_recursively(group)
repos: List[GitRepository] = [GitLabRepository(project.id, self._gitlab_client, project) for project in
projects]
return repos
def get_repositories_from_subgroup_recursively(self, group: Group) -> List[GitRepository]:
projects = group.projects.list()
sub_groups = group.subgroups.list()
sub_projects = []
for sub_group in sub_groups:
sub_projects += self.get_repositories_from_subgroup_recursively(todo_create_domain_group_object_from_rest_group_object(sub_group))
return projects + sub_projects
hoping that you will figure out any better solution to handle that :-/
@robrobert99 @MShekow WDYT?
Plying with a PAT token generated for one project and for one group works fine if a particular repos are pointed in
REPOS
. However, if for the same group token, I pointtest-group/test-subgroup
where a few projects I would like to analyze are located, I've got 404.(
REPOS=test-group/test-subgroup
)@robrobert99 Have you played with the groups in your environment? Is it supported for GitLab?