repomatic.broken_links module¶
Broken links detection and reporting.
Combines Lychee and Sphinx linkcheck results into a single “Broken links” GitHub issue. Sphinx linkcheck parsing detects broken auto-generated links (intersphinx, autodoc, type annotations) that Lychee cannot see because they only exist in the rendered HTML output.
run_lychee() runs the Lychee crawl itself, through the tool runner, and
reads back the report and the exit code. No workflow step has to relay either.
Each checker reports one LinkVerdict. Only a run that completed can
clear the issue: a checker that did not finish says nothing about the links,
so it never closes an open issue.
Issue lifecycle management is delegated to issue.
- repomatic.broken_links.ISSUE_TITLE = 'Broken links'¶
Issue title used for the combined broken links report.
- repomatic.broken_links.DOCUMENTATION_LABEL = '📚 documentation'¶
Label of the broken links issue, outside awesome lists.
- repomatic.broken_links.FIX_LINK_LABEL = '🩹 fix link'¶
Label of the broken links issue in an
awesome-*repository.
- repomatic.broken_links.LYCHEE_BROKEN_LINKS_EXIT = 2¶
The one lychee exit code that reports on the links rather than on the run.
Lychee exits 0 on success, 1 on an unexpected failure, 2 when it found broken links, and 3 on a config error. Only 2 is a verdict about the links; 1 and 3 say the run itself did not complete, so neither “broken links found” nor “no broken links” can be claimed from them.
- repomatic.broken_links.LYCHEE_REPORT_FORMAT: Final[tuple[str, ...]] = ('--format', 'markdown')¶
Flags that make lychee write the markdown report the issue body embeds.
- repomatic.broken_links.LYCHEE_INSTALL_FAILURE_EXIT = 1¶
Exit code a lychee that could not be installed counts as.
The one lychee itself returns on an unexpected failure: like a crash, a missing tool checks no link, so the issue is left as it is.
- repomatic.broken_links.SPHINX_DEFAULT_OUTPUT = PosixPath('docs/_linkcheck/output.json')¶
Default Sphinx linkcheck output path produced by the
docs.yamlworkflow.
- repomatic.broken_links.NO_BROKEN_LINKS = 'No broken links found.'¶
The section body of a checker that completed and found nothing broken.
- class repomatic.broken_links.LinkVerdict(*values)[source]¶
Bases:
StrEnumWhat one checker’s run says about the links it covers.
- BROKEN = 'broken'¶
The run completed and found broken links.
- CLEAN = 'clean'¶
The run completed and found no broken link.
- UNKNOWN = 'unknown'¶
The run did not complete, or left no report: nothing can be claimed.
- class repomatic.broken_links.LycheeRun(exit_code, report=None)[source]¶
Bases:
objectWhat one lychee crawl of the documentation files returned.
- exit_code: int¶
Exit code of lychee. See
LYCHEE_BROKEN_LINKS_EXIT.
- repomatic.broken_links.run_lychee()[source]¶
Crawl the documentation files with lychee, and keep its report.
Runs the invocation of a bare
repomatic run lychee: the default arguments of the registry, over thedoc_filesinventory. The markdown report goes to a scratch file this function reads back, so no workflow step has to agree on a path with it.A lychee that cannot be installed checked no link, so it counts as a run that did not complete:
LYCHEE_INSTALL_FAILURE_EXIT.
- class repomatic.broken_links.LinkcheckResult(filename, lineno, status, uri, info)[source]¶
Bases:
objectA single result entry from Sphinx linkcheck
output.json.Each line in the JSON-lines file corresponds to one checked URI.
- repomatic.broken_links.parse_output_json(output_json)[source]¶
Parse the Sphinx linkcheck
output.jsonfile.The file uses JSON-lines format: one JSON object per line. Blank lines are skipped.
- Parameters:
output_json (
Path) – Path to theoutput.jsonfile.- Return type:
- Returns:
List of parsed linkcheck results.
- repomatic.broken_links.filter_broken(results)[source]¶
Filter results to only broken and timed-out links.
- Parameters:
results (
Iterable[LinkcheckResult]) – Iterable of linkcheck results.- Return type:
- Returns:
List of results with
statusof"broken"or"timeout".
- repomatic.broken_links.generate_markdown_report(broken, source_url=None)[source]¶
Generate a Markdown report of broken links grouped by source file.
The report starts with H2 file headings, suitable for embedding as a section in the combined broken links issue body.
- Parameters:
broken (
list[LinkcheckResult]) – List of broken linkcheck results.source_url (
str|None) – Base URL for linking filenames and line numbers. When provided, file headers become clickable links and line numbers deep-link to the specific line.
- Return type:
- Returns:
Markdown-formatted report string.
- repomatic.broken_links.get_label(repo_name)[source]¶
Return the label the broken links issue carries in a repository.
- Parameters:
repo_name (
str) – The repository name.- Return type:
- Returns:
FIX_LINK_LABELforawesome-*repos, elseDOCUMENTATION_LABEL.
- repomatic.broken_links.lychee_section(run)[source]¶
Render the Lychee section of the issue body, with its verdict.
Only
LYCHEE_BROKEN_LINKS_EXITreports on the links themselves, and only with a report to show: a broken-links verdict with nothing to show would file an issue whose body claims the links are fine. Every other non-zero code reports that the run failed.- Parameters:
run (
LycheeRun) – The lychee crawl.- Return type:
- Returns:
The section markdown, and what it says about the links.
- repomatic.broken_links.sphinx_section(output_json, source_url=None)[source]¶
Render the Sphinx linkcheck section of the issue body, with its verdict.
- repomatic.broken_links.manage_combined_broken_links_issue(repo_name=None, lychee=None, sphinx_output_json=None, sphinx_source_url=None)[source]¶
Manage the combined broken links issue lifecycle.
Combines results from Lychee and Sphinx linkcheck into a single “Broken links” issue. Each tool’s results appear under its own heading. Tools that were not run are omitted from the report.
The issue is filed or updated when any checker found broken links, and closed when every checker that ran completed clean. When no checker found broken links but one did not complete, the issue is left as it is: the links that run covers might still be broken. When no checker ran at all, the issue is left as it is too, with a warning: nothing was checked.
When running in GitHub Actions, most parameters are auto-detected from
Metadataand well-known file paths:repo_namedefaults toMetadata.repo_name.sphinx_output_jsondefaults toSPHINX_DEFAULT_OUTPUTwhen the file exists.sphinx_source_urlis composed fromMetadata.repo_urlandMetadata.sha.
- Parameters:
repo_name (
str|None) – Repository name, for label selection.lychee (
LycheeRun|None) – The lychee crawl fromrun_lychee(),Noneif lychee did not run.sphinx_output_json (
Path|None) – Path to Sphinx linkcheckoutput.json.sphinx_source_url (
str|None) – Base URL for linking filenames and line numbers in the Sphinx report.
- Return type:
- Returns:
The combined verdict, or
Nonewhen no checker ran.- Raises:
ValueError – If
repo_namecannot be determined.