From 1877ef1510175566c5ce08129929c0fe253d67ff Mon Sep 17 00:00:00 2001 From: dima1206 <32818228+dima1206@users.noreply.github.com> Date: Sat, 25 Feb 2023 12:03:13 +0200 Subject: [PATCH] github_webhook: Don't include secret in the config if it's absent (#5994) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * github_webhook: Don't include secret in the config if it's absent * Add changelogs * Fix indentation * Apply suggestion to simplify the check Co-authored-by: Felix Fontein --------- Co-authored-by: dima1206 <–32818228+dima1206@users.noreply.github.com> Co-authored-by: Felix Fontein --- changelogs/fragments/5994-github-webhook-secret.yml | 2 ++ plugins/modules/github_webhook.py | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/5994-github-webhook-secret.yml diff --git a/changelogs/fragments/5994-github-webhook-secret.yml b/changelogs/fragments/5994-github-webhook-secret.yml new file mode 100644 index 0000000000..700703840c --- /dev/null +++ b/changelogs/fragments/5994-github-webhook-secret.yml @@ -0,0 +1,2 @@ +bugfixes: + - github_webhook - fix always changed state when no secret is provided (https://github.com/ansible-collections/community.general/pull/5994). \ No newline at end of file diff --git a/plugins/modules/github_webhook.py b/plugins/modules/github_webhook.py index 71e199adbe..d47b7a82fa 100644 --- a/plugins/modules/github_webhook.py +++ b/plugins/modules/github_webhook.py @@ -161,13 +161,18 @@ from ansible.module_utils.common.text.converters import to_native def _create_hook_config(module): - return { + hook_config = { "url": module.params["url"], "content_type": module.params["content_type"], - "secret": module.params.get("secret"), "insecure_ssl": "1" if module.params["insecure_ssl"] else "0" } + secret = module.params.get("secret") + if secret: + hook_config["secret"] = secret + + return hook_config + def create_hook(repo, module): config = _create_hook_config(module)