From 9eb4f503b8c4aa8dd3918a5f2cb56e36169be474 Mon Sep 17 00:00:00 2001 From: Olivier Korach Date: Tue, 21 Oct 2025 09:52:58 +0200 Subject: [PATCH 1/4] Fixes #2015 --- sonar/audit/problem.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sonar/audit/problem.py b/sonar/audit/problem.py index 1d3a78a63..479efedae 100644 --- a/sonar/audit/problem.py +++ b/sonar/audit/problem.py @@ -86,6 +86,10 @@ def __dump_csv(problems: list[Problem], file: str, server_id: str = None, with_u """ with utilities.open_file(file, "w") as fd: csvwriter = csv.writer(fd, delimiter=separator) + header = ["Server Id"] if server_id else [] + header += ["Audit Check", "Category", "Severity", "Message"] + header += ["URL"] if with_url else [] + csvwriter.writerow(header) for p in problems: data = [] if server_id is not None: From 4505eb4c49b2631c16ee41f60e3f7e83f74d6b96 Mon Sep 17 00:00:00 2001 From: Olivier Korach Date: Tue, 21 Oct 2025 09:53:06 +0200 Subject: [PATCH 2/4] Formatting --- test/unit/test_housekeeper.py | 7 +++++-- test/unit/utilities.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/test/unit/test_housekeeper.py b/test/unit/test_housekeeper.py index 288d7f9cc..0470e5aab 100644 --- a/test/unit/test_housekeeper.py +++ b/test/unit/test_housekeeper.py @@ -40,13 +40,16 @@ def test_housekeeper() -> None: for opts in __GOOD_OPTS: assert tutil.run_cmd(housekeeper.main, f"{CMD} {tutil.SQS_OPTS} {opts}") == errcodes.OK + def test_keep_branches_override(csv_file: Generator[str]) -> None: """test_keep_branches_override""" if tutil.SQ.version() == "community": pytest.skip("No branches in Community") assert tutil.run_cmd(housekeeper.main, f"{CMD} {tutil.SQS_OPTS} -P 730 -T 730 -R 730 -B 90 -f {csv_file}") == errcodes.OK nbr_br = tutil.csv_col_count_values(csv_file, 1, "BRANCH_LAST_ANALYSIS") - assert tutil.run_cmd(housekeeper.main, f"{CMD} {tutil.SQS_OPTS} -P 730 -T 730 -R 730 -B 90 -f {csv_file} --keepWhenInactive 'dontkeepanything'") == errcodes.OK + assert ( + tutil.run_cmd(housekeeper.main, f"{CMD} {tutil.SQS_OPTS} -P 730 -T 730 -R 730 -B 90 -f {csv_file} --keepWhenInactive 'dontkeepanything'") + == errcodes.OK + ) # With 'dontkeepanything' as branch regexp, more branches to delete should be found assert tutil.csv_col_count_values(csv_file, 1, "BRANCH_LAST_ANALYSIS") > nbr_br - diff --git a/test/unit/utilities.py b/test/unit/utilities.py index dffa10fd8..d30404781 100644 --- a/test/unit/utilities.py +++ b/test/unit/utilities.py @@ -304,7 +304,7 @@ def csv_col_count_values(csv_file: str, col_name_or_nbr: Union[str, int], *value if isinstance(col_name_or_nbr, int): col = col_name_or_nbr - 1 else: - (col,) = get_cols(next(reader, col_name_or_nbr)) + (col,) = get_cols(next(reader, col_name_or_nbr)) counter = sum(1 if line[col] in values_to_search else 0 for line in reader) return counter From f69e5119f6e6150c2b78fee46114cc72e4ce2400 Mon Sep 17 00:00:00 2001 From: Olivier Korach Date: Tue, 21 Oct 2025 10:12:12 +0200 Subject: [PATCH 3/4] Fix regression --- test/unit/utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/utilities.py b/test/unit/utilities.py index d30404781..86622a017 100644 --- a/test/unit/utilities.py +++ b/test/unit/utilities.py @@ -304,7 +304,7 @@ def csv_col_count_values(csv_file: str, col_name_or_nbr: Union[str, int], *value if isinstance(col_name_or_nbr, int): col = col_name_or_nbr - 1 else: - (col,) = get_cols(next(reader, col_name_or_nbr)) + (col,) = get_cols(next(reader), col_name_or_nbr) counter = sum(1 if line[col] in values_to_search else 0 for line in reader) return counter From e661ceba276f3bf962cd3e264d64f4cba80f5206 Mon Sep 17 00:00:00 2001 From: Olivier Korach Date: Tue, 21 Oct 2025 10:12:23 +0200 Subject: [PATCH 4/4] Formatting --- test/unit/test_housekeeper.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/test/unit/test_housekeeper.py b/test/unit/test_housekeeper.py index 0470e5aab..2fed00002 100644 --- a/test/unit/test_housekeeper.py +++ b/test/unit/test_housekeeper.py @@ -45,11 +45,9 @@ def test_keep_branches_override(csv_file: Generator[str]) -> None: """test_keep_branches_override""" if tutil.SQ.version() == "community": pytest.skip("No branches in Community") - assert tutil.run_cmd(housekeeper.main, f"{CMD} {tutil.SQS_OPTS} -P 730 -T 730 -R 730 -B 90 -f {csv_file}") == errcodes.OK - nbr_br = tutil.csv_col_count_values(csv_file, 1, "BRANCH_LAST_ANALYSIS") - assert ( - tutil.run_cmd(housekeeper.main, f"{CMD} {tutil.SQS_OPTS} -P 730 -T 730 -R 730 -B 90 -f {csv_file} --keepWhenInactive 'dontkeepanything'") - == errcodes.OK - ) + opts = f"{CMD} {tutil.SQS_OPTS} -P 730 -T 730 -R 730 -B 90 -f {csv_file}" + assert tutil.run_cmd(housekeeper.main, opts) == errcodes.OK + nbr_br = tutil.csv_col_count_values(csv_file, "Audit Check", "BRANCH_LAST_ANALYSIS") + assert tutil.run_cmd(housekeeper.main, f"{opts} --keepWhenInactive 'dontkeepanything'") == errcodes.OK # With 'dontkeepanything' as branch regexp, more branches to delete should be found - assert tutil.csv_col_count_values(csv_file, 1, "BRANCH_LAST_ANALYSIS") > nbr_br + assert tutil.csv_col_count_values(csv_file, "Audit Check", "BRANCH_LAST_ANALYSIS") > nbr_br