Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions action/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ["<details>", f"<summary>{label}</summary>", "", *body, "", "</details>"]

Expand Down
41 changes: 40 additions & 1 deletion tests/log_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 <jane@example.com>\n",
listing,
)
Expand Down
6 changes: 3 additions & 3 deletions tests/report_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<summary>All 1 check</summary>", body)
self.assertIn("<summary>1 check</summary>", body)

def test_body_opens_with_hidden_marker(self):
body = render.render_job_summary([pass_scope("Branch")])
Expand All @@ -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("<details>", body)
self.assertIn("<summary>All 1 check</summary>", body)
self.assertIn("<summary>1 check</summary>", body)
self.assertIn("```text", body)
self.assertIn("\nBranch\n ✔ branch main\n", body)
self.assertNotIn("```diff", body)
Expand Down Expand Up @@ -418,7 +418,7 @@ def test_failure_shows_the_diff_and_the_rule_links(self):
self.assertIn(
"<sub>Rules: [CC001](https://commit-check.com/rules/#cc001)", body
)
self.assertIn("<summary>All 1 check</summary>", body)
self.assertIn("<summary>1 check</summary>", body)
self.assertIn(" ✖ 1/1 bad message\n", body)
self.assertIn(" CC001 message", body)
self.assertIn(" value: bad message", body)
Expand Down
Loading