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

[PR #8790/573a7b97 backport][stable-9] Fix gitlab_project container_expiration_policy for project create (#8801)

Fix gitlab_project container_expiration_policy for project create (#8790)

* 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

(cherry picked from commit 573a7b97c6)

Co-authored-by: Veikko Virrankoski <71337077+vvirrank@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2024-08-26 11:35:05 +02:00 committed by GitHub
parent 812431e7fe
commit 5e1be68b01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View file

@ -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).

View file

@ -512,6 +512,8 @@ class GitLabProject(object):
return True return True
arguments['namespace_id'] = namespace.id arguments['namespace_id'] = namespace.id
if 'container_expiration_policy' in arguments:
arguments['container_expiration_policy_attributes'] = arguments['container_expiration_policy']
try: try:
project = self._gitlab.projects.create(arguments) project = self._gitlab.projects.create(arguments)
except (gitlab.exceptions.GitlabCreateError) as e: except (gitlab.exceptions.GitlabCreateError) as e:
@ -539,9 +541,9 @@ class GitLabProject(object):
for arg_key, arg_value in arguments.items(): for arg_key, arg_value in arguments.items():
if arguments[arg_key] is not None: 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': 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} final_val = {key: value for key, value in arg_value.items() if value is not None}
if final_val.get('older_than') == '0d': if final_val.get('older_than') == '0d':