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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ commit and rule is linked under it, and two folds hold the rest: how to fix it

> <img alt="✖" width="24" height="24" align="top" src="https://raw.githubusercontent.com/commit-check/.github/main/branding/status/failed.png"> **Commit Check failed**
>
> <img alt="✔" width="16" height="16" align="top" src="https://raw.githubusercontent.com/commit-check/.github/main/branding/status/line-passed.png"> Pull request: passed<br>
> <img alt="✖" width="16" height="16" align="top" src="https://raw.githubusercontent.com/commit-check/.github/main/branding/status/line-failed.png"> Commits: 1 of 2 failed<br>
> <img alt="✖" width="16" height="16" align="top" src="https://raw.githubusercontent.com/commit-check/.github/main/branding/status/line-failed.png"> Branch: failed
> <img alt="✔" width="16" height="16" align="absmiddle" src="https://raw.githubusercontent.com/commit-check/.github/main/branding/status/line-passed.png"> Pull request: passed<br>
> <img alt="✖" width="16" height="16" align="absmiddle" src="https://raw.githubusercontent.com/commit-check/.github/main/branding/status/line-failed.png"> Commits: 1 of 2 failed<br>
> <img alt="✖" width="16" height="16" align="absmiddle" src="https://raw.githubusercontent.com/commit-check/.github/main/branding/status/line-failed.png"> Branch: failed
>
> ```diff
> @@ 5584f46 @@
Expand Down
24 changes: 17 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1826,17 +1826,28 @@ def _fenced(language: str, body: list[str]) -> list[str]:


def _status_mark(status: str, size: int, line: bool = False) -> str:
"""The ``<img>`` of a status mark: the tile at 24 px, the line mark at 16."""
"""The ``<img>`` of a status mark: the tile at 24 px, the line mark at 16.

The tile sits at the top of the heading. A line mark is centred on its
line of text (``absmiddle``): aligned to the top it rode about two pixels
above the words beside it.
"""
name = f"{'line-' if line else ''}{STATUS_WORDS[status]}"
align = "absmiddle" if line else "top"
return (
f'<img alt="{STATUS_GLYPHS[status]}" width="{size}" height="{size}" '
f'align="top" src="{STATUS_MARK_URL}/{name}.png">'
f'align="{align}" src="{STATUS_MARK_URL}/{name}.png">'
)


def _group_lines(results: list[ScopeResult]) -> str:
"""One line per group, its status mark in front: the overview."""
return "<br>\n".join(
"""One line per group, its status mark in front: the overview.

The lines are joined by ``<br>`` alone, on one source line. A pull request
comment turns every newline into a line break of its own, so ``<br>``
followed by a newline left an empty line between the groups there.
"""
return "<br>".join(
f"{_status_mark(status, 16, line=True)} {group_name}: {text}"
for group_name, scopes in _grouped(results)
for status, text in [_group_status(scopes)]
Expand Down Expand Up @@ -2087,9 +2098,8 @@ def _all_checks(results: list[ScopeResult]) -> list[str]:
# <!-- commit-check-action -->
# ## <mark:failed> Commit Check failed
#
# <mark:line-passed> Pull request: passed<br>
# <mark:line-failed> Commits: 2 of 3 failed<br>
# <mark:line-failed> Branch: failed
# <mark:line-passed> Pull request: passed<br><mark:line-failed> Commits: 2 of 3 failed<br><mark:line-failed> Branch: failed
# (one source line: see _group_lines)
#
# ```diff
# @@ 5584f46 @@
Expand Down
26 changes: 13 additions & 13 deletions main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def heading(glyph: str, word: str, verdict: str) -> str:
def group_line(glyph: str, word: str, text: str) -> str:
"""One group's line of the report: its line mark, name and result."""
return (
f'<img alt="{glyph}" width="16" height="16" align="top" '
f'<img alt="{glyph}" width="16" height="16" align="absmiddle" '
f'src="{MARKS}/line-{word}.png"> {text}'
)

