Skip to content

Commit 42bab21

Browse files
author
Sreeparna Deb
committed
testing without repo name and default branch hardcoding + md content updates + full readme content
1 parent c8bca1d commit 42bab21

File tree

1 file changed

+69
-39
lines changed

1 file changed

+69
-39
lines changed

scripts/update_plugininfo.py

Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,111 @@
1-
import requests
21
import os
32
import sys
3+
import requests
44
import yaml
55
from datetime import datetime
66

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()
932
OUTPUT_PATH = f"{REPO.lower()}.md"
10-
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
1133

34+
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
1235
HEADERS = {"Accept": "application/vnd.github+json"}
1336
if GITHUB_TOKEN:
1437
HEADERS["Authorization"] = f"Bearer {GITHUB_TOKEN}"
1538

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"
1948
r = requests.get(url)
2049
r.raise_for_status()
2150
return r.json()
2251

2352
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"
2554
r = requests.get(url, headers=HEADERS)
2655
r.raise_for_status()
2756
return [user["login"] for user in r.json()]
2857

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 ""
5172

5273
# ---------- Write output markdown ----------
53-
def write_markdown(info, authors, readme_snippet=""):
74+
def write_markdown(info, authors, readme_text=""):
5475
metadata = {
5576
"layout": "plugin",
5677
"name": info["name"],
5778
"shortname": info["name"].split()[0],
5879
"key": REPO.lower(),
5980
"type": info.get("type", "").lower(),
6081
"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"),
6283
"organization": "ManiVault",
6384
"organization-link": "https://www.manivault.studio",
6485
"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}",
6688
}
6789

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+
6897
with open(OUTPUT_PATH, "w", encoding="utf-8") as f:
6998
f.write("---\n")
7099
yaml.dump(metadata, f, sort_keys=False, allow_unicode=True)
71100
f.write("---\n\n")
72-
if readme_snippet:
73-
f.write(readme_snippet + "\n")
101+
f.write(body)
74102

75-
print(f" Updated {OUTPUT_PATH}")
103+
print(f" Updated {OUTPUT_PATH} for {OWNER}/{REPO}")
76104

105+
# ---------- Main ----------
77106
if __name__ == "__main__":
78-
info = fetch_plugin_info()
107+
branch = fetch_default_branch()
108+
info = fetch_plugin_info(branch)
79109
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

Comments
 (0)