From f6034dea940ab5842ed6e00c735a19b75f645fc3 Mon Sep 17 00:00:00 2001 From: Valentin Rigal Date: Thu, 29 Aug 2024 13:51:50 +0200 Subject: [PATCH] Support empty clang-format diff file (#2328) --- bot/code_review_bot/tasks/clang_format.py | 10 ++++++++-- bot/tests/test_clang.py | 12 ++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bot/code_review_bot/tasks/clang_format.py b/bot/code_review_bot/tasks/clang_format.py index 3bca683e..d6f8917c 100644 --- a/bot/code_review_bot/tasks/clang_format.py +++ b/bot/code_review_bot/tasks/clang_format.py @@ -93,9 +93,15 @@ class ClangFormatTask(AnalysisTask): return f"`./mach clang-format -p {files}`" def parse_issues(self, artifacts, revision): - artifact = artifacts.get("public/code-review/clang-format.diff") + if "public/code-review/clang-format.diff" not in artifacts: + logger.warn( + "public/code-review/clang-format.diff is missing from artifacts" + ) + return [] + + artifact = artifacts["public/code-review/clang-format.diff"] if artifact is None: - logger.warn("Missing clang-format.diff") + logger.info("Empty clang-format.diff, no patches to process") return [] # Use all chunks provided by parsepatch diff --git a/bot/tests/test_clang.py b/bot/tests/test_clang.py index 6b96cb5f..f7fda2a9 100644 --- a/bot/tests/test_clang.py +++ b/bot/tests/test_clang.py @@ -187,6 +187,18 @@ def test_empty_patch(patch): assert patches == [] +def test_missing_clang_format_diff(mock_task, mock_revision, capsys): + """ + Clang format task requires diff artifact to detect issues + """ + task = mock_task(ClangFormatTask, "mock-clang-format") + assert task.parse_issues({}, mock_revision) == [] + assert ( + "public/code-review/clang-format.diff is missing from artifacts" + in capsys.readouterr().out + ) + + def test_real_patch(mock_revision, mock_task): """ Test clang format patch parsing with a real patch