intermediate commit
This commit is contained in:
48
tools/repo/generate-repository-index.py
Normal file
48
tools/repo/generate-repository-index.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
CATEGORIES = ("system", "module", "connector", "website")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
manifest = json.loads((ROOT / "repositories.json").read_text(encoding="utf-8"))
|
||||
lines = [
|
||||
"# GovOPlaN Repository Index",
|
||||
"",
|
||||
"Generated from `repositories.json`. Use that JSON file as the machine-readable source of truth; this page is the human-readable link index.",
|
||||
"",
|
||||
]
|
||||
for category in CATEGORIES:
|
||||
entries = [entry for entry in manifest["repositories"] if entry["category"] == category]
|
||||
if not entries:
|
||||
continue
|
||||
lines.extend([
|
||||
f"## {category.title()}",
|
||||
"",
|
||||
"| Repository | Subtype | Local path | Gitea |",
|
||||
"| --- | --- | --- | --- |",
|
||||
])
|
||||
for entry in entries:
|
||||
name = entry["name"]
|
||||
subtype = entry.get("subtype", "")
|
||||
path = entry["path"]
|
||||
url = gitea_url(entry["remote"])
|
||||
lines.append(f"| `{name}` | `{subtype}` | `../{path}` | [{name}]({url}) |")
|
||||
lines.append("")
|
||||
(ROOT / "docs" / "REPOSITORY_INDEX.md").write_text("\n".join(lines).rstrip() + "\n", encoding="utf-8")
|
||||
return 0
|
||||
|
||||
|
||||
def gitea_url(remote: str) -> str:
|
||||
if remote.startswith("git@git.add-ideas.de:"):
|
||||
return remote.replace("git@git.add-ideas.de:", "https://git.add-ideas.de/", 1).removesuffix(".git")
|
||||
return remote
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user