From 199dcc282c6e60b03bf218ae2da2c9bb41c9eec8 Mon Sep 17 00:00:00 2001 From: dima1206 <–32818228+dima1206@users.noreply.github.com> Date: Wed, 15 Feb 2023 17:41:31 +0200 Subject: [PATCH 1/4] github_webhook: Don't include secret in the config if it's absent --- plugins/modules/github_webhook.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/modules/github_webhook.py b/plugins/modules/github_webhook.py index b97087d221e..2adaeedc75d 100644 --- a/plugins/modules/github_webhook.py +++ b/plugins/modules/github_webhook.py @@ -154,13 +154,18 @@ 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 is not None and len(secret) > 0: + hook_config["secret"] = secret + + return hook_config + def create_hook(repo, module): config = _create_hook_config(module) From 998d01f545b878027454dd934d9d76ed7af72632 Mon Sep 17 00:00:00 2001 From: dima1206 <–32818228+dima1206@users.noreply.github.com> Date: Wed, 15 Feb 2023 18:03:31 +0200 Subject: [PATCH 2/4] Add changelogs --- changelogs/fragments/5994-github-webhook-secret.yml | 2 ++ 1 file changed, 2 insertions(+) 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 00000000000..700703840cb --- /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 From 64f1a713c5e6e0dffed2be7fde654b0ee44039e3 Mon Sep 17 00:00:00 2001 From: dima1206 <–32818228+dima1206@users.noreply.github.com> Date: Wed, 15 Feb 2023 18:11:57 +0200 Subject: [PATCH 3/4] Fix indentation --- plugins/modules/github_webhook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/github_webhook.py b/plugins/modules/github_webhook.py index 2adaeedc75d..4a290165e0b 100644 --- a/plugins/modules/github_webhook.py +++ b/plugins/modules/github_webhook.py @@ -162,7 +162,7 @@ def _create_hook_config(module): secret = module.params.get("secret") if secret is not None and len(secret) > 0: - hook_config["secret"] = secret + hook_config["secret"] = secret return hook_config From ba302f0119a7b0435d2a00c1c2bb307a16354ed4 Mon Sep 17 00:00:00 2001 From: dima1206 <32818228+dima1206@users.noreply.github.com> Date: Thu, 16 Feb 2023 13:15:14 +0200 Subject: [PATCH 4/4] Apply suggestion to simplify the check Co-authored-by: Felix Fontein --- plugins/modules/github_webhook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/github_webhook.py b/plugins/modules/github_webhook.py index 4a290165e0b..f1f11ce10c8 100644 --- a/plugins/modules/github_webhook.py +++ b/plugins/modules/github_webhook.py @@ -161,7 +161,7 @@ def _create_hook_config(module): } secret = module.params.get("secret") - if secret is not None and len(secret) > 0: + if secret: hook_config["secret"] = secret return hook_config