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

gitlab_project - Add ability to create project under a user (#2824)

* Add ability to create project under a user

* Add changelog

* Add username option

* Update changelogs/fragments/2824-gitlab_project-project-under-user.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Make group and username mutually exclusive

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Stef Graces 2021-06-27 16:09:41 +02:00 committed by GitHub
parent 199ead85d0
commit c7cf6f2eb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -0,0 +1,3 @@
---
minor_changes:
- gitlab_project - projects can be created under other user's namespaces with the new ``username`` option (https://github.com/ansible-collections/community.general/pull/2824).

View file

@ -109,6 +109,11 @@ options:
required: false required: false
default: false default: false
version_added: "2.0.0" version_added: "2.0.0"
username:
description:
- Used to create a personal project under a user's name.
type: str
version_added: "3.3.0"
''' '''
EXAMPLES = r''' EXAMPLES = r'''
@ -302,6 +307,7 @@ def main():
import_url=dict(type='str'), import_url=dict(type='str'),
state=dict(type='str', default="present", choices=["absent", "present"]), state=dict(type='str', default="present", choices=["absent", "present"]),
lfs_enabled=dict(default=False, type='bool'), lfs_enabled=dict(default=False, type='bool'),
username=dict(type='str'),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -309,6 +315,7 @@ def main():
mutually_exclusive=[ mutually_exclusive=[
['api_username', 'api_token'], ['api_username', 'api_token'],
['api_password', 'api_token'], ['api_password', 'api_token'],
['group', 'username'],
], ],
required_together=[ required_together=[
['api_username', 'api_password'], ['api_username', 'api_password'],
@ -332,6 +339,7 @@ def main():
import_url = module.params['import_url'] import_url = module.params['import_url']
state = module.params['state'] state = module.params['state']
lfs_enabled = module.params['lfs_enabled'] lfs_enabled = module.params['lfs_enabled']
username = module.params['username']
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)
@ -352,6 +360,9 @@ def main():
module.fail_json(msg="Failed to create project: group %s doesn't exists" % group_identifier) module.fail_json(msg="Failed to create project: group %s doesn't exists" % group_identifier)
namespace_id = group.id namespace_id = group.id
else:
if username:
namespace = gitlab_instance.namespaces.list(search=username)[0]
else: else:
namespace = gitlab_instance.namespaces.list(search=gitlab_instance.user.username)[0] namespace = gitlab_instance.namespaces.list(search=gitlab_instance.user.username)[0]
namespace_id = namespace.id namespace_id = namespace.id