From 9fb76efde0f6ce4626a9d7bc23b1d924118e5c33 Mon Sep 17 00:00:00 2001 From: Mikhail Yohman Date: Sat, 30 Oct 2021 00:14:30 -0600 Subject: [PATCH] gitlab_project: Add `initialize_with_readme` option (#3601) * Add initialize_with_readme option to gitlab_project. Update integration/unit tests. * Fix pep8 * Revert unit tests * Update plugins/modules/source_control/gitlab/gitlab_project.py Co-authored-by: Felix Fontein * Update plugins/modules/source_control/gitlab/gitlab_project.py Co-authored-by: Felix Fontein * Update plugins/modules/source_control/gitlab/gitlab_project.py Co-authored-by: Felix Fontein * Move initialize_with_readme to proper spot to only add if project does not exist. * Update plugins/modules/source_control/gitlab/gitlab_project.py Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein --- .../modules/source_control/gitlab/gitlab_project.py | 13 +++++++++++++ .../targets/gitlab_project/tasks/main.yml | 3 +-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/modules/source_control/gitlab/gitlab_project.py b/plugins/modules/source_control/gitlab/gitlab_project.py index 338da7c072..ad5e0a2166 100644 --- a/plugins/modules/source_control/gitlab/gitlab_project.py +++ b/plugins/modules/source_control/gitlab/gitlab_project.py @@ -48,6 +48,13 @@ options: description: - An description for the project. type: str + initialize_with_readme: + description: + - Will initialize the project with a default C(README.md). + - Is only used when the project is created, and ignored otherwise. + type: bool + default: false + version_added: "4.0.0" issues_enabled: description: - Whether you want to create issues or not. @@ -187,6 +194,7 @@ EXAMPLES = r''' wiki_enabled: True snippets_enabled: True import_url: http://git.example.com/example/lab.git + initialize_with_readme: true state: present delegate_to: localhost ''' @@ -270,6 +278,8 @@ class GitLabProject(object): 'path': options['path'], 'import_url': options['import_url'], }) + if options['initialize_with_readme']: + project_options['initialize_with_readme'] = options['initialize_with_readme'] project_options = self.getOptionsWithValue(project_options) project = self.createProject(namespace, project_options) changed = True @@ -359,6 +369,7 @@ def main(): name=dict(type='str', required=True), path=dict(type='str'), description=dict(type='str'), + initialize_with_readme=dict(type='bool', default=False), issues_enabled=dict(type='bool', default=True), merge_requests_enabled=dict(type='bool', default=True), merge_method=dict(type='str', default='merge', choices=["merge", "rebase_merge", "ff"]), @@ -399,6 +410,7 @@ def main(): project_name = module.params['name'] project_path = module.params['path'] project_description = module.params['description'] + initialize_with_readme = module.params['initialize_with_readme'] issues_enabled = module.params['issues_enabled'] merge_requests_enabled = module.params['merge_requests_enabled'] merge_method = module.params['merge_method'] @@ -467,6 +479,7 @@ def main(): if gitlab_project.createOrUpdateProject(project_name, namespace, { "path": project_path, "description": project_description, + "initialize_with_readme": initialize_with_readme, "issues_enabled": issues_enabled, "merge_requests_enabled": merge_requests_enabled, "merge_method": merge_method, diff --git a/tests/integration/targets/gitlab_project/tasks/main.yml b/tests/integration/targets/gitlab_project/tasks/main.yml index 0a36d3886a..2e6dd0cfd3 100644 --- a/tests/integration/targets/gitlab_project/tasks/main.yml +++ b/tests/integration/targets/gitlab_project/tasks/main.yml @@ -22,10 +22,10 @@ validate_certs: False login_token: "{{ gitlab_login_token }}" name: "{{ gitlab_project_name }}" + initialize_with_readme: True state: present register: gitlab_project_state - - assert: that: - gitlab_project_state is changed @@ -39,7 +39,6 @@ state: present register: gitlab_project_state_again - - assert: that: - gitlab_project_state_again is not changed