railyard/apps/gitea/scripts/explore-featured-refresh.sh
caelum0x 8d66b80ccb
Some checks failed
audit / audit (push) Has been cancelled
ci / cargo test (abacus) (push) Has been cancelled
ci / cargo test (agent-runtime) (push) Has been cancelled
ci / cargo test (context-passport) (push) Has been cancelled
ci / cargo test (game-economy) (push) Has been cancelled
ci / cargo test (ledgerline) (push) Has been cancelled
ci / cargo test (mint) (push) Has been cancelled
ci / cargo test (rago) (push) Has been cancelled
ci / cargo test (relay) (push) Has been cancelled
ci / cargo test (toolgate) (push) Has been cancelled
ci / cargo test (turnstile) (push) Has been cancelled
ci / cargo test (vend) (push) Has been cancelled
ci / node suites (push) Has been cancelled
fix(rithub): UI round 2 -- file-list overflow, Explore featured section, mcp-docs home link
rithub-beat-github-2026-11-18.md UI findings, round 2 (live at rithub.dev):

1. Mobile repo file-list commit-message overflow (finding #1, re-opened).
   The 2026-11-18 mobile fix forced .repo-file-item out of stock Gitea's
   display:contents, which pulled it out of #repo-files-table's own
   3-column CSS grid -- each row was then auto-placed as one opaque grid
   item sized by its own min-content width (measured live: 911.625px on
   a 390px screen), blowing commit-message text off the right edge with
   no ellipsis. Fixed by collapsing #repo-files-table to a single grid
   column at this breakpoint AND adding min-width:0 to the grid/flex
   items so the existing overflow:hidden;text-overflow:ellipsis on
   .repo-file-cell.message can actually do its job. Verified live:
   item width 372px, message cell 348px, body.scrollWidth == innerWidth
   (390), ellipsis renders correctly across every row including nested
   paths.

2. Explore leads with real public repos (finding #3, the "not done" half
   from the prior pass). New templates/explore/repos.tmpl (override) +
   explore/featured.tmpl: a curated "Featured" section above the raw
   bulk list, shown on the default unfiltered first page only. The 8
   pinned repos were chosen via a real Jev (TypeSafe System One) score
   per repo ("how strong a flagship example is this to showcase" --
   stars are 0 across the board this early, so quality-of-description
   was the real signal); apps/gitea/scripts/explore-featured-refresh.sh
   (installed on railyard-box's crontab, daily) refreshes each pinned
   repo's live stars/description/push-time and re-sorts by that --
   static template content, no engine/Go code change, self-gated restart
   (load1<6, no other build) matching oauth-auto-import.sh's pattern.

3. Home page links to /mcp-docs ("Works with your coding agent") -- a
   single tertiary text link under the two hero CTAs, not a third pill
   button.

4. Full 390px/1440px sweep of home, explore, repo, issues, pulls, login,
   signup, mcp-docs: no console errors, no horizontal page overflow,
   no regressions.

Screenshots: gtm/qa-shots/rithub-ui-round2-2026-11-19/. 3 container
restarts this pass (gated on load1<6 + no build each time): 1 shipped
the intended fix set, 2 were corrective after live DOM/CSS-cascade
inspection (CDP `inspect`) proved the first file-list fix attempt hadn't
actually closed the overflow -- documented honestly in the CSS comments
and plans/railyard.md rather than claiming success from the screenshot
alone.
2026-11-19 02:20:41 +03:00

196 lines
8.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Rithub UI round 2 (owner task, 2026-11-19): regenerate the curated
# "Featured" section at the top of Explore
# (rithub-beat-github-2026-11-18.md finding #3 -- "Explore should lead
# with the best real public repos").
#
# The repo list itself is a real, Jev-scored editorial pin (see
# PINNED_REPO_NAMES below and plans/railyard.md for the score table) --
# stars are 0 across the board right now (too early a product for that
# signal), so a one-time quality judgment picked the set, not a nightly
# heuristic. What this script does on every run is refresh that fixed
# set against live data:
# 1. Fetch each pinned repo's current description/stars/push-time from
# the live API.
# 2. Drop any that are now private/empty (gone/retired since pinning).
# 3. Re-sort the (still-fixed) set by live star count, then most
# recently pushed.
# 4. Render plain static HTML cards and rewrite the content between
# the RITHUB-FEATURED markers in custom/templates/explore/featured.tmpl.
# 5. If the file actually changed, restart the gitea container so the
# new static content is picked up -- Gitea runs RUN_MODE=prod,
# which caches custom templates in memory for the process lifetime,
# so a template-file edit alone has no effect until restart. This
# follows the exact same load1<6 / no-other-build self-gate as
# oauth-auto-import.sh in this same directory -- skips quietly and
# retries next tick if the box is busy, never forces it.
#
# No engine/Go code change: this is pure data (template content) churn.
#
# Install (one-time, on railyard-box -- installed under the real `deploy`
# user's own crontab, same as oauth-auto-import.sh actually runs despite
# that script's header comment saying `-u git`; there is no `git` system
# user on this box):
# (crontab -l 2>/dev/null; echo "17 4 * * * /srv/railyard-gitea/scripts/explore-featured-refresh.sh >> /var/log/rithub-explore-featured-refresh.log 2>&1") | crontab -
# Installed live 2026-11-19 (UI round 2) -- `crontab -l` on railyard-box
# confirmed both this line and the pre-existing oauth-auto-import.sh one.
set -euo pipefail
LOCK_FILE="/var/lock/rithub-explore-featured.lock"
GITEA_CONTAINER="railyard-gitea-gitea-1"
RITHUB_HOST="${RITHUB_HOST:-rithub.dev}"
RITHUB_BASE_URL="${RITHUB_BASE_URL:-https://${RITHUB_HOST}}"
CUSTOM_DIR="${RITHUB_CUSTOM_DIR:-/srv/railyard-gitea/custom}"
FEATURED_TMPL="${CUSTOM_DIR}/templates/explore/featured.tmpl"
TOP_N="${RITHUB_FEATURED_COUNT:-8}"
exec 9>"$LOCK_FILE"
if ! flock -n 9; then
exit 0
fi
if [ ! -f "$FEATURED_TMPL" ]; then
echo "explore-featured-refresh: $FEATURED_TMPL not found, skipping" >&2
exit 0
fi
before_hash=$(md5sum "$FEATURED_TMPL" 2>/dev/null | cut -d' ' -f1 || echo "")
python3 -I - "$RITHUB_BASE_URL" "$FEATURED_TMPL" "$TOP_N" <<'PYEOF'
import sys, json, html, re, urllib.request
base_url, featured_path, top_n = sys.argv[1], sys.argv[2], int(sys.argv[3])
top_n = max(1, min(top_n, 24))
REPO_ICON_SVG = (
'<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true">'
'<path d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75'
'h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.5 2.5 0 0 1 '
'2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.5 2.5 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 '
'.25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.25.25 0 0 0-.3 0L5.4 '
'15.7a.25.25 0 0 1-.4-.2Z"/></svg>'
)
# The actual curated pin list (chosen 2026-11-19, UI round 2): every
# public repo was Jev-scored ("how strong a flagship example is this
# repo to feature on Explore" -- a real/credible-product judgment, not a
# toy/tutorial/placeholder one -- plans/railyard.md has the full score
# table) against the live catalog of 172 real (non-"stars/*"/"forks/*"
# mirror) public repos; stars are currently 0 across the board (too
# early for that signal to differentiate), so quality-of-description was
# the real signal Jev used. Top 8, kept diverse across orgs rather than
# every rithub/scribase repo in a row. This script does NOT re-run that
# judgment on a schedule -- it only refreshes each pinned repo's live
# stars/description/push-time from the API and re-sorts this fixed set
# by that live data, so the page always shows current numbers without a
# human/Jev re-curation pass every night.
PINNED_REPO_NAMES = [
"rithub/railyard",
"scribase/scribase-mail-studio",
"caelum0x/qie-forge",
"caelum0x/menivor",
"scribase/scribase-hermes-plugin",
"caelum0x/umpirix",
"scribase/schemaproof",
"rithub/rit",
]
def fetch_repo(base_url, full_name):
url = f"{base_url}/api/v1/repos/{full_name}"
req = urllib.request.Request(url, headers={"User-Agent": "rithub-explore-featured-refresh/1"})
with urllib.request.urlopen(req, timeout=20) as r:
return json.load(r)
def _to_epoch(ts):
if not ts:
return 0
try:
import datetime
return int(datetime.datetime.fromisoformat(ts.replace("Z", "+00:00")).timestamp())
except Exception:
return 0
def render_card(repo):
full_name = repo["full_name"]
owner, name = full_name.split("/", 1)
desc = (repo.get("description") or "").strip()
desc = desc[:160] + ("…" if len(desc) > 160 else "")
href = f"/{html.escape(owner)}/{html.escape(name)}"
return (
f'<a class="rithub-featured-card" href="{href}">'
f'<div class="rithub-featured-card-head">{REPO_ICON_SVG}'
f'<span class="rithub-featured-card-name">{html.escape(owner)}/{html.escape(name)}</span>'
f'</div>'
f'<div class="rithub-featured-card-desc">{html.escape(desc)}</div>'
f'</a>'
)
picked = []
for full_name in PINNED_REPO_NAMES:
try:
repo = fetch_repo(base_url, full_name)
except Exception as e:
print(f"explore-featured-refresh: {full_name} fetch failed ({e}), skipping it this run", file=sys.stderr)
continue
if repo.get("private") or repo.get("empty"):
print(f"explore-featured-refresh: {full_name} is now private/empty, skipping it this run", file=sys.stderr)
continue
picked.append(repo)
picked.sort(key=lambda r: (-r.get("stars_count", 0), -_to_epoch(r.get("updated_at"))))
picked = picked[:top_n]
if not picked:
print("explore-featured-refresh: no pinned repos resolved live, leaving featured.tmpl untouched", file=sys.stderr)
sys.exit(0)
cards_html = "\n\t\t".join(render_card(r) for r in picked)
new_block = f"<!-- RITHUB-FEATURED:BEGIN -->\n\t\t{cards_html}\n\t\t<!-- RITHUB-FEATURED:END -->"
content = open(featured_path, encoding="utf-8").read()
updated = re.sub(
r"<!-- RITHUB-FEATURED:BEGIN -->.*?<!-- RITHUB-FEATURED:END -->",
new_block.replace("\\", "\\\\"),
content,
flags=re.S,
)
if updated == content:
print("explore-featured-refresh: no change")
sys.exit(0)
open(featured_path, "w", encoding="utf-8").write(updated)
print(f"explore-featured-refresh: wrote {len(picked)} featured repos: " +
", ".join(r["full_name"] for r in picked))
PYEOF
after_hash=$(md5sum "$FEATURED_TMPL" 2>/dev/null | cut -d' ' -f1 || echo "")
if [ "$before_hash" = "$after_hash" ]; then
echo "explore-featured-refresh: featured.tmpl unchanged, no restart needed"
exit 0
fi
# Content changed on disk -- Gitea (RUN_MODE=prod) caches custom templates
# in memory, so this needs a restart to actually show up. Same load1<6 /
# no-other-build self-gate as oauth-auto-import.sh; skip quietly and pick
# it up on the next scheduled run rather than forcing it.
load1=$(cut -d' ' -f1 /proc/loadavg)
if awk "BEGIN{exit !($load1>=6)}"; then
echo "explore-featured-refresh: load1=$load1 >= 6, skipping restart this tick (content updated on disk, will take effect on next successful restart)"
exit 0
fi
if pgrep -f "docker.*build|buildx|next build" >/dev/null 2>&1; then
echo "explore-featured-refresh: a build is running, skipping restart this tick"
exit 0
fi
docker compose -f /srv/railyard-gitea/docker-compose.yml restart gitea >/dev/null 2>&1 \
|| docker restart "$GITEA_CONTAINER" >/dev/null 2>&1 \
|| true
echo "explore-featured-refresh: restarted $GITEA_CONTAINER to pick up refreshed Explore content"