Skip to content

Commit

Permalink
gitlab_project_members: improve project name matching (#3602)
Browse files Browse the repository at this point in the history
* Update gitlab_project_members.py

The actual search method doesn't accept path with namespace for project_name. If you have many project with same name, this module gitlab_project_members can't work.

* Update gitlab_project_members.py

* Update gitlab_project_members.py

* Update gitlab_project_members.py

* Create 3602-fix-gitlab_project_members-improve-search-method

* Rename 3602-fix-gitlab_project_members-improve-search-method to 3602-fix-gitlab_project_members-improve-search-method.yml

(cherry picked from commit cdfc4dc)
  • Loading branch information
paytroff authored and Patchback committed Oct 30, 2021
1 parent ad93c40 commit f04cf0b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- gitlab_project_members - ``get_project_id`` return the project id by matching ``full_path`` or ``name`` (https://github.com/ansible-collections/community.general/pull/3602).
12 changes: 8 additions & 4 deletions plugins/modules/source_control/gitlab/gitlab_project_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
type: str
project:
description:
- The name of the GitLab project the member is added to/removed from.
- The name (or full path) of the GitLab project the member is added to/removed from.
required: true
type: str
gitlab_user:
Expand Down Expand Up @@ -194,9 +194,13 @@ def __init__(self, module, gl):
self._gitlab = gl

def get_project(self, project_name):
project_exists = self._gitlab.projects.list(search=project_name)
if project_exists:
return project_exists[0].id
try:
project_exists = self._gitlab.projects.get(project_name)
return project_exists.id
except gitlab.exceptions.GitlabGetError as e:
project_exists = self._gitlab.projects.list(search=project_name)
if project_exists:
return project_exists[0].id

def get_user_id(self, gitlab_user):
user_exists = self._gitlab.users.list(username=gitlab_user)
Expand Down

0 comments on commit f04cf0b

Please sign in to comment.