Expand Down Expand Up @@ -2005,8 +2005,8 @@ def test_success_golden_output(self):
f"{main.COMMENT_MARKER}\n"
f"{heading('✔', 'passed', 'passed')}\n"
"\n"
f"{group_line('✔', 'passed', 'Pull request: passed')}<br>\n"
f"{group_line('✔', 'passed', 'Commits: 2 passed')}<br>\n"
f"{group_line('✔', 'passed', 'Pull request: passed')}<br>"
f"{group_line('✔', 'passed', 'Commits: 2 passed')}<br>"
f"{group_line('✔', 'passed', 'Branch: passed')}\n"
"\n"
"<details>\n"
Expand Down Expand Up @@ -2042,8 +2042,8 @@ def test_failure_golden_output(self):
f"{main.COMMENT_MARKER}\n"
f"{heading('✖', 'failed', 'failed')}\n"
"\n"
f"{group_line('✔', 'passed', 'Pull request: passed')}<br>\n"
f"{group_line('✖', 'failed', 'Commits: failed')}<br>\n"
f"{group_line('✔', 'passed', 'Pull request: passed')}<br>"
f"{group_line('✖', 'failed', 'Commits: failed')}<br>"
f"{group_line('✔', 'passed', 'Branch: passed')}\n"
"\n"
"```diff\n"
Expand Down Expand Up @@ -2118,8 +2118,8 @@ def test_failure_golden_output_with_commits(self):
f"{main.COMMENT_MARKER}\n"
f"{heading('✖', 'failed', 'failed')}\n"
"\n"
f"{group_line('✔', 'passed', 'Pull request: passed')}<br>\n"
f"{group_line('✖', 'failed', 'Commits: 2 of 3 failed')}<br>\n"
f"{group_line('✔', 'passed', 'Pull request: passed')}<br>"
f"{group_line('✖', 'failed', 'Commits: 2 of 3 failed')}<br>"
f"{group_line('✔', 'passed', 'Branch: passed')}\n"
"\n"
"```diff\n"
Expand Down Expand Up @@ -3721,7 +3721,7 @@ def test_all_skipped_golden_output(self):
"\n"
"Nothing was validated.\n"
"\n"
f"{group_line('⊘', 'skipped', 'Pull request: skipped')}<br>\n"
f"{group_line('⊘', 'skipped', 'Pull request: skipped')}<br>"
f"{group_line('⊘', 'skipped', 'Commits: skipped')}\n"
"\n"
"<details>\n"
Expand All @@ -3744,15 +3744,15 @@ def test_partial_skip_does_not_claim_all_passed(self):
results.append(pass_scope("PR description"))
body = main.render_report(results)
self.assertIn("Commit Check passed\n", body)
self.assertIn("> Branch: passed<br>\n", body)
self.assertIn("> Branch: passed<br>", body)
# Two scopes in the group, one of which ran: never "2 passed".
self.assertIn("> Pull request: 1 passed, 1 skipped\n", body)

def test_failure_still_wins_over_skips(self):
results = [fail_scope("Commit 1/1"), skip_scope("PR title")]
body = main.render_report(results)
self.assertIn("Commit Check failed\n", body)
self.assertIn("> Commits: failed<br>\n", body)
self.assertIn("> Commits: failed<br>", body)
self.assertIn("> Pull request: skipped\n", body)

def test_skipped_scope_reports_no_checked_value(self):
Expand Down Expand Up @@ -3993,7 +3993,7 @@ def test_warning_only_golden_output(self):
f"{main.COMMENT_MARKER}\n"
f"{heading('⚠', 'warned', 'passed with warnings')}\n"
"\n"
f"{group_line('✔', 'passed', 'Pull request: passed')}<br>\n"
f"{group_line('✔', 'passed', 'Pull request: passed')}<br>"
f"{group_line('⚠', 'warned', 'Branch: 1 warning')}\n"
"\n"
"**Warnings**\n"
Expand Down Expand Up @@ -4030,8 +4030,8 @@ def test_warning_and_skip_each_get_their_own_group_line(self):
body = main.render_report(results)
self.assertIn("Commit Check passed with warnings\n", body)
self.assertIn(
f"{group_line('✔', 'passed', 'Pull request: passed')}<br>\n"
f"{group_line('⚠', 'warned', 'Branch: 1 warning')}<br>\n"
f"{group_line('✔', 'passed', 'Pull request: passed')}<br>"
f"{group_line('⚠', 'warned', 'Branch: 1 warning')}<br>"
f"{group_line('⊘', 'skipped', 'Author: skipped')}\n",
body,
)
Expand Down
Loading