diff --git a/action/render.py b/action/render.py index eca1d9c..29fc48b 100644 --- a/action/render.py +++ b/action/render.py @@ -452,12 +452,17 @@ def _finding_lines(check: dict[str, str]) -> list[str]: message; a multi-line value (a whole commit message on a failing rule) or suggestion is split the same way, so every line of user text sits inside the tree rather than at column 0. + + The rest of a multi-line value (a commit body, the second declaration + box CC501 found) is aligned under its first line, so the value reads as + one block and the error after it is not mistaken for part of it. A blank + line stays empty, with no trailing spaces. """ lines: list[str] = [] if check.get("value"): first, *rest = str(check["value"]).splitlines() lines.append(f"value: {first}") - lines.extend(rest) + lines.extend(f"{'':7}{line}" if line else "" for line in rest) lines.extend(check.get("error", "").splitlines()) fix = check.get("fix", "") suggest = check.get("suggest", "") @@ -485,7 +490,9 @@ def _render_findings(checks: list[dict[str, str]], include_docs: bool) -> list[s # warning says so on its own line rather than borrow the row's mark. kind = " (warning)" if check.get("status") == "warn" else "" lines.append(f" {_rule_label(check)}{kind}") - lines.extend(f" {line}" for line in _finding_lines(check)) + lines.extend( + f" {line}" if line else "" for line in _finding_lines(check) + ) if include_docs and check.get("docs_url"): lines.append(f" Docs: {check['docs_url']}") return lines @@ -1072,8 +1079,10 @@ def _all_checks(results: list[model.ScopeResult]) -> list[str]: and why". The same block is used whether or not anything failed. """ _failed, total = _check_counts(results) - unit = "check" if total == 1 else "checks" - label = f"All {total} {unit}" if total else "Details" + if total > 1: + label = f"All {total} checks" + else: + label = "1 check" if total else "Details" body = _fenced("text", _render_tree(results, include_docs=False)) return ["
", f"{label}", "", *body, "", "
"] diff --git a/tests/log_test.py b/tests/log_test.py index 5ac0ed6..b5e5d57 100644 --- a/tests/log_test.py +++ b/tests/log_test.py @@ -149,6 +149,45 @@ def test_finding_lines_are_the_value_the_error_and_the_fix(self): ], ) + def test_a_list_value_lines_up_under_its_first_item(self): + """The second declaration box would otherwise sit at the column of + ``value:`` and read as a line of its own.""" + check = make_check( + "ai_declaration", + status="fail", + rule_id="CC501", + value="- [ ] No AI tools were used\n- [ ] AI tools were used", + error="No AI declaration box is ticked", + ) + self.assertEqual( + render._finding_lines(check), + [ + "value: - [ ] No AI tools were used", + " - [ ] AI tools were used", + "No AI declaration box is ticked", + ], + ) + + def test_a_commit_body_lines_up_under_the_subject(self): + """The body sits under the subject, so the error after it is not + read as a line of the message. The blank line stays empty.""" + check = make_check( + "message", + status="fail", + rule_id="CC001", + value="added login page\n\nIt also fixes the redirect.", + error="The commit message should follow Conventional Commits.", + ) + self.assertEqual( + render._finding_lines(check), + [ + "value: added login page", + "", + " It also fixes the redirect.", + "The commit message should follow Conventional Commits.", + ], + ) + def test_annotation_without_an_error_still_names_the_kind_of_finding(self): scope = model.ScopeResult( label="Branch", @@ -220,7 +259,7 @@ def test_a_multi_line_fix_takes_one_row_per_line(self): listing = output.split("::endgroup::")[0] self.assertIn( " Fix: feat: add login page\n" - " \n" + "\n" " Signed-off-by: Jane Doe \n", listing, ) diff --git a/tests/report_test.py b/tests/report_test.py index 4789534..b718195 100644 --- a/tests/report_test.py +++ b/tests/report_test.py @@ -346,7 +346,7 @@ def test_total_does_not_grow_with_the_number_of_rules(self): for results in (one_rule, many_rules): body = render.render_report(results) self.assertIn("> Branch: passed\n", body) - self.assertIn("All 1 check", body) + self.assertIn("1 check", body) def test_body_opens_with_hidden_marker(self): body = render.render_job_summary([pass_scope("Branch")]) @@ -369,7 +369,7 @@ def test_all_pass(self): body = render.render_job_summary([pass_scope("Branch", value="main")]) self.assertIn("Commit Check passed\n", body) self.assertIn("
", body) - self.assertIn("All 1 check", body) + self.assertIn("1 check", body) self.assertIn("```text", body) self.assertIn("\nBranch\n ✔ branch main\n", body) self.assertNotIn("```diff", body) @@ -418,7 +418,7 @@ def test_failure_shows_the_diff_and_the_rule_links(self): self.assertIn( "Rules: [CC001](https://commit-check.com/rules/#cc001)", body ) - self.assertIn("All 1 check", body) + self.assertIn("1 check", body) self.assertIn(" ✖ 1/1 bad message\n", body) self.assertIn(" CC001 message", body) self.assertIn(" value: bad message", body)