Move rule change table into details block
This commit is contained in:
@@ -11,7 +11,7 @@ from subprocess import PIPE
|
||||
from typing import TYPE_CHECKING, Iterator, Self, Sequence
|
||||
|
||||
from ruff_ecosystem import logger
|
||||
from ruff_ecosystem.markdown import project_section
|
||||
from ruff_ecosystem.markdown import markdown_project_section, markdown_details
|
||||
from ruff_ecosystem.types import (
|
||||
Comparison,
|
||||
Diff,
|
||||
@@ -78,15 +78,13 @@ def summarize_check_result(result: Result) -> str:
|
||||
error_count = len(result.errored)
|
||||
|
||||
if total_removed == 0 and total_added == 0 and error_count == 0:
|
||||
return "\u2705 ecosystem check detected no `ruff check` changes."
|
||||
return "\u2705 ecosystem check detected no linter changes."
|
||||
|
||||
# Summarize the total changes
|
||||
s = "s" if error_count != 1 else ""
|
||||
changes = f"(+{total_added}, -{total_removed}, {error_count} error{s})"
|
||||
|
||||
lines.append(
|
||||
f"\u2139\ufe0f ecosystem check **detected `ruff check` changes**. {changes}"
|
||||
)
|
||||
lines.append(f"\u2139\ufe0f ecosystem check **detected linter changes**. {changes}")
|
||||
lines.append("")
|
||||
|
||||
# Then per-project changes
|
||||
@@ -111,9 +109,9 @@ def summarize_check_result(result: Result) -> str:
|
||||
diff_lines.append("</pre>")
|
||||
|
||||
lines.extend(
|
||||
project_section(
|
||||
markdown_project_section(
|
||||
title=f"+{diff.lines_added}, -{diff.lines_removed}",
|
||||
content="\n".join(diff_lines),
|
||||
content=diff_lines,
|
||||
options=project.check_options.markdown(),
|
||||
project=project,
|
||||
)
|
||||
@@ -121,7 +119,7 @@ def summarize_check_result(result: Result) -> str:
|
||||
|
||||
for project, error in result.errored:
|
||||
lines.extend(
|
||||
project_section(
|
||||
markdown_project_section(
|
||||
title="error",
|
||||
content=str(error),
|
||||
options="",
|
||||
@@ -131,10 +129,9 @@ def summarize_check_result(result: Result) -> str:
|
||||
|
||||
# Display a summary table of changed rules
|
||||
if all_rule_changes:
|
||||
lines.append(f"Rules changed: {len(all_rule_changes.rule_codes())}")
|
||||
lines.append("")
|
||||
lines.append("| Rule | Changes | Additions | Removals |")
|
||||
lines.append("| ---- | ------- | --------- | -------- |")
|
||||
table_lines = []
|
||||
table_lines.append("| Rule | Changes | Additions | Removals |")
|
||||
table_lines.append("| ---- | ------- | --------- | -------- |")
|
||||
for rule, total in sorted(
|
||||
all_rule_changes.total_changes_by_rule(),
|
||||
key=lambda item: item[1], # Sort by the total changes
|
||||
@@ -144,7 +141,15 @@ def summarize_check_result(result: Result) -> str:
|
||||
all_rule_changes.added[rule],
|
||||
all_rule_changes.removed[rule],
|
||||
)
|
||||
lines.append(f"| {rule} | {total} | {additions} | {removals} |")
|
||||
table_lines.append(f"| {rule} | {total} | {additions} | {removals} |")
|
||||
|
||||
lines.extend(
|
||||
markdown_details(
|
||||
summary=f"Rules changed: {len(all_rule_changes.rule_codes())}",
|
||||
preface="",
|
||||
content=table_lines,
|
||||
)
|
||||
)
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ from typing import TYPE_CHECKING, Self, Sequence
|
||||
from unidiff import PatchSet
|
||||
|
||||
from ruff_ecosystem import logger
|
||||
from ruff_ecosystem.markdown import project_section
|
||||
from ruff_ecosystem.markdown import markdown_project_section
|
||||
from ruff_ecosystem.types import Comparison, Diff, Result, RuffError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -56,7 +56,7 @@ def summarize_format_result(result: Result) -> str:
|
||||
title = f"+{comparison.diff.lines_added}, -{comparison.diff.lines_removed} lines in {files} file{s}"
|
||||
|
||||
lines.extend(
|
||||
project_section(
|
||||
markdown_project_section(
|
||||
title=title,
|
||||
content=patch_set_with_permalinks(patch_set, comparison.repo),
|
||||
options=project.format_options.markdown(),
|
||||
@@ -66,7 +66,7 @@ def summarize_format_result(result: Result) -> str:
|
||||
|
||||
for project, error in result.errored:
|
||||
lines.extend(
|
||||
project_section(
|
||||
markdown_project_section(
|
||||
title="error",
|
||||
content=str(error),
|
||||
options="",
|
||||
|
||||
@@ -6,18 +6,27 @@ if TYPE_CHECKING:
|
||||
from ruff_ecosystem.projects import Project
|
||||
|
||||
|
||||
def project_section(
|
||||
title: str, content: str, options: str, project: Project
|
||||
def markdown_project_section(
|
||||
title: str, content: str | list[str], options: str, project: Project
|
||||
) -> list[str]:
|
||||
lines = []
|
||||
lines.append(
|
||||
f'<details><summary><a href="{project.repo.url}">{project.repo.fullname}</a> ({title})</summary>'
|
||||
return markdown_details(
|
||||
summary=f'<a href="{project.repo.url}">{project.repo.fullname}</a> ({title})',
|
||||
preface=options,
|
||||
content=content,
|
||||
)
|
||||
lines.append(options)
|
||||
|
||||
|
||||
def markdown_details(summary: str, preface: str, content: str | list[str]):
|
||||
lines = []
|
||||
lines.append(f"<details><summary>{summary}</summary>")
|
||||
lines.append(preface)
|
||||
lines.append("<p>")
|
||||
lines.append("")
|
||||
|
||||
lines.append(content)
|
||||
if isinstance(content, str):
|
||||
lines.append(content)
|
||||
else:
|
||||
lines.extend(content)
|
||||
|
||||
lines.append("")
|
||||
lines.append("</p>")
|
||||
|
||||
Reference in New Issue
Block a user