mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-10 11:51:49 +00:00
[PR #11917/798439f1 backport][stable-12] Fix gitlab_hook: add default value for releases_events parameter (#12017)
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()`
* Update plugins/modules/gitlab_hook.py
Remove the null check for `options[“releases_events”]`
---------
(cherry picked from commit 798439f1fe)
Co-authored-by: RealCharlesChia <161665317+RealCharlesChia@users.noreply.github.com>
Co-authored-by: Charles Chia <charleschia@email.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
4ecae71dc9
commit
b3669957d9
2 changed files with 26 additions and 35 deletions
|
|
@ -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).
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue