Skip to content

Commit

Permalink
Fix gitlab_project container_expiration_policy for project create (#8790
Browse files Browse the repository at this point in the history
)

* Fix gitlab_project container_expiration_policy for project create

* Check for container_expiration_policy presence before renaming it

* Add missing links to changelog fragment

* Fix changelog grammar
  • Loading branch information
vvirrank authored Aug 25, 2024
1 parent 4598758 commit 573a7b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- gitlab_project - fix crash caused by old Gitlab projects not having a ``container_expiration_policy`` attribute (https://github.com/ansible-collections/community.general/pull/8790).
- gitlab_project - fix ``container_expiration_policy`` not being applied when creating a new project (https://github.com/ansible-collections/community.general/pull/8790).
6 changes: 4 additions & 2 deletions plugins/modules/gitlab_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ def create_project(self, namespace, arguments):
return True

arguments['namespace_id'] = namespace.id
if 'container_expiration_policy' in arguments:
arguments['container_expiration_policy_attributes'] = arguments['container_expiration_policy']
try:
project = self._gitlab.projects.create(arguments)
except (gitlab.exceptions.GitlabCreateError) as e:
Expand Down Expand Up @@ -548,9 +550,9 @@ def update_project(self, project, arguments):

for arg_key, arg_value in arguments.items():
if arguments[arg_key] is not None:
if getattr(project, arg_key) != arguments[arg_key]:
if getattr(project, arg_key, None) != arguments[arg_key]:
if arg_key == 'container_expiration_policy':
old_val = getattr(project, arg_key)
old_val = getattr(project, arg_key, {})
final_val = {key: value for key, value in arg_value.items() if value is not None}

if final_val.get('older_than') == '0d':
Expand Down

0 comments on commit 573a7b9

Please sign in to comment.