From d32193afefc2a6318ead3877cf74d497aaa83ac5 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sun, 27 Jun 2021 14:43:44 +0200 Subject: [PATCH] Fix/gitlab project user workspace (#2881) (#2891) * Add ability to create project under a user * Add changelog * Change minor_changes in changelog As suggested in this comment https://github.com/ansible-collections/community.general/pull/2824#discussion_r653411741 * Fix user's namespace * Delete changelog * Add changelog * Fix changelog Co-authored-by: Felix Fontein Co-authored-by: Amin Vakil * Change user_group_id to namespace_group_id Co-authored-by: Felix Fontein * Change to namespace_id Co-authored-by: Felix Fontein Co-authored-by: Amin Vakil (cherry picked from commit 2fb08775775b7ec3b8a4d4cad2781ee3b6a06263) Co-authored-by: Stef Graces --- .../2881-gitlab_project-fix_workspace_user.yaml | 3 +++ .../source_control/gitlab/gitlab_project.py | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/2881-gitlab_project-fix_workspace_user.yaml diff --git a/changelogs/fragments/2881-gitlab_project-fix_workspace_user.yaml b/changelogs/fragments/2881-gitlab_project-fix_workspace_user.yaml new file mode 100644 index 0000000000..0de8368b7f --- /dev/null +++ b/changelogs/fragments/2881-gitlab_project-fix_workspace_user.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - gitlab_project - user projects are created using namespace ID now, instead of user ID (https://github.com/ansible-collections/community.general/pull/2881). diff --git a/plugins/modules/source_control/gitlab/gitlab_project.py b/plugins/modules/source_control/gitlab/gitlab_project.py index 73def710c3..61d1ac0cb1 100644 --- a/plugins/modules/source_control/gitlab/gitlab_project.py +++ b/plugins/modules/source_control/gitlab/gitlab_project.py @@ -345,22 +345,22 @@ def main(): gitlab_project = GitLabProject(module, gitlab_instance) namespace = None - user_group_id = None + namespace_id = None if group_identifier: group = findGroup(gitlab_instance, group_identifier) if group is None: module.fail_json(msg="Failed to create project: group %s doesn't exists" % group_identifier) - user_group_id = group.id + namespace_id = group.id else: - user = gitlab_instance.users.list(username=gitlab_instance.user.username)[0] - user_group_id = user.id + namespace = gitlab_instance.namespaces.list(search=gitlab_instance.user.username)[0] + namespace_id = namespace.id - if not user_group_id: - module.fail_json(msg="Failed to find the user/group id which required to find namespace") + if not namespace_id: + module.fail_json(msg="Failed to find the namespace or group ID which is required to look up the namespace") try: - namespace = gitlab_instance.namespaces.get(user_group_id) + namespace = gitlab_instance.namespaces.get(namespace_id) except gitlab.exceptions.GitlabGetError as e: module.fail_json(msg="Failed to find the namespace for the given user: %s" % to_native(e))