From d548441e359142a003f3ed65595c6c428b1ce028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20GATELLIER?= <26511053+lgatellier@users.noreply.github.com> Date: Sun, 27 Aug 2023 19:33:27 +0200 Subject: [PATCH] feat: gitlab_project module - Allow to update project default branch --- ...158-gitlab-project-default-branch-update.yml | 2 ++ plugins/modules/gitlab_project.py | 17 ++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/7158-gitlab-project-default-branch-update.yml diff --git a/changelogs/fragments/7158-gitlab-project-default-branch-update.yml b/changelogs/fragments/7158-gitlab-project-default-branch-update.yml new file mode 100644 index 00000000000..f9fcfca8b24 --- /dev/null +++ b/changelogs/fragments/7158-gitlab-project-default-branch-update.yml @@ -0,0 +1,2 @@ +breaking_changes: + - gitlab_project - add ``default_branch`` support for project update. If you used the module so far with ``default_branch`` to update a project, the value of ``default_branch`` was ignored. Make sure that you either do not pass a value if you are not sure whether it is the one you want to have to avoid unexpected breaking changes (https://github.com/ansible-collections/community.general/pull/7158). diff --git a/plugins/modules/gitlab_project.py b/plugins/modules/gitlab_project.py index b10a0625778..a28e021951f 100644 --- a/plugins/modules/gitlab_project.py +++ b/plugins/modules/gitlab_project.py @@ -175,8 +175,10 @@ version_added: "4.2.0" default_branch: description: - - Default branch name for a new project. - - This option is only used on creation, not for updates. This is also only used if O(initialize_with_readme=true). + - The default branch name for this project. + - For project creation, this option requires O(initialize_with_readme=true). + - For project update, the branch must exist. + - Supports project's default branch update since community.general 8.0.0. type: str version_added: "4.2.0" builds_access_level: @@ -355,7 +357,7 @@ def __init__(self, module, gitlab_instance): @param namespace Namespace Object (User or Group) @param options Options of the project ''' - def create_or_update_project(self, project_name, namespace, options): + def create_or_update_project(self, module, project_name, namespace, options): changed = False project_options = { 'name': project_name, @@ -395,6 +397,8 @@ def create_or_update_project(self, project_name, namespace, options): # Because we have already call userExists in main() if self.project_object is None: + if options['default_branch'] and not options['initialize_with_readme']: + module.fail_json(msg="Param default_branch need param initialize_with_readme set to true") project_options.update({ 'path': options['path'], 'import_url': options['import_url'], @@ -416,6 +420,8 @@ def create_or_update_project(self, project_name, namespace, options): changed = True else: + if options['default_branch']: + project_options['default_branch'] = options['default_branch'] changed, project = self.update_project(self.project_object, project_options) self.project_object = project @@ -590,9 +596,6 @@ def main(): security_and_compliance_access_level = module.params['security_and_compliance_access_level'] topics = module.params['topics'] - if default_branch and not initialize_with_readme: - module.fail_json(msg="Param default_branch need param initialize_with_readme set to true") - gitlab_instance = gitlab_authentication(module) # Set project_path to project_name if it is empty. @@ -636,7 +639,7 @@ def main(): if state == 'present': - if gitlab_project.create_or_update_project(project_name, namespace, { + if gitlab_project.create_or_update_project(module, project_name, namespace, { "path": project_path, "description": project_description, "initialize_with_readme": initialize_with_readme,