Skip to content

Commit 616eb74

Browse files
committed
refactor: split report title and status into separate lines
The report now opens with a plain '# Commit Check' title line followed by the status line ('✅ All checks passed (N scopes)' or the failure count), keeping the PR comment and job summary identical.
1 parent c8e8695 commit 616eb74

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

‎main.py‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
from dataclasses import dataclass, field
2020
from typing import Any
2121

22-
# Constants for message titles
23-
SUCCESS_TITLE = "# Commit Check ✔️"
24-
FAILURE_TITLE = "# Commit Check ❌"
22+
# Constant for the report title
23+
REPORT_TITLE = "# Commit Check"
2524
COMMIT_MESSAGE_DELIMITER = "\x00"
2625
RULES_URL = "https://commit-check.com/rules/"
2726

@@ -419,20 +418,22 @@ def _markdown_details(results: list[ScopeResult]) -> str:
419418
def render_report(results: list[ScopeResult], include_footer: bool = True) -> str:
420419
"""Render the Markdown report shared by the job summary and PR comment.
421420
422-
All checks passing collapses to a single success line; failures render
423-
a scope table with rule links plus collapsible failure details.
421+
The report opens with the plain title line followed by the status line:
422+
``✅ All checks passed (N scopes)`` on success, or the failure count on
423+
failure, followed by a scope table with rule links and collapsible
424+
failure details.
424425
"""
425426
if all(scope.status == "pass" for scope in results):
426427
scopes = "scope" if len(results) == 1 else "scopes"
427-
return f"{SUCCESS_TITLE} All checks passed ({len(results)} {scopes})"
428+
return f"{REPORT_TITLE}\n\n✅ All checks passed ({len(results)} {scopes})"
428429

429430
failures = _failure_count(results)
430431
unit = "failure" if failures == 1 else "failures"
431432
scopes = "scope" if len(results) == 1 else "scopes"
432433
lines = [
433-
FAILURE_TITLE,
434+
REPORT_TITLE,
434435
"",
435-
f"**{failures} {unit}** across {len(results)} {scopes}",
436+
f"❌ **{failures} {unit}** across {len(results)} {scopes}",
436437
"",
437438
_markdown_table(results),
438439
"",
@@ -456,8 +457,8 @@ def render_pr_comment(results: list[ScopeResult]) -> str:
456457
def build_result_body(result_text: str | None) -> str:
457458
"""Legacy helper kept for backward compatibility with existing callers."""
458459
if result_text is None:
459-
return SUCCESS_TITLE
460-
return f"{FAILURE_TITLE}\n```\n{result_text}\n```"
460+
return REPORT_TITLE
461+
return f"{REPORT_TITLE}\n```\n{result_text}\n```"
461462

462463

463464
# ---------------------------------------------------------------------------
@@ -605,7 +606,7 @@ def add_pr_comments(results: list[ScopeResult]) -> int:
605606
matching_comments = [
606607
c
607608
for c in comments
608-
if c.body.startswith(SUCCESS_TITLE) or c.body.startswith(FAILURE_TITLE)
609+
if c.body.startswith(REPORT_TITLE)
609610
# Match comments from older versions that used a hyphenated title.
610611
or c.body.startswith("# Commit-Check")
611612
]

‎main_test.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -631,12 +631,12 @@ def test_raw_text_fallback_is_printed(self):
631631
class TestRenderJobSummary(unittest.TestCase):
632632
def test_all_pass(self):
633633
body = main.render_job_summary([pass_scope("Branch")])
634-
self.assertTrue(body.startswith(main.SUCCESS_TITLE))
634+
self.assertTrue(body.startswith(main.REPORT_TITLE))
635635
self.assertIn("All checks passed (1 scope)", body)
636636

637637
def test_failure_renders_table_with_rule_links(self):
638638
body = main.render_job_summary([fail_scope("Commit 1/1")])
639-
self.assertTrue(body.startswith(main.FAILURE_TITLE))
639+
self.assertTrue(body.startswith(main.REPORT_TITLE))
640640
self.assertIn("**1 failure** across 1 scope", body)
641641
self.assertIn("| Scope | Failed checks | Result |", body)
642642
self.assertIn(
@@ -658,25 +658,25 @@ def test_all_pass_matches_job_summary(self):
658658
comment = main.render_pr_comment([pass_scope("Branch")])
659659
summary = main.render_job_summary([pass_scope("Branch")])
660660
self.assertEqual(comment, summary)
661-
self.assertTrue(comment.startswith(main.SUCCESS_TITLE))
661+
self.assertTrue(comment.startswith(main.REPORT_TITLE))
662662
self.assertIn("All checks passed (1 scope)", comment)
663663

664664
def test_failure_matches_job_summary(self):
665665
comment = main.render_pr_comment([fail_scope("Commit 1/1")])
666666
summary = main.render_job_summary([fail_scope("Commit 1/1")])
667667
self.assertEqual(comment, summary)
668-
self.assertTrue(comment.startswith(main.FAILURE_TITLE))
668+
self.assertTrue(comment.startswith(main.REPORT_TITLE))
669669
self.assertIn("**1 failure** across 1 scope", comment)
670670
self.assertIn("| Scope | Failed checks | Result |", comment)
671671

672672

673673
class TestBuildResultBody(unittest.TestCase):
674674
def test_success_body(self):
675-
self.assertEqual(main.build_result_body(None), main.SUCCESS_TITLE)
675+
self.assertEqual(main.build_result_body(None), main.REPORT_TITLE)
676676

677677
def test_failure_body(self):
678678
result = main.build_result_body("bad commit")
679-
self.assertIn(main.FAILURE_TITLE, result)
679+
self.assertIn(main.REPORT_TITLE, result)
680680
self.assertIn("bad commit", result)
681681

682682

@@ -800,7 +800,7 @@ def test_creates_comment_with_rendered_body(self):
800800
self.assertEqual(rc, 1)
801801
self.assertEqual(mock_pull_request.create_comment.call_count, 1)
802802
body = mock_pull_request.create_comment.call_args[1]["body"]
803-
self.assertTrue(body.startswith(main.FAILURE_TITLE))
803+
self.assertTrue(body.startswith(main.REPORT_TITLE))
804804
self.assertIn("| Scope | Failed checks | Result |", body)
805805

806806
def test_updates_existing_comment_when_changed(self):

0 commit comments

Comments
 (0)