railyard/apps/gitea/custom/templates/shared/bring_your_code.tmpl
caelum0x 913ab6e6ae feat(railyard): Rithub share loops — dashboard share card, README badge, OG/twitter cards, ref counting, import-reversibility preview
Ships the Rithub row of plans/growth-loops-2026-11-19.md's
"SHARE EVERYWHERE + REASONS TO SHARE" table:

- templates/shared/share_card.tmpl: one-time dashboard share card shown
  the first time a signed-in user has >=1 imported repo (the dashboard's
  own complement of the 0-repo "Bring your code" screen). Icon-only
  share row (X, LinkedIn, Bluesky, Reddit, HN, WhatsApp, Telegram, copy
  link, native share-sheet "More"), every link carrying
  rithub.dev/?ref=<username>. Client-side localStorage gate, dismissible,
  never posts on the user's behalf.
- templates/repo/header.tmpl: "hosted on Rithub" README badge popup,
  one-click copy of the markdown snippet (badge SVG served from
  custom/public/assets/badge/hosted-on-rithub.svg, ?ref=<owner> in the
  link).
- templates/base/head_opengraph.tmpl: added the missing twitter:card/
  twitter:title/twitter:image tags on the repo/issue/diff/profile
  branches (only the homepage branch had them before), so shared repo
  links render a real preview card on X/Slack-style unfurlers.
- scripts/ref-count.py + ref-count.sh: counts ?ref=<value> visits from
  Caddy's own JSON access logs into ref-counts.json (box-only, offset-
  tracked, idempotent across cron ticks) — no new Gitea route needed.
- templates/shared/bring_your_code.tmpl: real user feedback (PremAnjwani,
  Product Hunt forum) — a compact "what moves, what doesn't" preview
  right before the GitHub import button (copied/how/not-copied/
  reversible), every fact sourced from scripts/lib/bulk-migrate.sh's
  real migrate request body and the live container's own convert-mirror
  template (verified repo-owner self-service, not site-admin-only).

Deployed to railyard-box (container restart only, no rebuild) and
verified live: repo-page OG/twitter tags + badge markdown with real
?ref, dashboard share card + import preview rendered for a real signed-
in session (disposable mail.tm QA account, repo migrated then deleted,
account deleted), share-card JS link construction verified in a Node
sandbox, ref-count script verified against a real ?ref hit and proven
idempotent on a second run, cron installed (*/15 min).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-11-19 18:30:31 +03:00

121 lines
7.9 KiB
Cheetah

