From 798439f1fe437c7d0ad5e594e99c52889be76879 Mon Sep 17 00:00:00 2001 From: RealCharlesChia <161665317+RealCharlesChia@users.noreply.github.com> Date: Sun, 10 May 2026 03:52:48 +0800 Subject: [PATCH] Fix gitlab_hook: add default value for releases_events parameter (#11917) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix gitlab_hook: only pass releases_events to API when specified The releases_events parameter now only gets passed to the GitLab API: - On create: always passed (fixes 500 error when not specified) - On update: only passed when explicitly specified by user This avoids forcing the releases_events value during updates when not intended by the user. Fixes: https://github.com/ansible-collections/community.general/issues/11269 * Add changelog fragment for gitlab_hook releases_events fix Fixes: https://github.com/ansible-collections/community.general/issues/11269 * Add PR link to changelog fragment * Use .get() for safer dict access in releases_events handling * Update plugins/modules/gitlab_hook.py remove `.get()` Co-authored-by: Felix Fontein * Update plugins/modules/gitlab_hook.py Remove the null check for `options[“releases_events”]` Co-authored-by: Felix Fontein --------- Co-authored-by: Charles Chia Co-authored-by: Felix Fontein --- .../11269-gitlab-hook-releases-events.yaml | 5 ++ plugins/modules/gitlab_hook.py | 56 +++++++------------ 2 files changed, 26 insertions(+), 35 deletions(-) create mode 100644 changelogs/fragments/11269-gitlab-hook-releases-events.yaml 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: