mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Adds few more gitlab group options (#3248)
* Adds few more gitlab group options * Update plugins/modules/source_control/gitlab/gitlab_group.py Co-authored-by: Felix Fontein <felix@fontein.de> * Removes default for new string options * Removes default from argument_spec * Adds changelog fragment * Update plugins/modules/source_control/gitlab/gitlab_group.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/source_control/gitlab/gitlab_group.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/source_control/gitlab/gitlab_group.py Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Maik Schueller <maik.schueller@sap.com> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
05fe587a3e
commit
58d018ebbd
5 changed files with 96 additions and 8 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- gitlab_group - add new options ``project_creation_level``, ``auto_devops_enabled``, ``subgroup_creation_level`` (https://github.com/ansible-collections/community.general/pull/3248).
|
|
@ -61,6 +61,23 @@ options:
|
||||||
choices: ["private", "internal", "public"]
|
choices: ["private", "internal", "public"]
|
||||||
default: private
|
default: private
|
||||||
type: str
|
type: str
|
||||||
|
project_creation_level:
|
||||||
|
description:
|
||||||
|
- Determine if developers can create projects in the group.
|
||||||
|
choices: ["developer", "maintainer", "noone"]
|
||||||
|
type: str
|
||||||
|
version_added: 3.7.0
|
||||||
|
auto_devops_enabled:
|
||||||
|
description:
|
||||||
|
- Default to Auto DevOps pipeline for all projects within this group.
|
||||||
|
type: bool
|
||||||
|
version_added: 3.7.0
|
||||||
|
subgroup_creation_level:
|
||||||
|
description:
|
||||||
|
- Allowed to create subgroups.
|
||||||
|
choices: ["maintainer", "owner"]
|
||||||
|
type: str
|
||||||
|
version_added: 3.7.0
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
@ -93,6 +110,20 @@ EXAMPLES = '''
|
||||||
path: my_first_group
|
path: my_first_group
|
||||||
state: present
|
state: present
|
||||||
parent: "super_parent/parent"
|
parent: "super_parent/parent"
|
||||||
|
|
||||||
|
# Other group which only allows sub-groups - no projects
|
||||||
|
- name: "Create GitLab Group for SubGroups only"
|
||||||
|
community.general.gitlab_group:
|
||||||
|
api_url: https://gitlab.example.com/
|
||||||
|
validate_certs: True
|
||||||
|
api_username: dj-wasabi
|
||||||
|
api_password: "MySecretPassword"
|
||||||
|
name: my_main_group
|
||||||
|
path: my_main_group
|
||||||
|
state: present
|
||||||
|
project_creation_level: noone
|
||||||
|
auto_devops_enabled: false
|
||||||
|
subgroup_creation_level: maintainer
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -166,7 +197,10 @@ class GitLabGroup(object):
|
||||||
'name': name,
|
'name': name,
|
||||||
'path': options['path'],
|
'path': options['path'],
|
||||||
'parent_id': parent_id,
|
'parent_id': parent_id,
|
||||||
'visibility': options['visibility']
|
'visibility': options['visibility'],
|
||||||
|
'project_creation_level': options['project_creation_level'],
|
||||||
|
'auto_devops_enabled': options['auto_devops_enabled'],
|
||||||
|
'subgroup_creation_level': options['subgroup_creation_level'],
|
||||||
}
|
}
|
||||||
if options.get('description'):
|
if options.get('description'):
|
||||||
payload['description'] = options['description']
|
payload['description'] = options['description']
|
||||||
|
@ -176,7 +210,11 @@ class GitLabGroup(object):
|
||||||
changed, group = self.updateGroup(self.groupObject, {
|
changed, group = self.updateGroup(self.groupObject, {
|
||||||
'name': name,
|
'name': name,
|
||||||
'description': options['description'],
|
'description': options['description'],
|
||||||
'visibility': options['visibility']})
|
'visibility': options['visibility'],
|
||||||
|
'project_creation_level': options['project_creation_level'],
|
||||||
|
'auto_devops_enabled': options['auto_devops_enabled'],
|
||||||
|
'subgroup_creation_level': options['subgroup_creation_level'],
|
||||||
|
})
|
||||||
|
|
||||||
self.groupObject = group
|
self.groupObject = group
|
||||||
if changed:
|
if changed:
|
||||||
|
@ -258,6 +296,9 @@ def main():
|
||||||
state=dict(type='str', default="present", choices=["absent", "present"]),
|
state=dict(type='str', default="present", choices=["absent", "present"]),
|
||||||
parent=dict(type='str'),
|
parent=dict(type='str'),
|
||||||
visibility=dict(type='str', default="private", choices=["internal", "private", "public"]),
|
visibility=dict(type='str', default="private", choices=["internal", "private", "public"]),
|
||||||
|
project_creation_level=dict(type='str', choices=['developer', 'maintainer', 'noone']),
|
||||||
|
auto_devops_enabled=dict(type='bool'),
|
||||||
|
subgroup_creation_level=dict(type='str', choices=['maintainer', 'owner']),
|
||||||
))
|
))
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
|
@ -281,6 +322,9 @@ def main():
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
parent_identifier = module.params['parent']
|
parent_identifier = module.params['parent']
|
||||||
group_visibility = module.params['visibility']
|
group_visibility = module.params['visibility']
|
||||||
|
project_creation_level = module.params['project_creation_level']
|
||||||
|
auto_devops_enabled = module.params['auto_devops_enabled']
|
||||||
|
subgroup_creation_level = module.params['subgroup_creation_level']
|
||||||
|
|
||||||
if not HAS_GITLAB_PACKAGE:
|
if not HAS_GITLAB_PACKAGE:
|
||||||
module.fail_json(msg=missing_required_lib("python-gitlab"), exception=GITLAB_IMP_ERR)
|
module.fail_json(msg=missing_required_lib("python-gitlab"), exception=GITLAB_IMP_ERR)
|
||||||
|
@ -314,7 +358,10 @@ def main():
|
||||||
if gitlab_group.createOrUpdateGroup(group_name, parent_group, {
|
if gitlab_group.createOrUpdateGroup(group_name, parent_group, {
|
||||||
"path": group_path,
|
"path": group_path,
|
||||||
"description": description,
|
"description": description,
|
||||||
"visibility": group_visibility}):
|
"visibility": group_visibility,
|
||||||
|
"project_creation_level": project_creation_level,
|
||||||
|
"auto_devops_enabled": auto_devops_enabled,
|
||||||
|
"subgroup_creation_level": subgroup_creation_level}):
|
||||||
module.exit_json(changed=True, msg="Successfully created or updated the group %s" % group_name, group=gitlab_group.groupObject._attrs)
|
module.exit_json(changed=True, msg="Successfully created or updated the group %s" % group_name, group=gitlab_group.groupObject._attrs)
|
||||||
else:
|
else:
|
||||||
module.exit_json(changed=False, msg="No need to update the group %s" % group_name, group=gitlab_group.groupObject._attrs)
|
module.exit_json(changed=False, msg="No need to update the group %s" % group_name, group=gitlab_group.groupObject._attrs)
|
||||||
|
|
|
@ -72,3 +72,28 @@
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- gitlab_group_state_desc.group.description == "My Test Group"
|
- gitlab_group_state_desc.group.description == "My Test Group"
|
||||||
|
|
||||||
|
- name: Cleanup GitLab Group for project_creation_level Test
|
||||||
|
gitlab_group:
|
||||||
|
api_url: "{{ gitlab_host }}"
|
||||||
|
validate_certs: false
|
||||||
|
api_token: "{{ gitlab_login_token }}"
|
||||||
|
name: ansible_test_group
|
||||||
|
path: ansible_test_group
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Create GitLab Group for project_creation_level Test
|
||||||
|
gitlab_group:
|
||||||
|
api_url: "{{ gitlab_host }}"
|
||||||
|
validate_certs: false
|
||||||
|
api_token: "{{ gitlab_login_token }}"
|
||||||
|
name: ansible_test_group
|
||||||
|
path: ansible_test_group
|
||||||
|
project_creation_level: noone
|
||||||
|
state: present
|
||||||
|
register: gitlab_group_state_pcl
|
||||||
|
|
||||||
|
- name: Test group created with project_creation_level
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- gitlab_group_state_pcl.group.project_creation_level == "noone"
|
||||||
|
|
|
@ -194,6 +194,7 @@ def resp_get_group(url, request):
|
||||||
'"lfs_enabled": true, "avatar_url": "http://localhost:3000/uploads/group/avatar/1/foo.jpg",'
|
'"lfs_enabled": true, "avatar_url": "http://localhost:3000/uploads/group/avatar/1/foo.jpg",'
|
||||||
'"web_url": "http://localhost:3000/groups/foo-bar", "request_access_enabled": false,'
|
'"web_url": "http://localhost:3000/groups/foo-bar", "request_access_enabled": false,'
|
||||||
'"full_name": "Foobar Group", "full_path": "foo-bar",'
|
'"full_name": "Foobar Group", "full_path": "foo-bar",'
|
||||||
|
'"project_creation_level": "maintainer", "subgroup_creation_level": "maintainer",'
|
||||||
'"file_template_project_id": 1, "parent_id": null, "projects": [{"id": 1,"description": null, "default_branch": "master",'
|
'"file_template_project_id": 1, "parent_id": null, "projects": [{"id": 1,"description": null, "default_branch": "master",'
|
||||||
'"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",'
|
||||||
|
@ -225,7 +226,8 @@ def resp_create_group(url, request):
|
||||||
'"lfs_enabled": true, "avatar_url": "http://localhost:3000/uploads/group/avatar/1/foo.jpg",'
|
'"lfs_enabled": true, "avatar_url": "http://localhost:3000/uploads/group/avatar/1/foo.jpg",'
|
||||||
'"web_url": "http://localhost:3000/groups/foo-bar", "request_access_enabled": false,'
|
'"web_url": "http://localhost:3000/groups/foo-bar", "request_access_enabled": false,'
|
||||||
'"full_name": "Foobar Group", "full_path": "foo-bar",'
|
'"full_name": "Foobar Group", "full_path": "foo-bar",'
|
||||||
'"file_template_project_id": 1, "parent_id": null}')
|
'"file_template_project_id": 1, "parent_id": null,'
|
||||||
|
'"project_creation_level": "developer", "subgroup_creation_level": "maintainer"}')
|
||||||
content = content.encode("utf-8")
|
content = content.encode("utf-8")
|
||||||
return response(200, content, headers, None, 5, request)
|
return response(200, content, headers, None, 5, request)
|
||||||
|
|
||||||
|
@ -238,7 +240,8 @@ def resp_create_subgroup(url, request):
|
||||||
'"lfs_enabled": true, "avatar_url": "http://localhost:3000/uploads/group/avatar/2/bar.jpg",'
|
'"lfs_enabled": true, "avatar_url": "http://localhost:3000/uploads/group/avatar/2/bar.jpg",'
|
||||||
'"web_url": "http://localhost:3000/groups/foo-bar/bar-foo", "request_access_enabled": false,'
|
'"web_url": "http://localhost:3000/groups/foo-bar/bar-foo", "request_access_enabled": false,'
|
||||||
'"full_name": "BarFoo Group", "full_path": "foo-bar/bar-foo",'
|
'"full_name": "BarFoo Group", "full_path": "foo-bar/bar-foo",'
|
||||||
'"file_template_project_id": 1, "parent_id": 1}')
|
'"file_template_project_id": 1, "parent_id": 1,'
|
||||||
|
'"project_creation_level": "noone"}')
|
||||||
content = content.encode("utf-8")
|
content = content.encode("utf-8")
|
||||||
return response(200, content, headers, None, 5, request)
|
return response(200, content, headers, None, 5, request)
|
||||||
|
|
||||||
|
|
|
@ -68,32 +68,43 @@ class TestGitlabGroup(GitlabModuleTestCase):
|
||||||
def test_create_group(self):
|
def test_create_group(self):
|
||||||
group = self.moduleUtil.createGroup({'name': "Foobar Group",
|
group = self.moduleUtil.createGroup({'name': "Foobar Group",
|
||||||
'path': "foo-bar",
|
'path': "foo-bar",
|
||||||
'description': "An interesting group"})
|
'description': "An interesting group",
|
||||||
|
'project_creation_level': "developer",
|
||||||
|
'subgroup_creation_level': "maintainer"})
|
||||||
|
|
||||||
self.assertEqual(type(group), Group)
|
self.assertEqual(type(group), Group)
|
||||||
self.assertEqual(group.name, "Foobar Group")
|
self.assertEqual(group.name, "Foobar Group")
|
||||||
self.assertEqual(group.path, "foo-bar")
|
self.assertEqual(group.path, "foo-bar")
|
||||||
self.assertEqual(group.description, "An interesting group")
|
self.assertEqual(group.description, "An interesting group")
|
||||||
|
self.assertEqual(group.project_creation_level, "developer")
|
||||||
|
self.assertEqual(group.subgroup_creation_level, "maintainer")
|
||||||
self.assertEqual(group.id, 1)
|
self.assertEqual(group.id, 1)
|
||||||
|
|
||||||
@with_httmock(resp_create_subgroup)
|
@with_httmock(resp_create_subgroup)
|
||||||
def test_create_subgroup(self):
|
def test_create_subgroup(self):
|
||||||
group = self.moduleUtil.createGroup({'name': "BarFoo Group", 'path': "bar-foo", "parent_id": 1})
|
group = self.moduleUtil.createGroup({'name': "BarFoo Group",
|
||||||
|
'path': "bar-foo",
|
||||||
|
'parent_id': 1,
|
||||||
|
'project_creation_level': "noone"})
|
||||||
|
|
||||||
self.assertEqual(type(group), Group)
|
self.assertEqual(type(group), Group)
|
||||||
self.assertEqual(group.name, "BarFoo Group")
|
self.assertEqual(group.name, "BarFoo Group")
|
||||||
self.assertEqual(group.full_path, "foo-bar/bar-foo")
|
self.assertEqual(group.full_path, "foo-bar/bar-foo")
|
||||||
|
self.assertEqual(group.project_creation_level, "noone")
|
||||||
self.assertEqual(group.id, 2)
|
self.assertEqual(group.id, 2)
|
||||||
self.assertEqual(group.parent_id, 1)
|
self.assertEqual(group.parent_id, 1)
|
||||||
|
|
||||||
@with_httmock(resp_get_group)
|
@with_httmock(resp_get_group)
|
||||||
def test_update_group(self):
|
def test_update_group(self):
|
||||||
group = self.gitlab_instance.groups.get(1)
|
group = self.gitlab_instance.groups.get(1)
|
||||||
changed, newGroup = self.moduleUtil.updateGroup(group, {'name': "BarFoo Group", "visibility": "private"})
|
changed, newGroup = self.moduleUtil.updateGroup(group, {'name': "BarFoo Group",
|
||||||
|
'visibility': "private",
|
||||||
|
'project_creation_level': "maintainer"})
|
||||||
|
|
||||||
self.assertEqual(changed, True)
|
self.assertEqual(changed, True)
|
||||||
self.assertEqual(newGroup.name, "BarFoo Group")
|
self.assertEqual(newGroup.name, "BarFoo Group")
|
||||||
self.assertEqual(newGroup.visibility, "private")
|
self.assertEqual(newGroup.visibility, "private")
|
||||||
|
self.assertEqual(newGroup.project_creation_level, "maintainer")
|
||||||
|
|
||||||
changed, newGroup = self.moduleUtil.updateGroup(group, {'name': "BarFoo Group"})
|
changed, newGroup = self.moduleUtil.updateGroup(group, {'name': "BarFoo Group"})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue