Skip to content

Commit 72910be

Browse files
joke1196sonartech
authored andcommitted
SONARPY-4120 Ruling Diff Comment: support rule with legacy key (#1081)
GitOrigin-RevId: 6f838e0f5531078e6f595cdfece99a0b06b404ad
1 parent 5f20d98 commit 72910be

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

.github/actions/ruling-diff-comment/ruling_diff_core_lib/ruling_diff_logic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def parse_rule_filename(filename: str) -> tuple[str, str]:
4444
repository, rule_key = basename.rsplit("-", 1)
4545
if not repository:
4646
raise ValueError(f"Missing repo in filename: {filename}")
47-
if not rule_key.startswith("S") or not rule_key[1:].isdigit():
48-
raise ValueError(f"Invalid rule key in filename: {filename}")
47+
if not rule_key:
48+
raise ValueError(f"Missing rule key in filename: {filename}")
4949
return repository, rule_key
5050

5151

.github/actions/ruling-diff-comment/test_ruling_diff.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ def test_parse_ruling_path_with_pythonenterprise(self) -> None:
5656
core.parse_ruling_path(path),
5757
)
5858

59+
def test_parse_ruling_path_with_legacy_key(self) -> None:
60+
path = "private/its-enterprise/ruling/src/test/resources/expected_ruling/scikit-learn/python-LineLength.json"
61+
self.assertEqual(
62+
("scikit-learn", "python", "LineLength"),
63+
core.parse_ruling_path(path),
64+
)
65+
66+
def test_parse_rule_filename_rejects_empty_rule_key(self) -> None:
67+
with self.assertRaises(ValueError):
68+
core.parse_rule_filename("python-.json")
69+
70+
def test_parse_rule_filename_rejects_empty_repository(self) -> None:
71+
with self.assertRaises(ValueError):
72+
core.parse_rule_filename("-S1066.json")
73+
5974

6075
class DiffLogicTest(unittest.TestCase):
6176
def test_diff_ruling_jsons_added_issues(self) -> None:
@@ -408,9 +423,7 @@ def test_resolve_source_path_for_project_rulings_falls_back_to_sources_child(sel
408423
io_impl.resolve_source_path("project", "S1716.py"),
409424
)
410425

411-
def test_resolve_source_path_for_project_rulings_falls_back_to_sources_internal(
412-
self,
413-
) -> None:
426+
def test_resolve_source_path_for_project_rulings_falls_back_to_sources_internal(self) -> None:
414427
io_impl = io.GitHubActionIO()
415428
with tempfile.TemporaryDirectory() as tmp_dir:
416429
sources_ruling = f"{tmp_dir}/sources_ruling"
@@ -432,9 +445,7 @@ def test_resolve_source_path_for_project_rulings_falls_back_to_sources_internal(
432445
):
433446
self.assertEqual(target, io_impl.resolve_source_path("project", "foo.py"))
434447

435-
def test_resolve_source_path_for_project_rulings_falls_back_to_namespace_child(
436-
self,
437-
) -> None:
448+
def test_resolve_source_path_for_project_rulings_falls_back_to_namespace_child(self) -> None:
438449
io_impl = io.GitHubActionIO()
439450
with tempfile.TemporaryDirectory() as tmp_dir:
440451
sources_ruling = f"{tmp_dir}/sources_ruling"

0 commit comments

Comments
 (0)