{{/*
Rithub "Bring your code" — the real fix for the 0-repo funnel gap found
2026-11-19 (plans/railyard.md): both real external signups (harish via
email, blenderwebservices via Google OAuth) landed with 0 repos and no
next step. New shared partial, included from two places so the content
only lives once:
- templates/user/dashboard/dashboard.tmpl — replaces the whole
(otherwise empty) dashboard for a signed-in user with 0 repos.
- templates/user/profile.tmpl — replaces the empty "Repositories" tab
when viewing your OWN profile with 0 repos (strangers viewing your
empty profile still see the stock "no repos" message, unchanged).
Three options, one screen, one click each where possible:
1. "Import from GitHub" -> {{AppSubUrl}}/user/oauth2/GitHub. Same
route used everywhere else on this site (home hero, sign_up). For
an ALREADY-signed-in user (which is always true here — this partial
only ever renders behind reqSignIn/a real profile view), Gitea's own
routers/web/auth/oauth.go SignInOAuthCallback takes the
`ctx.Doer != nil` branch and calls externalaccount.LinkAccountToUser
unconditionally — this is stock Gitea account-linking, already live,
zero code change needed. That's what makes this button correct for
email-signup (harish) and Google-signup (blenderwebservices) users
too, not just fresh GitHub sign-ins: clicking it links GitHub to
their EXISTING account, and the oauth-auto-import loop (scripts/
oauth-auto-import.sh) picks up the new external_login_user row and
imports their public repos automatically, same as a fresh GitHub
signup gets.
2. "Import by URL" — a single visible field (the clone URL) + one
button. Posts straight to the stock `/repo/migrate` POST route
(services/forms.MigrateRepoForm) with every other required field
(service, uid, mirror, repo_name) sent as a hidden input — repo_name
is derived from the pasted URL by a few lines of inline JS (last
path segment, `.git` suffix stripped, invalid chars replaced) so
the user only ever sees and types one field. service=1 is
structs.PlainGitService ("Git") — works with any host, not just
GitHub. mirror=true per the task: a continuously-synced mirror, not
a one-time copy.
3. "Start an empty repo" — plain link to the stock `/repo/create`
wizard. Not collapsed to one field on purpose: unlike the URL-paste
case there's no source value to derive a name from, and Gitea's own
create flow is already a native one-screen step, not a dead end.
No Go fork, no new routes — template + a few lines of unobtrusive inline
JS only, same intent as every other apps/gitea/custom override in this
repo (plans/OSS-ADOPTION-2026-10-15.md).
2026-11-19 (real user feedback, PremAnjwani via the Product Hunt forum,
relayed by the owner): the thing that decides whether someone actually
clicks "Import from GitHub" is knowing it's reversible -- what moves,
what doesn't, whether their GitHub copy stays untouched. Added the
compact "what moves, what doesn't" preview below, right before the
GitHub button. Every fact in it is read straight from
scripts/lib/bulk-migrate.sh's real migrate request body (mirror=true,
mirror_interval=8h, wiki/issues/pull_requests/releases/labels/
milestones=true, GitHub repos read via affiliation=owner -- own repos,
not org/starred) -- not aspirational copy. "Not copied" (CI secrets,
webhooks, Actions settings) is true by omission: none of those fields
exist in that request body, and Gitea's migrate API never touches them.
"GitHub is only read, never changed" is true because every GitHub call
in that path is a read (git fetch + GET to api.github.com); nothing in
this flow ever pushes or writes back to GitHub. "Switch to a normal
repo later in Settings" was verified against the live container's own
bundled template (not just assumed from docs): repo/settings/
options.tmpl's convert-mirror-repo-modal is gated by
`{{if .Permission.IsOwner}}{{if .Repository.IsMirror}}`, i.e. it's a
real self-service repo-owner action (Settings tab itself only needs
`.Permission.IsAdmin`, which a repo's own owner always has on their own
repo) -- not a site-admin-only control.
*/}}
<section class="rithub-bring-code">
<div class="rithub-bring-code-icon">{{svg "octicon-repo" 28}}</div>
<h2 class="rithub-bring-code-title">Bring your code to Rithub</h2>
<p class="rithub-bring-code-sub">Import an existing repo in one click, or start something new.</p>
<div class="rithub-import-preview">
<div class="rithub-import-preview-title">What moves, what doesn't</div>
<div class="rithub-import-preview-row">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><polyline points="20 6 9 17 4 12"/></svg>
<span><b>Copied</b> — code + full history, wiki, issues, pull requests, releases, labels, milestones (repos you own)</span>
</div>
<div class="rithub-import-preview-row">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><polyline points="23 4 23 10 17 10"/><polyline points="1 20 1 14 7 14"/><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/></svg>
<span><b>How</b> — re-syncs from GitHub every 8 hours; GitHub is only read, never changed</span>
</div>
<div class="rithub-import-preview-row">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
<span><b>Not copied</b> — CI secrets, webhooks, Actions settings</span>
</div>
<div class="rithub-import-preview-row">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><polyline points="1 4 1 10 7 10"/><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"/></svg>
<span><b>Reversible</b> — delete on Rithub anytime, your GitHub repo stays untouched; switch to a normal repo later in Settings</span>
</div>
</div>
<div class="rithub-bring-code-primary">
<a class="rithub-cta-btn rithub-cta-btn-primary" href="{{AppSubUrl}}/user/oauth2/GitHub" title="Import your GitHub repos — one click, no form">
{{svg "octicon-mark-github" 18}}<span>Import from GitHub</span>
</a>
</div>
<form class="rithub-bring-code-url-form" action="{{AppSubUrl}}/repo/migrate" method="post">
{{.CsrfTokenHtml}}
<input type="hidden" name="service" value="1">
<input type="hidden" name="uid" value="{{.SignedUser.ID}}">
<input type="hidden" name="mirror" value="true">
<input type="hidden" name="repo_name" id="rithub-bring-code-repo-name" value="imported-repo">
<label for="rithub-bring-code-url" class="rithub-bring-code-url-label">Import by URL</label>
<div class="rithub-bring-code-url-row">
{{svg "octicon-repo-clone" 16}}
<input id="rithub-bring-code-url" name="clone_addr" type="text" required
placeholder="https://github.com/owner/repo.git" autocomplete="off" autocapitalize="off" spellcheck="false"
oninput="(function(i){var n=document.getElementById('rithub-bring-code-repo-name');if(!n)return;var v=i.value.trim().replace(/\.git$/i,'');var seg=v.split('/').filter(Boolean).pop()||'';seg=seg.replace(/[^A-Za-z0-9_.-]/g,'-').slice(0,100);n.value=seg||'imported-repo';})(this)">
<button class="rithub-cta-btn" type="submit">Import</button>
</div>
</form>
<a class="rithub-bring-code-empty" href="{{AppSubUrl}}/repo/create">
{{svg "octicon-plus" 14}}<span>Start an empty repo</span>
</a>
</section>