|
1 | | -import requests |
2 | 1 | import os |
3 | 2 | import sys |
| 3 | +import requests |
4 | 4 | import yaml |
5 | 5 | from datetime import datetime |
6 | 6 |
|
7 | | -ORG = "ManiVaultStudio" |
8 | | -REPO = sys.argv[1] if len(sys.argv) > 1 else "Scatterplot" |
| 7 | +# ---------- Resolve owner/repo ---------- |
| 8 | +def resolve_owner_repo(): |
| 9 | + """ |
| 10 | + Accepts: |
| 11 | + - argv[1] as 'owner/repo' or 'repo' |
| 12 | + - else uses GITHUB_REPOSITORY env ('owner/repo') |
| 13 | + Raises if neither present. |
| 14 | + """ |
| 15 | + if len(sys.argv) > 1: |
| 16 | + arg = sys.argv[1].strip() |
| 17 | + if "/" in arg: |
| 18 | + owner, repo = arg.split("/", 1) |
| 19 | + else: |
| 20 | + owner = os.getenv("GITHUB_REPOSITORY", "").split("/")[0] or "ManiVaultStudio" |
| 21 | + repo = arg |
| 22 | + return owner, repo |
| 23 | + |
| 24 | + env_repo = os.getenv("GITHUB_REPOSITORY", "") |
| 25 | + if env_repo and "/" in env_repo: |
| 26 | + owner, repo = env_repo.split("/", 1) |
| 27 | + return owner, repo |
| 28 | + |
| 29 | + raise SystemExit("❌ Repo not specified. Pass '<owner>/<repo>' or set GITHUB_REPOSITORY.") |
| 30 | + |
| 31 | +OWNER, REPO = resolve_owner_repo() |
9 | 32 | OUTPUT_PATH = f"{REPO.lower()}.md" |
10 | | -GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") |
11 | 33 |
|
| 34 | +GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") |
12 | 35 | HEADERS = {"Accept": "application/vnd.github+json"} |
13 | 36 | if GITHUB_TOKEN: |
14 | 37 | HEADERS["Authorization"] = f"Bearer {GITHUB_TOKEN}" |
15 | 38 |
|
16 | | -# ---------- Fetch base info ---------- |
17 | | -def fetch_plugin_info(): |
18 | | - url = f"https://raw.githubusercontent.com/{ORG}/{REPO}/master/PluginInfo.json" |
| 39 | +# ---------- Helpers ---------- |
| 40 | +def fetch_default_branch(): |
| 41 | + url = f"https://api.github.com/repos/{OWNER}/{REPO}" |
| 42 | + r = requests.get(url, headers=HEADERS) |
| 43 | + r.raise_for_status() |
| 44 | + return r.json().get("default_branch", "master") |
| 45 | + |
| 46 | +def fetch_plugin_info(branch): |
| 47 | + url = f"https://raw.githubusercontent.com/{OWNER}/{REPO}/{branch}/PluginInfo.json" |
19 | 48 | r = requests.get(url) |
20 | 49 | r.raise_for_status() |
21 | 50 | return r.json() |
22 | 51 |
|
23 | 52 | def fetch_contributors(): |
24 | | - url = f"https://api.github.com/repos/{ORG}/{REPO}/contributors" |
| 53 | + url = f"https://api.github.com/repos/{OWNER}/{REPO}/contributors" |
25 | 54 | r = requests.get(url, headers=HEADERS) |
26 | 55 | r.raise_for_status() |
27 | 56 | return [user["login"] for user in r.json()] |
28 | 57 |
|
29 | | -# ---------- Fetch README content ---------- |
30 | | -def fetch_readme_excerpt(lines=5): |
31 | | - """Return first `lines` lines from README.md (skipping initial heading).""" |
32 | | - url = f"https://raw.githubusercontent.com/{ORG}/{REPO}/master/README.md" |
33 | | - r = requests.get(url) |
34 | | - if r.status_code != 200: |
35 | | - return "" |
36 | | - |
37 | | - all_lines = r.text.splitlines() |
38 | | - |
39 | | - # Skip the first heading line (starts with '#') |
40 | | - filtered = [] |
41 | | - heading_skipped = False |
42 | | - for line in all_lines: |
43 | | - if not heading_skipped and line.strip().startswith("#"): |
44 | | - heading_skipped = True |
45 | | - continue |
46 | | - filtered.append(line) |
47 | | - if len(filtered) >= lines: |
48 | | - break |
49 | | - |
50 | | - return "\n".join(filtered) |
| 58 | +def fetch_readme_full(branch): |
| 59 | + """Return full README.md content (skip first heading line if present).""" |
| 60 | + raw_urls = [ |
| 61 | + f"https://raw.githubusercontent.com/{OWNER}/{REPO}/{branch}/README.md", |
| 62 | + f"https://raw.githubusercontent.com/{OWNER}/{REPO}/{branch}/readme.md", |
| 63 | + ] |
| 64 | + for url in raw_urls: |
| 65 | + r = requests.get(url) |
| 66 | + if r.status_code == 200: |
| 67 | + lines = r.text.splitlines() |
| 68 | + if lines and lines[0].strip().startswith("#"): |
| 69 | + lines = lines[1:] |
| 70 | + return "\n".join(lines).strip() |
| 71 | + return "" |
51 | 72 |
|
52 | 73 | # ---------- Write output markdown ---------- |
53 | | -def write_markdown(info, authors, readme_snippet=""): |
| 74 | +def write_markdown(info, authors, readme_text=""): |
54 | 75 | metadata = { |
55 | 76 | "layout": "plugin", |
56 | 77 | "name": info["name"], |
57 | 78 | "shortname": info["name"].split()[0], |
58 | 79 | "key": REPO.lower(), |
59 | 80 | "type": info.get("type", "").lower(), |
60 | 81 | "version": info["version"]["plugin"], |
61 | | - "date": datetime.today().strftime("%Y-%m-%d %H:%M:%S"), |
| 82 | + "date": datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"), |
62 | 83 | "organization": "ManiVault", |
63 | 84 | "organization-link": "https://www.manivault.studio", |
64 | 85 | "authors": authors, |
65 | | - "shortdescription": f"{info['type']} plugin with dependencies: {', '.join(info.get('dependencies', []))}", |
| 86 | + # NOTE: shortdescription intentionally removed (derived on site) |
| 87 | + "repo": f"https://github.com/{OWNER}/{REPO}", |
66 | 88 | } |
67 | 89 |
|
| 90 | + # Build page body: README + repo link footer |
| 91 | + body_parts = [] |
| 92 | + if readme_text: |
| 93 | + body_parts.append(readme_text) |
| 94 | + body_parts.append(f"\n---\n**Source repository:** https://github.com/{OWNER}/{REPO}\n") |
| 95 | + body = "\n".join(body_parts).lstrip("\n") |
| 96 | + |
68 | 97 | with open(OUTPUT_PATH, "w", encoding="utf-8") as f: |
69 | 98 | f.write("---\n") |
70 | 99 | yaml.dump(metadata, f, sort_keys=False, allow_unicode=True) |
71 | 100 | f.write("---\n\n") |
72 | | - if readme_snippet: |
73 | | - f.write(readme_snippet + "\n") |
| 101 | + f.write(body) |
74 | 102 |
|
75 | | - print(f" Updated {OUTPUT_PATH}") |
| 103 | + print(f"✅ Updated {OUTPUT_PATH} for {OWNER}/{REPO}") |
76 | 104 |
|
| 105 | +# ---------- Main ---------- |
77 | 106 | if __name__ == "__main__": |
78 | | - info = fetch_plugin_info() |
| 107 | + branch = fetch_default_branch() |
| 108 | + info = fetch_plugin_info(branch) |
79 | 109 | authors = fetch_contributors() |
80 | | - readme_excerpt = fetch_readme_excerpt(lines=5) |
81 | | - write_markdown(info, authors, readme_snippet=readme_excerpt) |
| 110 | + readme_text = fetch_readme_full(branch) |
| 111 | + write_markdown(info, authors, readme_text=readme_text) |
0 commit comments