|
20 | 20 | from typing import Any |
21 | 21 |
|
22 | 22 | # Constants for message titles |
23 | | -SUCCESS_TITLE = "# Commit-Check ✔️" |
24 | | -FAILURE_TITLE = "# Commit-Check ❌" |
| 23 | +SUCCESS_TITLE = "# Commit Check ✔️" |
| 24 | +FAILURE_TITLE = "# Commit Check ❌" |
25 | 25 | COMMIT_MESSAGE_DELIMITER = "\x00" |
26 | 26 | RULES_URL = "https://commit-check.com/rules/" |
27 | 27 |
|
@@ -416,45 +416,41 @@ def _markdown_details(results: list[ScopeResult]) -> str: |
416 | 416 | return "\n".join(sections) |
417 | 417 |
|
418 | 418 |
|
419 | | -def render_job_summary(results: list[ScopeResult]) -> str: |
420 | | - """Create the Markdown body for the GitHub job summary.""" |
421 | | - header = "# Commit Check Policy Report" |
| 419 | +def render_report(results: list[ScopeResult], include_footer: bool = True) -> str: |
| 420 | + """Render the Markdown report shared by the job summary and PR comment. |
| 421 | +
|
| 422 | + All checks passing collapses to a single success line; failures render |
| 423 | + a scope table with rule links plus collapsible failure details. |
| 424 | + """ |
422 | 425 | if all(scope.status == "pass" for scope in results): |
423 | 426 | scopes = "scope" if len(results) == 1 else "scopes" |
424 | | - return f"{header}\n\n\u2705 **All checks passed** ({len(results)} {scopes})" |
| 427 | + return f"{SUCCESS_TITLE} All checks passed ({len(results)} {scopes})" |
425 | 428 |
|
426 | 429 | failures = _failure_count(results) |
427 | 430 | unit = "failure" if failures == 1 else "failures" |
428 | 431 | scopes = "scope" if len(results) == 1 else "scopes" |
429 | 432 | lines = [ |
430 | | - header, |
| 433 | + FAILURE_TITLE, |
431 | 434 | "", |
432 | 435 | f"**{failures} {unit}** across {len(results)} {scopes}", |
433 | 436 | "", |
434 | 437 | _markdown_table(results), |
435 | 438 | "", |
436 | 439 | _markdown_details(results), |
437 | | - "", |
438 | | - f"_Rules reference: {RULES_URL}_", |
439 | 440 | ] |
| 441 | + if include_footer: |
| 442 | + lines.extend(["", f"_Rules reference: {RULES_URL}_"]) |
440 | 443 | return "\n".join(lines) |
441 | 444 |
|
442 | 445 |
|
443 | | -def render_pr_comment(results: list[ScopeResult]) -> str: |
444 | | - """Create the Markdown body for the PR comment.""" |
445 | | - if all(scope.status == "pass" for scope in results): |
446 | | - return f"{SUCCESS_TITLE} All checks passed" |
| 446 | +def render_job_summary(results: list[ScopeResult]) -> str: |
| 447 | + """Create the Markdown body for the GitHub job summary.""" |
| 448 | + return render_report(results, include_footer=True) |
447 | 449 |
|
448 | | - failures = _failure_count(results) |
449 | | - unit = "failure" if failures == 1 else "failures" |
450 | | - lines = [ |
451 | | - f"{FAILURE_TITLE} {failures} {unit}", |
452 | | - "", |
453 | | - _markdown_table(results), |
454 | | - "", |
455 | | - _markdown_details(results), |
456 | | - ] |
457 | | - return "\n".join(lines) |
| 450 | + |
| 451 | +def render_pr_comment(results: list[ScopeResult]) -> str: |
| 452 | + """Create the Markdown body for the PR comment (same report as summary).""" |
| 453 | + return render_report(results, include_footer=True) |
458 | 454 |
|
459 | 455 |
|
460 | 456 | def build_result_body(result_text: str | None) -> str: |
@@ -610,6 +606,8 @@ def add_pr_comments(results: list[ScopeResult]) -> int: |
610 | 606 | c |
611 | 607 | for c in comments |
612 | 608 | if c.body.startswith(SUCCESS_TITLE) or c.body.startswith(FAILURE_TITLE) |
| 609 | + # Match comments from older versions that used a hyphenated title. |
| 610 | + or c.body.startswith("# Commit-Check") |
613 | 611 | ] |
614 | 612 |
|
615 | 613 | if matching_comments: |
|
0 commit comments