Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gitlab_project module - Allow to update project default branch #7158

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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).
17 changes: 10 additions & 7 deletions plugins/modules/gitlab_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'],
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down