From 05e2ada17e944e468e933db497801efb3b6852e0 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Thu, 9 Jan 2025 21:43:14 +0100 Subject: [PATCH] FIX: remove `ci.skip` if empty (#485) --- src/compwa_policy/check_dev_files/precommit.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/compwa_policy/check_dev_files/precommit.py b/src/compwa_policy/check_dev_files/precommit.py index a1ccdf29..3dd82133 100644 --- a/src/compwa_policy/check_dev_files/precommit.py +++ b/src/compwa_policy/check_dev_files/precommit.py @@ -115,17 +115,18 @@ def _update_precommit_ci_skip(precommit: ModifiablePrecommit) -> None: local_hooks = get_local_hooks(precommit.document) non_functional_hooks = get_non_functional_hooks(precommit.document) expected_skips = sorted(set(non_functional_hooks) | set(local_hooks)) + if not expected_skips and "skip" in precommit_ci: + del precommit_ci["skip"] + msg = "Removed redundant ci.skip section" + precommit.changelog.append(msg) + return existing_skips = precommit_ci.get("skip") - if existing_skips != expected_skips: + if expected_skips and existing_skips != expected_skips: precommit_ci["skip"] = sorted(expected_skips) yaml_config = cast("CommentedMap", precommit.document) yaml_config.yaml_set_comment_before_after_key("repos", before="\n") msg = "Updated ci.skip section" precommit.changelog.append(msg) - if not expected_skips and existing_skips: - del precommit_ci["skip"] - msg = "Removed redundant ci.skip section" - precommit.changelog.append(msg) def get_local_hooks(config: PrecommitConfig) -> list[str]: