From ba8bd0bcfb4b08eb07b6c180c3925ec0bd2c6382 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Tue, 13 Sep 2022 06:30:49 +1200 Subject: [PATCH] gitlab_hook: minor refactoring (#5271) * gitlab_hook: minor refactoring * add changelog fragment (cherry picked from commit fbb6ceea1da2a424a72ee7b1461b3263e1c369c6) --- .../fragments/5271-gitlab_hook-refactor.yaml | 2 ++ .../source_control/gitlab/gitlab_hook.py | 17 +++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) create mode 100644 changelogs/fragments/5271-gitlab_hook-refactor.yaml diff --git a/changelogs/fragments/5271-gitlab_hook-refactor.yaml b/changelogs/fragments/5271-gitlab_hook-refactor.yaml new file mode 100644 index 00000000000..c846e1b04ff --- /dev/null +++ b/changelogs/fragments/5271-gitlab_hook-refactor.yaml @@ -0,0 +1,2 @@ +minor_changes: + - gitlab_hook - minor refactoring (https://github.com/ansible-collections/community.general/pull/5271). diff --git a/plugins/modules/source_control/gitlab/gitlab_hook.py b/plugins/modules/source_control/gitlab/gitlab_hook.py index f0824a96c7c..3eb79be312d 100644 --- a/plugins/modules/source_control/gitlab/gitlab_hook.py +++ b/plugins/modules/source_control/gitlab/gitlab_hook.py @@ -233,9 +233,8 @@ def create_or_update_hook(self, project, hook_url, options): hook.save() except Exception as e: self._module.fail_json(msg="Failed to update hook: %s " % e) - return True - else: - return False + + return changed ''' @param project Project Object @@ -257,9 +256,9 @@ def update_hook(self, hook, arguments): changed = False for arg_key, arg_value in arguments.items(): - if arguments[arg_key] is not None: - if getattr(hook, arg_key, None) != arguments[arg_key]: - setattr(hook, arg_key, arguments[arg_key]) + if arg_value is not None: + if getattr(hook, arg_key, None) != arg_value: + setattr(hook, arg_key, arg_value) changed = True return (changed, hook) @@ -287,10 +286,8 @@ def exists_hook(self, project, hook_url): return False def delete_hook(self): - if self._module.check_mode: - return True - - return self.hook_object.delete() + if not self._module.check_mode: + self.hook_object.delete() def main():