mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
gitlab_project: add support for merge_method on projects (#636)
Migrated from ansible/ansible#66813 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
41cfdda6a3
commit
c034e8c04f
4 changed files with 49 additions and 13 deletions
2
changelogs/fragments/66813_gitlab_project.yml
Normal file
2
changelogs/fragments/66813_gitlab_project.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- gitlab_project - add support for merge_method on projects (https://github.com/ansible/ansible/pull/66813).
|
|
@ -8,7 +8,7 @@
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = r'''
|
||||||
---
|
---
|
||||||
module: gitlab_project
|
module: gitlab_project
|
||||||
short_description: Creates/updates/deletes GitLab Projects
|
short_description: Creates/updates/deletes GitLab Projects
|
||||||
|
@ -95,9 +95,17 @@ options:
|
||||||
default: present
|
default: present
|
||||||
type: str
|
type: str
|
||||||
choices: ["present", "absent"]
|
choices: ["present", "absent"]
|
||||||
|
merge_method:
|
||||||
|
description:
|
||||||
|
- What requirements are placed upon merges.
|
||||||
|
- Possible values are C(merge), C(rebase_merge) merge commit with semi-linear history, C(ff) fast-forward merges only.
|
||||||
|
type: str
|
||||||
|
choices: ["ff", "merge", "rebase_merge"]
|
||||||
|
default: merge
|
||||||
|
version_added: "1.0.0"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = r'''
|
||||||
- name: Delete GitLab Project
|
- name: Delete GitLab Project
|
||||||
community.general.gitlab_project:
|
community.general.gitlab_project:
|
||||||
api_url: https://gitlab.example.com/
|
api_url: https://gitlab.example.com/
|
||||||
|
@ -116,6 +124,7 @@ EXAMPLES = '''
|
||||||
name: my_first_project
|
name: my_first_project
|
||||||
group: ansible
|
group: ansible
|
||||||
issues_enabled: False
|
issues_enabled: False
|
||||||
|
merge_method: rebase_merge
|
||||||
wiki_enabled: True
|
wiki_enabled: True
|
||||||
snippets_enabled: True
|
snippets_enabled: True
|
||||||
import_url: http://git.example.com/example/lab.git
|
import_url: http://git.example.com/example/lab.git
|
||||||
|
@ -123,26 +132,26 @@ EXAMPLES = '''
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = r'''
|
||||||
msg:
|
msg:
|
||||||
description: Success or failure message
|
description: Success or failure message.
|
||||||
returned: always
|
returned: always
|
||||||
type: str
|
type: str
|
||||||
sample: "Success"
|
sample: "Success"
|
||||||
|
|
||||||
result:
|
result:
|
||||||
description: json parsed response from the server
|
description: json parsed response from the server.
|
||||||
returned: always
|
returned: always
|
||||||
type: dict
|
type: dict
|
||||||
|
|
||||||
error:
|
error:
|
||||||
description: the error message returned by the GitLab API
|
description: the error message returned by the GitLab API.
|
||||||
returned: failed
|
returned: failed
|
||||||
type: str
|
type: str
|
||||||
sample: "400: path is already in use"
|
sample: "400: path is already in use"
|
||||||
|
|
||||||
project:
|
project:
|
||||||
description: API object
|
description: API object.
|
||||||
returned: always
|
returned: always
|
||||||
type: dict
|
type: dict
|
||||||
'''
|
'''
|
||||||
|
@ -186,6 +195,7 @@ class GitLabProject(object):
|
||||||
'description': options['description'],
|
'description': options['description'],
|
||||||
'issues_enabled': options['issues_enabled'],
|
'issues_enabled': options['issues_enabled'],
|
||||||
'merge_requests_enabled': options['merge_requests_enabled'],
|
'merge_requests_enabled': options['merge_requests_enabled'],
|
||||||
|
'merge_method': options['merge_method'],
|
||||||
'wiki_enabled': options['wiki_enabled'],
|
'wiki_enabled': options['wiki_enabled'],
|
||||||
'snippets_enabled': options['snippets_enabled'],
|
'snippets_enabled': options['snippets_enabled'],
|
||||||
'visibility': options['visibility'],
|
'visibility': options['visibility'],
|
||||||
|
@ -197,6 +207,7 @@ class GitLabProject(object):
|
||||||
'description': options['description'],
|
'description': options['description'],
|
||||||
'issues_enabled': options['issues_enabled'],
|
'issues_enabled': options['issues_enabled'],
|
||||||
'merge_requests_enabled': options['merge_requests_enabled'],
|
'merge_requests_enabled': options['merge_requests_enabled'],
|
||||||
|
'merge_method': options['merge_method'],
|
||||||
'wiki_enabled': options['wiki_enabled'],
|
'wiki_enabled': options['wiki_enabled'],
|
||||||
'snippets_enabled': options['snippets_enabled'],
|
'snippets_enabled': options['snippets_enabled'],
|
||||||
'visibility': options['visibility']})
|
'visibility': options['visibility']})
|
||||||
|
@ -276,6 +287,7 @@ def main():
|
||||||
description=dict(type='str'),
|
description=dict(type='str'),
|
||||||
issues_enabled=dict(type='bool', default=True),
|
issues_enabled=dict(type='bool', default=True),
|
||||||
merge_requests_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"]),
|
||||||
wiki_enabled=dict(type='bool', default=True),
|
wiki_enabled=dict(type='bool', default=True),
|
||||||
snippets_enabled=dict(default=True, type='bool'),
|
snippets_enabled=dict(default=True, type='bool'),
|
||||||
visibility=dict(type='str', default="private", choices=["internal", "private", "public"], aliases=["visibility_level"]),
|
visibility=dict(type='str', default="private", choices=["internal", "private", "public"], aliases=["visibility_level"]),
|
||||||
|
@ -304,6 +316,7 @@ def main():
|
||||||
project_description = module.params['description']
|
project_description = module.params['description']
|
||||||
issues_enabled = module.params['issues_enabled']
|
issues_enabled = module.params['issues_enabled']
|
||||||
merge_requests_enabled = module.params['merge_requests_enabled']
|
merge_requests_enabled = module.params['merge_requests_enabled']
|
||||||
|
merge_method = module.params['merge_method']
|
||||||
wiki_enabled = module.params['wiki_enabled']
|
wiki_enabled = module.params['wiki_enabled']
|
||||||
snippets_enabled = module.params['snippets_enabled']
|
snippets_enabled = module.params['snippets_enabled']
|
||||||
visibility = module.params['visibility']
|
visibility = module.params['visibility']
|
||||||
|
@ -346,6 +359,7 @@ def main():
|
||||||
"description": project_description,
|
"description": project_description,
|
||||||
"issues_enabled": issues_enabled,
|
"issues_enabled": issues_enabled,
|
||||||
"merge_requests_enabled": merge_requests_enabled,
|
"merge_requests_enabled": merge_requests_enabled,
|
||||||
|
"merge_method": merge_method,
|
||||||
"wiki_enabled": wiki_enabled,
|
"wiki_enabled": wiki_enabled,
|
||||||
"snippets_enabled": snippets_enabled,
|
"snippets_enabled": snippets_enabled,
|
||||||
"visibility": visibility,
|
"visibility": visibility,
|
||||||
|
|
|
@ -353,7 +353,7 @@ PROJECT API
|
||||||
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects", method="get")
|
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects", method="get")
|
||||||
def resp_find_project(url, request):
|
def resp_find_project(url, request):
|
||||||
headers = {'content-type': 'application/json'}
|
headers = {'content-type': 'application/json'}
|
||||||
content = ('[{"id": 1,"description": null, "default_branch": "master",'
|
content = ('[{"id": 1,"description": null, "default_branch": "master", "merge_method": "merge",'
|
||||||
'"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",'
|
'"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",'
|
||||||
'"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",'
|
'"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",'
|
||||||
'"web_url": "http://example.com/diaspora/diaspora-client",'
|
'"web_url": "http://example.com/diaspora/diaspora-client",'
|
||||||
|
@ -371,7 +371,7 @@ def resp_find_project(url, request):
|
||||||
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1", method="get")
|
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1", method="get")
|
||||||
def resp_get_project(url, request):
|
def resp_get_project(url, request):
|
||||||
headers = {'content-type': 'application/json'}
|
headers = {'content-type': 'application/json'}
|
||||||
content = ('{"id": 1,"description": null, "default_branch": "master",'
|
content = ('{"id": 1,"description": null, "default_branch": "master", "merge_method": "merge",'
|
||||||
'"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",'
|
'"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",'
|
||||||
'"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",'
|
'"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",'
|
||||||
'"web_url": "http://example.com/diaspora/diaspora-client",'
|
'"web_url": "http://example.com/diaspora/diaspora-client",'
|
||||||
|
@ -389,7 +389,7 @@ def resp_get_project(url, request):
|
||||||
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/foo-bar%2Fdiaspora-client", method="get")
|
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/foo-bar%2Fdiaspora-client", method="get")
|
||||||
def resp_get_project_by_name(url, request):
|
def resp_get_project_by_name(url, request):
|
||||||
headers = {'content-type': 'application/json'}
|
headers = {'content-type': 'application/json'}
|
||||||
content = ('{"id": 1,"description": null, "default_branch": "master",'
|
content = ('{"id": 1,"description": null, "default_branch": "master", "merge_method": "merge",'
|
||||||
'"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",'
|
'"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",'
|
||||||
'"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",'
|
'"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",'
|
||||||
'"web_url": "http://example.com/diaspora/diaspora-client",'
|
'"web_url": "http://example.com/diaspora/diaspora-client",'
|
||||||
|
@ -407,7 +407,7 @@ def resp_get_project_by_name(url, request):
|
||||||
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1/projects", method="get")
|
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1/projects", method="get")
|
||||||
def resp_find_group_project(url, request):
|
def resp_find_group_project(url, request):
|
||||||
headers = {'content-type': 'application/json'}
|
headers = {'content-type': 'application/json'}
|
||||||
content = ('[{"id": 1,"description": null, "default_branch": "master",'
|
content = ('[{"id": 1,"description": null, "default_branch": "master", "merge_method": "merge",'
|
||||||
'"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",'
|
'"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",'
|
||||||
'"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",'
|
'"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",'
|
||||||
'"web_url": "http://example.com/diaspora/diaspora-client",'
|
'"web_url": "http://example.com/diaspora/diaspora-client",'
|
||||||
|
@ -425,7 +425,7 @@ def resp_find_group_project(url, request):
|
||||||
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1/projects/1", method="get")
|
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1/projects/1", method="get")
|
||||||
def resp_get_group_project(url, request):
|
def resp_get_group_project(url, request):
|
||||||
headers = {'content-type': 'application/json'}
|
headers = {'content-type': 'application/json'}
|
||||||
content = ('{"id": 1,"description": null, "default_branch": "master",'
|
content = ('{"id": 1,"description": null, "default_branch": "master", "merge_method": "merge",'
|
||||||
'"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",'
|
'"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",'
|
||||||
'"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",'
|
'"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",'
|
||||||
'"web_url": "http://example.com/diaspora/diaspora-client",'
|
'"web_url": "http://example.com/diaspora/diaspora-client",'
|
||||||
|
@ -443,7 +443,7 @@ def resp_get_group_project(url, request):
|
||||||
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects", method="post")
|
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects", method="post")
|
||||||
def resp_create_project(url, request):
|
def resp_create_project(url, request):
|
||||||
headers = {'content-type': 'application/json'}
|
headers = {'content-type': 'application/json'}
|
||||||
content = ('{"id": 1,"description": null, "default_branch": "master",'
|
content = ('{"id": 1,"description": null, "default_branch": "master", "merge_method": "merge",'
|
||||||
'"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",'
|
'"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",'
|
||||||
'"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",'
|
'"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",'
|
||||||
'"web_url": "http://example.com/diaspora/diaspora-client",'
|
'"web_url": "http://example.com/diaspora/diaspora-client",'
|
||||||
|
|
|
@ -91,6 +91,26 @@ class TestGitlabProject(GitlabModuleTestCase):
|
||||||
self.assertEqual(changed, False)
|
self.assertEqual(changed, False)
|
||||||
self.assertEqual(newProject.name, "New Name")
|
self.assertEqual(newProject.name, "New Name")
|
||||||
|
|
||||||
|
@with_httmock(resp_get_project)
|
||||||
|
def test_update_project_merge_method(self):
|
||||||
|
project = self.gitlab_instance.projects.get(1)
|
||||||
|
|
||||||
|
# merge_method should be 'merge' by default
|
||||||
|
self.assertEqual(project.merge_method, "merge")
|
||||||
|
|
||||||
|
changed, newProject = self.moduleUtil.updateProject(project, {"name": "New Name", "merge_method": "rebase_merge"})
|
||||||
|
|
||||||
|
self.assertEqual(changed, True)
|
||||||
|
self.assertEqual(type(newProject), Project)
|
||||||
|
self.assertEqual(newProject.name, "New Name")
|
||||||
|
self.assertEqual(newProject.merge_method, "rebase_merge")
|
||||||
|
|
||||||
|
changed, newProject = self.moduleUtil.updateProject(project, {"name": "New Name", "merge_method": "rebase_merge"})
|
||||||
|
|
||||||
|
self.assertEqual(changed, False)
|
||||||
|
self.assertEqual(newProject.name, "New Name")
|
||||||
|
self.assertEqual(newProject.merge_method, "rebase_merge")
|
||||||
|
|
||||||
@with_httmock(resp_get_group)
|
@with_httmock(resp_get_group)
|
||||||
@with_httmock(resp_get_project_by_name)
|
@with_httmock(resp_get_project_by_name)
|
||||||
@with_httmock(resp_delete_project)
|
@with_httmock(resp_delete_project)
|
||||||
|
|
Loading…
Reference in a new issue