Skip to content

Commit

Permalink
style: update formatting using black
Browse files Browse the repository at this point in the history
  • Loading branch information
amimas committed Feb 28, 2024
1 parent 3733e78 commit 3ab81d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
18 changes: 11 additions & 7 deletions gitlabform/processors/project/hooks_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _process_configuration(self, project_and_group: str, configuration: dict):
else:
debug(f"Not deleting hook '{hook}', because it doesn't exist")
continue

# Process new hook creation
if not hook_id:
debug(f"Creating hook '{hook}'")
Expand All @@ -49,7 +49,9 @@ def _process_configuration(self, project_and_group: str, configuration: dict):
# Processing existing hook updates
gl_hook: dict = hook_in_gitlab.asdict() if hook_in_gitlab else {}
if self.is_hook_config_different(gl_hook, hook_config):
debug(f"The hook '{hook}' config is different from what's in gitlab OR it contains a token")
debug(
f"The hook '{hook}' config is different from what's in gitlab OR it contains a token"
)
debug(f"Updating hook '{hook}'")
updated_hook: Dict[str, Any] = project.hooks.update(
hook_id, hook_config
Expand All @@ -67,11 +69,13 @@ def _process_configuration(self, project_and_group: str, configuration: dict):
)
project.hooks.delete(gh.id)

def is_hook_config_different(self, config_in_gitlab, config_in_gitlabform):
'''
def is_hook_config_different(
self, config_in_gitlab: dict, config_in_gitlabform: dict
):
"""
Compare two dictionary representing a webhook configuration and determine
if they are different.
GitLab's webhook data does not contain "token" as it is considered a secret.
If GitLabForm config for a webhook contains a "token", the difference cannot
be validated. So, an empty value for "token" is used as GitLab's webhook data,
Expand All @@ -80,10 +84,10 @@ def is_hook_config_different(self, config_in_gitlab, config_in_gitlabform):
Args:
config_in_gitlab (dict): hook configuration in gitlab
config_in_gitlabform (dict): hook configuration in gitlabform
Returns:
boolean: True if the two configs are different. Otherwise False.
'''
"""
if "token" in config_in_gitlabform:
debug(
f"The hook '{config_in_gitlabform['url']}' config includes a token. Diff between config vs gitlab cannot be confirmed"
Expand Down
5 changes: 4 additions & 1 deletion tests/acceptance/standard/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ def test_hooks_delete(self, gl, project, urls, caplog):
# The last hook configured for deletion but it was never setup in gitlab.
# Ensure expected error message is reported.
with caplog.at_level(logging.DEBUG):
assert f"Not deleting hook '{non_existent_hook_url}', because it doesn't exist" in caplog.text
assert (
f"Not deleting hook '{non_existent_hook_url}', because it doesn't exist"
in caplog.text
)

def test_hooks_enforce(self, gl, group, project, urls):
target = project.path_with_namespace
Expand Down

0 comments on commit 3ab81d4

Please sign in to comment.