diff --git a/scripts/generate_site.py b/scripts/generate_site.py index 0e0b5c06..c1e3dc64 100644 --- a/scripts/generate_site.py +++ b/scripts/generate_site.py @@ -2470,6 +2470,9 @@ def generate_emulator_page( else: lines.append(f"| Upstream | {upstream} |") lines.append(f"| Version | {version} |") + revision = revision_markdown(profile) + if revision: + lines.append(f"| Revision | {revision} |") lines.append(f"| Profiled | {profiled} |") if cores: lines.append(f"| Cores | {', '.join(str(c) for c in cores)} |") @@ -3989,6 +3992,7 @@ from sitewrite import ( # noqa: E402,F401 _sweep_generated, ) from sitesources import ( # noqa: E402,F401 + revision_markdown, _repo_pins, _forge_sources, _source_permalink, diff --git a/scripts/sitesources.py b/scripts/sitesources.py index e5863db5..b7a0ef62 100644 --- a/scripts/sitesources.py +++ b/scripts/sitesources.py @@ -92,6 +92,32 @@ def _source_permalink(repo: upstream.Repo, pin: str, path: str, url += f"-L{end}" return url +def _commit_url(repo: upstream.Repo, pin: str) -> str: + """Forge-specific browser URL for one commit.""" + base = f"https://{repo.host}/{repo.owner}/{repo.name}" + if repo.family == "gitlab": + return f"{base}/-/commit/{pin}" + return f"{base}/commit/{pin}" + + +def revision_markdown(profile: dict) -> str: + """Each repository the profile reads, linked at the commit it was read at. + + The page linked the repositories unpinned: the revision every citation + refers to sat in the YAML alone, for 178 profiles. + """ + links = [ + f"[{repo.slug}@{pin[:12]}]({_commit_url(repo, pin)})" + for repo, pin in _forge_sources(profile) + ] + branch = profile.get("source_branch") + if branch and not isinstance(branch, dict): + links.append(f"branch `{branch}`") + elif isinstance(branch, dict): + links += [f"{mode} branch `{name}`" for mode, name in branch.items()] + return ", ".join(links) + + def _source_ref_markdown(profile: dict, value) -> str: """Render source_ref values as pinned links when their forge is known. diff --git a/tests/test_site_exports.py b/tests/test_site_exports.py index 73c462bb..c89c6250 100644 --- a/tests/test_site_exports.py +++ b/tests/test_site_exports.py @@ -287,5 +287,30 @@ class PerModeSourcePins(unittest.TestCase): self.assertEqual(_json_text("c" * 40), "c" * 40) + +class AnEmulatorPageNamesItsRevision(unittest.TestCase): + """The page linked the repositories unpinned; the commit every citation + refers to sat in the YAML alone, for 178 profiles.""" + + def test_each_repository_links_its_pinned_commit(self): + import generate_site # noqa: PLC0415 + + profile = { + "emulator": "Caprice32", "type": "libretro", + "source": "https://github.com/libretro/libretro-cap32", + "upstream": "https://github.com/ColinPitrat/caprice32", + "source_commit": "c" * 40, "upstream_commit": "6" * 40, + "source_branch": "main", "systems": ["amstrad-cpc"], "files": [], + } + page = generate_site.generate_emulator_page("cap32", profile, {"files": {}}) + self.assertIn( + "| Revision | [libretro/libretro-cap32@cccccccccccc]" + "(https://github.com/libretro/libretro-cap32/commit/" + "c" * 40 + "), " + "[ColinPitrat/caprice32@666666666666]" + "(https://github.com/ColinPitrat/caprice32/commit/" + "6" * 40 + "), " + "branch `main` |", + page, + ) + if __name__ == "__main__": unittest.main()