Skip to content

Commit

Permalink
[PR #6278/cee5f31b backport][stable-6] Add support to topics on Gitla…
Browse files Browse the repository at this point in the history
…b Project module (#6283)

Add support to topics on Gitlab Project module (#6278)

* add topics to gitlab_project.py

* add chngelog fragment

* fix lint error

* Update changelogs/fragments/6277-add-topics-gitlab-project.yml

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

* Apply suggestions from code review

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

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit cee5f31)

Co-authored-by: Lorenzo Tanganelli <35271287+tanganellilore@users.noreply.github.com>
  • Loading branch information
patchback[bot] and tanganellilore authored Apr 3, 2023
1 parent f0320b5 commit f6d15ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/6277-add-topics-gitlab-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- gitlab_project - add new option ``topics`` for adding topics to GitLab projects (https://github.com/ansible-collections/community.general/pull/6278).
20 changes: 20 additions & 0 deletions plugins/modules/gitlab_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@
type: str
choices: ["private", "disabled", "enabled"]
version_added: "6.4.0"
topics:
description:
- A topic or list of topics to be assigned to a project.
- It is compatible with old GitLab server releases (versions before 14, correspond to C(tag_list)).
type: list
elements: str
version_added: "6.6.0"
'''

EXAMPLES = r'''
Expand Down Expand Up @@ -334,6 +341,8 @@
auth_argument_spec, find_group, find_project, gitlab_authentication, gitlab, ensure_gitlab_package
)

from ansible_collections.community.general.plugins.module_utils.version import LooseVersion


class GitLabProject(object):
def __init__(self, module, gitlab_instance):
Expand Down Expand Up @@ -376,6 +385,14 @@ def create_or_update_project(self, project_name, namespace, options):
'monitor_access_level': options['monitor_access_level'],
'security_and_compliance_access_level': options['security_and_compliance_access_level'],
}

# topics was introduced on gitlab >=14 and replace tag_list. We get current gitlab version
# and check if less than 14. If yes we use tag_list instead topics
if LooseVersion(self._gitlab.version()[0]) < LooseVersion("14"):
project_options['tag_list'] = options['topics']
else:
project_options['topics'] = options['topics']

# Because we have already call userExists in main()
if self.project_object is None:
project_options.update({
Expand Down Expand Up @@ -514,6 +531,7 @@ def main():
infrastructure_access_level=dict(type='str', choices=['private', 'disabled', 'enabled']),
monitor_access_level=dict(type='str', choices=['private', 'disabled', 'enabled']),
security_and_compliance_access_level=dict(type='str', choices=['private', 'disabled', 'enabled']),
topics=dict(type='list', elements='str'),
))

module = AnsibleModule(
Expand Down Expand Up @@ -570,6 +588,7 @@ def main():
infrastructure_access_level = module.params['infrastructure_access_level']
monitor_access_level = module.params['monitor_access_level']
security_and_compliance_access_level = module.params['security_and_compliance_access_level']
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")
Expand Down Expand Up @@ -648,6 +667,7 @@ def main():
"infrastructure_access_level": infrastructure_access_level,
"monitor_access_level": monitor_access_level,
"security_and_compliance_access_level": security_and_compliance_access_level,
"topics": topics,
}):

module.exit_json(changed=True, msg="Successfully created or updated the project %s" % project_name, project=gitlab_project.project_object._attrs)
Expand Down

0 comments on commit f6d15ec

Please sign in to comment.