@@ -2044,7 +2044,25 @@ def _report_footer() -> str:
20442044 )
20452045
20462046
2047- def render_report (results : list [ScopeResult ]) -> str :
2047+ def _run_url () -> str :
2048+ """Link to this workflow run, whose page holds the job summary."""
2049+ repository = os .getenv ("GITHUB_REPOSITORY" , "" )
2050+ run_id = os .getenv ("GITHUB_RUN_ID" , "" )
2051+ if not (repository and run_id ):
2052+ return ""
2053+ server = os .getenv ("GITHUB_SERVER_URL" ) or "https://github.com"
2054+ return f"{ server .rstrip ('/' )} /{ repository } /actions/runs/{ run_id } "
2055+
2056+
2057+ def _elsewhere (what : str ) -> str :
2058+ """Point to where the parts a shortened comment left out can be read."""
2059+ where = "job summary" if _summary_written () else "step log"
2060+ url = _run_url ()
2061+ place = f"[{ where } ]({ url } )" if url else where
2062+ return f"{ what } are in the { place } of this run."
2063+
2064+
2065+ def render_report (results : list [ScopeResult ], detail : str = "full" ) -> str :
20482066 """Render the Markdown report shared by the job summary and PR comment.
20492067
20502068 Opens with the hidden marker and a heading that is the verdict — the
@@ -2053,6 +2071,10 @@ def render_report(results: list[ScopeResult]) -> str:
20532071 listed any rule under ``warn``, the folded "How to fix", and the folded
20542072 listing of every scope.
20552073
2074+ ``detail`` is for a PR comment that would not fit (``render_pr_comment``):
2075+ ``"short"`` leaves out the listing, ``"headline"`` everything below the
2076+ group lines, and either says where to read what it left out.
2077+
20562078 A warned scope counts toward "passed", never toward "failed": it ran,
20572079 found something, and is reported in full, but the config asked for it to
20582080 be surfaced rather than enforced.
@@ -2080,14 +2102,22 @@ def render_report(results: list[ScopeResult]) -> str:
20802102 lines .extend ([_group_lines (results ), "" ])
20812103 if skipped and _skip_reasons (results ):
20822104 lines .extend ([_skip_reasons (results ), "" ])
2105+ if detail == "headline" :
2106+ what = "The findings and how to fix them" if failed or warned else "All checks"
2107+ lines .extend ([_elsewhere (what ), "" , _report_footer ()])
2108+ return "\n " .join (lines )
20832109 if failed :
20842110 lines .extend ([* _diff_block (results ), "" ])
20852111 if warned :
20862112 lines .extend (["**Warnings**" , "" , * _diff_block (results , "warn" ), "" ])
20872113 if failed :
20882114 how = _how_to_fix (results )
20892115 lines .extend ([* how , "" ] if how else [])
2090- lines .extend ([* _all_checks (results ), "" , _report_footer ()])
2116+ if detail == "short" :
2117+ lines .extend ([_elsewhere (f"All { _plural (total , 'check' )} " ), "" ])
2118+ else :
2119+ lines .extend ([* _all_checks (results ), "" ])
2120+ lines .append (_report_footer ())
20912121 return "\n " .join (lines )
20922122
20932123
@@ -2096,9 +2126,31 @@ def render_job_summary(results: list[ScopeResult]) -> str:
20962126 return render_report (results )
20972127
20982128
2129+ #: The longest comment GitHub accepts, in UTF-16 code units.
2130+ COMMENT_LIMIT = 65536
2131+
2132+
2133+ def _comment_length (body : str ) -> int :
2134+ """Length of a comment as GitHub counts it: in UTF-16 code units."""
2135+ return len (body .encode ("utf-16-le" )) // 2
2136+
2137+
20992138def render_pr_comment (results : list [ScopeResult ]) -> str :
2100- """Create the Markdown body for the PR comment (same report as summary)."""
2101- return render_report (results )
2139+ """Create the Markdown body for the PR comment (same report as summary).
2140+
2141+ The report grows with the pull request: every failing commit's message
2142+ is quoted in the diff, the prompt and the listing. A few dozen failing
2143+ commits ran past GitHub's limit, the API refused the comment, and an
2144+ earlier one, perhaps saying "passed", stayed on the pull request. So a
2145+ report that does not fit drops the listing, then everything under the
2146+ group lines, and points to the run for the rest. The job summary, with
2147+ its far higher limit, keeps the full report.
2148+ """
2149+ for detail in ("full" , "short" ):
2150+ body = render_report (results , detail )
2151+ if _comment_length (body ) <= COMMENT_LIMIT :
2152+ return body
2153+ return render_report (results , "headline" )
21022154
21032155
21042156# ---------------------------------------------------------------------------
0 commit comments