diff --git a/changelogs/fragments/11269-gitlab-hook-releases-events.yaml b/changelogs/fragments/11269-gitlab-hook-releases-events.yaml new file mode 100644 index 0000000000..ea20f3d71f --- /dev/null +++ b/changelogs/fragments/11269-gitlab-hook-releases-events.yaml @@ -0,0 +1,5 @@ +--- +bugfixes: + - gitlab_hook - now properly passes the ``releases_events`` parameter to the GitLab API on hook creation, + fixing a 500 Internal Server Error when the parameter was not specified + (https://github.com/ansible-collections/community.general/issues/11269, https://github.com/ansible-collections/community.general/pull/11917). \ No newline at end of file diff --git a/plugins/modules/gitlab_hook.py b/plugins/modules/gitlab_hook.py index acf13d1ae2..7a35b81d51 100644 --- a/plugins/modules/gitlab_hook.py +++ b/plugins/modules/gitlab_hook.py @@ -193,45 +193,31 @@ class GitLabHook: def create_or_update_hook(self, project, hook_url, options): changed = False + hook_arguments = { + "url": hook_url, + "push_events": options["push_events"], + "push_events_branch_filter": options["push_events_branch_filter"], + "issues_events": options["issues_events"], + "merge_requests_events": options["merge_requests_events"], + "tag_push_events": options["tag_push_events"], + "note_events": options["note_events"], + "job_events": options["job_events"], + "pipeline_events": options["pipeline_events"], + "wiki_page_events": options["wiki_page_events"], + "enable_ssl_verification": options["enable_ssl_verification"], + "token": options["token"], + } + # Because we have already call userExists in main() if self.hook_object is None: - hook = self.create_hook( - project, - { - "url": hook_url, - "push_events": options["push_events"], - "push_events_branch_filter": options["push_events_branch_filter"], - "issues_events": options["issues_events"], - "merge_requests_events": options["merge_requests_events"], - "tag_push_events": options["tag_push_events"], - "note_events": options["note_events"], - "job_events": options["job_events"], - "pipeline_events": options["pipeline_events"], - "wiki_page_events": options["wiki_page_events"], - "releases_events": options["releases_events"], - "enable_ssl_verification": options["enable_ssl_verification"], - "token": options["token"], - }, - ) + if options["releases_events"] is not None: + hook_arguments["releases_events"] = options["releases_events"] + hook = self.create_hook(project, hook_arguments) changed = True else: - changed, hook = self.update_hook( - self.hook_object, - { - "push_events": options["push_events"], - "push_events_branch_filter": options["push_events_branch_filter"], - "issues_events": options["issues_events"], - "merge_requests_events": options["merge_requests_events"], - "tag_push_events": options["tag_push_events"], - "note_events": options["note_events"], - "job_events": options["job_events"], - "pipeline_events": options["pipeline_events"], - "wiki_page_events": options["wiki_page_events"], - "releases_events": options["releases_events"], - "enable_ssl_verification": options["enable_ssl_verification"], - "token": options["token"], - }, - ) + update_arguments = hook_arguments.copy() + update_arguments["releases_events"] = options["releases_events"] + changed, hook = self.update_hook(self.hook_object, update_arguments) self.hook_object = hook if changed: