1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-05-10 11:51:49 +00:00

Fix gitlab_hook: add default value for releases_events parameter (#11917)

* 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 <felix@fontein.de>

* Update plugins/modules/gitlab_hook.py

Remove the null check for `options[“releases_events”]`

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

---------

Co-authored-by: Charles Chia <charleschia@email.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
RealCharlesChia 2026-05-10 03:52:48 +08:00 committed by GitHub
parent cdd0d2521e
commit 798439f1fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 35 deletions

View file

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

View file

@ -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: