From 82cf5f8d8f641ea8d7d020423c66561469699d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Mon, 17 Jun 2024 11:50:33 +0200 Subject: [PATCH 1/2] Support pre-commit modification con commit --- github_app_geo_project/module/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/github_app_geo_project/module/utils.py b/github_app_geo_project/module/utils.py index d6322e66294..e4dc25417ce 100644 --- a/github_app_geo_project/module/utils.py +++ b/github_app_geo_project/module/utils.py @@ -562,7 +562,7 @@ def has_changes(include_un_followed: bool = False) -> bool: return proc.returncode != 0 -async def create_commit(message: str) -> bool: +async def create_commit(message: str, pre_commit_check: bool = True) -> bool: """Do a commit.""" proc = subprocess.run( # nosec # pylint: disable=subprocess-run-check ["git", "add", "--all"], capture_output=True, encoding="utf-8", timeout=30 @@ -573,13 +573,16 @@ async def create_commit(message: str) -> bool: _LOGGER.warning(proc_message) return False _, success, _ = await run_timeout( - ["git", "commit", f"--message={message}"], + ["git", "commit", f"--message={message}", *([] if pre_commit_check else ["--no-verify"])], None, 600, "Commit", "Error committing files", "Timeout committing files", ) + if not success and pre_commit_check: + # On pre-commit issues, add them to the commit, and try again without the pre-commit + success = await create_commit(message, False) return success From 246a893debad4c4bed525ed601c8b166f09c96f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Mon, 17 Jun 2024 10:53:24 +0200 Subject: [PATCH 2/2] Audit: more debug messages on diff --- github_app_geo_project/module/audit/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/github_app_geo_project/module/audit/__init__.py b/github_app_geo_project/module/audit/__init__.py index c42a1d1f989..f4b4aa4ec8a 100644 --- a/github_app_geo_project/module/audit/__init__.py +++ b/github_app_geo_project/module/audit/__init__.py @@ -235,6 +235,13 @@ async def _process_snyk_dpkg( ["git", "diff", "--quiet"], timeout=30 ) if diff_proc.returncode != 0: + proc = subprocess.run( # nosec # pylint: disable=subprocess-run-check + ["git", "diff"], timeout=30, capture_output=True, encoding="utf-8" + ) + message = module_utils.ansi_proc_message(proc) + message.title = "Changes to be committed" + _LOGGER.debug(message) + proc = subprocess.run( # nosec # pylint: disable=subprocess-run-check ["git", "checkout", "-b", new_branch], capture_output=True, encoding="utf-8", timeout=30 ) @@ -254,6 +261,8 @@ async def _process_snyk_dpkg( else: if pull_request is not None: issue_check.set_title(key, f"{key} ([Pull request]({pull_request.html_url}))") + else: + _LOGGER.debug("No changes to commit") except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as proc_error: message = module_utils.ansi_proc_message(proc_error) _LOGGER.exception("Audit %s process error", key)