1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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

This commit is contained in:
Léo GATELLIER 2023-09-06 19:11:11 +02:00 committed by GitHub
parent 0862511e82
commit 6b17ac1f30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View file

@ -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).

View file

@ -175,8 +175,10 @@ options:
version_added: "4.2.0" version_added: "4.2.0"
default_branch: default_branch:
description: description:
- Default branch name for a new project. - The default branch name for this project.
- This option is only used on creation, not for updates. This is also only used if O(initialize_with_readme=true). - 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 type: str
version_added: "4.2.0" version_added: "4.2.0"
builds_access_level: builds_access_level:
@ -355,7 +357,7 @@ class GitLabProject(object):
@param namespace Namespace Object (User or Group) @param namespace Namespace Object (User or Group)
@param options Options of the project @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 changed = False
project_options = { project_options = {
'name': project_name, 'name': project_name,
@ -395,6 +397,8 @@ class GitLabProject(object):
# Because we have already call userExists in main() # Because we have already call userExists in main()
if self.project_object is None: 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({ project_options.update({
'path': options['path'], 'path': options['path'],
'import_url': options['import_url'], 'import_url': options['import_url'],
@ -416,6 +420,8 @@ class GitLabProject(object):
changed = True changed = True
else: else:
if options['default_branch']:
project_options['default_branch'] = options['default_branch']
changed, project = self.update_project(self.project_object, project_options) changed, project = self.update_project(self.project_object, project_options)
self.project_object = project self.project_object = project
@ -590,9 +596,6 @@ def main():
security_and_compliance_access_level = module.params['security_and_compliance_access_level'] security_and_compliance_access_level = module.params['security_and_compliance_access_level']
topics = module.params['topics'] 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) gitlab_instance = gitlab_authentication(module)
# Set project_path to project_name if it is empty. # Set project_path to project_name if it is empty.
@ -636,7 +639,7 @@ def main():
if state == 'present': 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, "path": project_path,
"description": project_description, "description": project_description,
"initialize_with_readme": initialize_with_readme, "initialize_with_readme": initialize_with_readme,