mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-02 16:32:56 +00:00
[PR #11851/1db3d4f4 backport][stable-12] gitlab_project_members: fail when multiple projects match by name (#11864)
gitlab_project_members: fail when multiple projects match by name (#11851)
* gitlab_project_members: fail when multiple projects match by name
When the project parameter is a bare name (not a full path), and the
search returns more than one match, the module now fails with a clear
error asking the user to provide the full path (group/project) to
disambiguate, instead of silently operating on the first result.
Fixes #2767
* gitlab_project_members: improve code formatting
* gitlab_project_members: add changelog fragment for #11851
---------
(cherry picked from commit 1db3d4f441)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8def5bf46e
commit
644d362228
2 changed files with 12 additions and 1 deletions
|
|
@ -0,0 +1,4 @@
|
|||
bugfixes:
|
||||
- gitlab_project_members - fail with a clear error when multiple projects match the given name, instead of silently operating on the first result
|
||||
(https://github.com/ansible-collections/community.general/issues/2767,
|
||||
https://github.com/ansible-collections/community.general/pull/11851).
|
||||
|
|
@ -179,8 +179,15 @@ class GitLabProjectMembers:
|
|||
return project_exists.id
|
||||
except gitlab.exceptions.GitlabGetError:
|
||||
project_exists = self._gitlab.projects.list(search=project_name, all=False)
|
||||
if project_exists:
|
||||
if len(project_exists) == 1:
|
||||
return project_exists[0].id
|
||||
if len(project_exists) > 1:
|
||||
self._module.fail_json(
|
||||
msg=(
|
||||
f"More than one project matches '{project_name}'. "
|
||||
"Use the full path ('group/project') to disambiguate."
|
||||
)
|
||||
)
|
||||
|
||||
def get_user_id(self, gitlab_user):
|
||||
user_exists = self._gitlab.users.list(username=gitlab_user, all=False)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue