Some checks failed
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 / node suites (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
apps/gitea -> apps/rithub-server; compose services/containers renamed (rithub-server-app/postgres/act-runner) with explicit project name and volume names pinned to the exact existing Docker volumes (no data loss); our own GITEA_* compose/env var names -> RIT_*; new rit-admin CLI wrapper on railyard-box; giteaSession.mjs/giteaOAuth.mjs/giteaInfo.mjs -> ritSession/ritOAuth/ritInfo across 6 apps; GiteaForgeAdapter -> RitForgeAdapter + giteaSyncService/importGiteaRepos/syncGiteaRepos -> rit* in ritgram (tsc clean); apps/console/lib/gitea.ts -> lib/ritProvision.ts; Go internal/giteaclient -> internal/ritclient in rithub-async-import (go build/test clean); new /auth/rit + /forges/rit/connect routes with /gitea back-compat aliases; locale/swagger/footer/captcha template text scrubbed of remaining "Gitea" strings. Deployed to railyard-box: old containers stopped/removed, /srv/railyard-gitea renamed to /srv/rithub-server with a symlink kept, docker compose up -d from the new path, act_runner network-alias fix for its persisted instance URL. Live-verified: docker compose config diff showed zero unintended value changes, DB row counts unchanged (19 users, 635 repos), full route regression 200/expected, 0 "gitea" in headers/bodies on every checked page, real git clone+push over HTTPS and SSH with a disposable account (deleted after). Deferred on purpose (documented in plans/railyard.md): the forge discriminator / DB column names / Postgres role+volume names (data migrations, not a naming change) and the upstream GITEA__ env-to-ini keys and X-Gitea-* wire headers (hardcoded in the vendored engine binary). See plans/railyard.md RIT-OPS/RIT-BRD entry for the full old->new map and live evidence. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
277 lines
10 KiB
TypeScript
277 lines
10 KiB
TypeScript
'use client'
|
|
|
|
/**
|
|
* /import-from-github — "Move from GitHub" without GitHub OAuth.
|
|
*
|
|
* One-click "Sign in with GitHub" needs a GitHub OAuth app we don't have
|
|
* approved yet (see /docs/import-from-github for the manual fallback). This
|
|
* page is the real next-best thing: paste a GitHub username to see public
|
|
* repos (no token needed), or an optional fine-grained *read* token to also
|
|
* see private ones, tick the repos to move, and Rithub mirrors them via
|
|
* Rithub's own migration API with a live per-repo progress list. On success
|
|
* it lands on the new Ritgram profile.
|
|
*
|
|
* The token (if any) is sent once to our server for this request and is
|
|
* never stored or logged — see githubImportController.ts.
|
|
*/
|
|
|
|
import { useCallback, useMemo, useState } from 'react'
|
|
import { useRouter } from 'next/navigation'
|
|
import Link from 'next/link'
|
|
import { useAuthStore } from '@/store/authStore'
|
|
import { forgeService } from '@/services/forgeService'
|
|
import {
|
|
githubImportService,
|
|
GithubImportEvent,
|
|
GithubImportRepo,
|
|
} from '@/services/githubImportService'
|
|
import { useToast } from '@/components/ui/toast'
|
|
import { getErrorMessage } from '@/utils/error'
|
|
import { Button } from '@/components/ui/button'
|
|
import { Input } from '@/components/ui/input'
|
|
|
|
type RepoStatus = 'pending' | 'migrating' | 'migrated' | 'skipped' | 'failed'
|
|
|
|
export default function ImportFromGitHubPage() {
|
|
const router = useRouter()
|
|
const { isAuthenticated } = useAuthStore()
|
|
const { showToast } = useToast()
|
|
|
|
const [username, setUsername] = useState('')
|
|
const [token, setToken] = useState('')
|
|
const [loadingPreview, setLoadingPreview] = useState(false)
|
|
const [previewError, setPreviewError] = useState<string | null>(null)
|
|
const [repos, setRepos] = useState<GithubImportRepo[]>([])
|
|
const [resolvedUsername, setResolvedUsername] = useState<string | null>(null)
|
|
const [selected, setSelected] = useState<Record<string, boolean>>({})
|
|
const [statuses, setStatuses] = useState<Record<string, RepoStatus>>({})
|
|
const [importing, setImporting] = useState(false)
|
|
const [importDone, setImportDone] = useState<{ migrated: number; skipped: number; failed: number; profileUrl: string } | null>(null)
|
|
const [ritConnected, setRitConnected] = useState<boolean | null>(null)
|
|
|
|
const selectedCount = useMemo(() => Object.values(selected).filter(Boolean).length, [selected])
|
|
|
|
const checkRitConnection = useCallback(async () => {
|
|
if (!isAuthenticated) return
|
|
try {
|
|
const { available } = await forgeService.list()
|
|
setRitConnected(available.some((f) => f.forge === 'gitea' && f.connected))
|
|
} catch {
|
|
setRitConnected(null)
|
|
}
|
|
}, [isAuthenticated])
|
|
|
|
const handlePreview = async (e: React.FormEvent) => {
|
|
e.preventDefault()
|
|
if (!username.trim()) return
|
|
setLoadingPreview(true)
|
|
setPreviewError(null)
|
|
setImportDone(null)
|
|
try {
|
|
const result = await githubImportService.preview(username.trim(), token.trim() || undefined)
|
|
setRepos(result.repos)
|
|
setResolvedUsername(result.username)
|
|
const initial: Record<string, boolean> = {}
|
|
result.repos.forEach((r) => (initial[r.fullName] = true))
|
|
setSelected(initial)
|
|
setStatuses({})
|
|
if (result.repos.length === 0) {
|
|
setPreviewError('No repos found for that account.')
|
|
}
|
|
await checkRitConnection()
|
|
} catch (error: unknown) {
|
|
setPreviewError(getErrorMessage(error))
|
|
setRepos([])
|
|
} finally {
|
|
setLoadingPreview(false)
|
|
}
|
|
}
|
|
|
|
const toggleRepo = (fullName: string) => {
|
|
setSelected((prev) => ({ ...prev, [fullName]: !prev[fullName] }))
|
|
}
|
|
|
|
const handleImport = async () => {
|
|
const repoFullNames = Object.keys(selected).filter((k) => selected[k])
|
|
if (repoFullNames.length === 0) return
|
|
|
|
if (!isAuthenticated) {
|
|
showToast('Create a free Ritgram account first, then come back here.', 'error')
|
|
router.push(`/register?next=/import-from-github`)
|
|
return
|
|
}
|
|
if (ritConnected === false) {
|
|
showToast('Connect Rithub in Settings → Account first.', 'error')
|
|
router.push('/settings/account')
|
|
return
|
|
}
|
|
|
|
setImporting(true)
|
|
setImportDone(null)
|
|
const next: Record<string, RepoStatus> = {}
|
|
repoFullNames.forEach((name) => (next[name] = 'pending'))
|
|
setStatuses(next)
|
|
|
|
try {
|
|
await githubImportService.start(
|
|
{ username: resolvedUsername || username.trim(), token: token.trim() || undefined, repos: repoFullNames },
|
|
(event: GithubImportEvent) => {
|
|
if (event.type === 'migrating') {
|
|
setStatuses((prev) => ({ ...prev, [event.repo]: 'migrating' }))
|
|
} else if (event.type === 'migrated') {
|
|
setStatuses((prev) => ({ ...prev, [event.repo]: 'migrated' }))
|
|
} else if (event.type === 'skipped') {
|
|
setStatuses((prev) => ({ ...prev, [event.repo]: 'skipped' }))
|
|
} else if (event.type === 'failed') {
|
|
setStatuses((prev) => ({ ...prev, [event.repo]: 'failed' }))
|
|
} else if (event.type === 'done') {
|
|
setImportDone(event)
|
|
}
|
|
}
|
|
)
|
|
} catch (error: unknown) {
|
|
showToast(getErrorMessage(error), 'error')
|
|
} finally {
|
|
setImporting(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="max-w-3xl mx-auto py-16 px-4">
|
|
<h1 className="text-4xl font-bold mb-3">Move from GitHub</h1>
|
|
<p className="text-lg text-foreground-secondary mb-10">
|
|
Paste your GitHub username to see your public repos — no token needed. Add a
|
|
fine-grained read token if you also want to bring over private repos. Rithub
|
|
mirrors each one with its own built-in import, full history included.
|
|
</p>
|
|
|
|
<form onSubmit={handlePreview} className="space-y-4 mb-8">
|
|
<Input
|
|
label="GitHub username"
|
|
placeholder="octocat"
|
|
value={username}
|
|
onChange={(e) => setUsername(e.target.value)}
|
|
disabled={loadingPreview}
|
|
autoComplete="off"
|
|
/>
|
|
<Input
|
|
label="Fine-grained token (optional, for private repos)"
|
|
placeholder="github_pat_..."
|
|
type="password"
|
|
value={token}
|
|
onChange={(e) => setToken(e.target.value)}
|
|
disabled={loadingPreview}
|
|
autoComplete="off"
|
|
/>
|
|
<p className="text-xs text-foreground-secondary">
|
|
Used once to list and import your repos, then discarded — never stored, never logged.
|
|
Create a read-only token at{' '}
|
|
<a
|
|
href="https://github.com/settings/personal-access-tokens/new"
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className="underline"
|
|
>
|
|
github.com/settings/personal-access-tokens
|
|
</a>
|
|
.
|
|
</p>
|
|
<Button type="submit" loading={loadingPreview} disabled={!username.trim()}>
|
|
Find repos
|
|
</Button>
|
|
</form>
|
|
|
|
{previewError && <p className="text-error mb-6">{previewError}</p>}
|
|
|
|
{repos.length > 0 && (
|
|
<div className="space-y-3 mb-8">
|
|
<div className="flex items-center justify-between">
|
|
<h2 className="text-xl font-semibold">
|
|
{repos.length} repo{repos.length === 1 ? '' : 's'} found for {resolvedUsername}
|
|
</h2>
|
|
<span className="text-sm text-foreground-secondary">{selectedCount} selected</span>
|
|
</div>
|
|
<div className="border border-border rounded-xl divide-y divide-border max-h-[420px] overflow-y-auto">
|
|
{repos.map((repo) => {
|
|
const status = statuses[repo.fullName]
|
|
return (
|
|
<label
|
|
key={repo.fullName}
|
|
className="flex items-center gap-3 p-3 cursor-pointer hover:bg-surface-secondary"
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
checked={Boolean(selected[repo.fullName])}
|
|
onChange={() => toggleRepo(repo.fullName)}
|
|
disabled={importing}
|
|
className="h-4 w-4"
|
|
/>
|
|
<div className="flex-1 min-w-0">
|
|
<div className="font-medium truncate">
|
|
{repo.name}
|
|
{repo.isPrivate && (
|
|
<span className="ml-2 text-xs text-foreground-secondary border border-border rounded px-1">
|
|
private
|
|
</span>
|
|
)}
|
|
</div>
|
|
{repo.description && (
|
|
<div className="text-sm text-foreground-secondary truncate">{repo.description}</div>
|
|
)}
|
|
</div>
|
|
<div className="text-xs text-foreground-secondary w-24 text-right">
|
|
{statusLabel(status)}
|
|
</div>
|
|
</label>
|
|
)
|
|
})}
|
|
</div>
|
|
|
|
<Button onClick={handleImport} loading={importing} disabled={selectedCount === 0}>
|
|
Move {selectedCount} repo{selectedCount === 1 ? '' : 's'} to Rithub
|
|
</Button>
|
|
|
|
{!isAuthenticated && (
|
|
<p className="text-sm text-foreground-secondary">
|
|
You'll need a free Ritgram account and a connected Rithub account to finish —
|
|
we'll walk you through it.
|
|
</p>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{importDone && (
|
|
<div className="border border-border rounded-xl p-6 bg-surface space-y-3">
|
|
<p className="font-semibold">
|
|
Done — {importDone.migrated} moved, {importDone.skipped} already there, {importDone.failed} failed.
|
|
</p>
|
|
<Button onClick={() => router.push(importDone.profileUrl)}>Go to your Ritgram profile</Button>
|
|
</div>
|
|
)}
|
|
|
|
<p className="text-sm text-foreground-secondary mt-10">
|
|
Prefer the command line, or moving a huge repo?{' '}
|
|
<Link href="/docs/import-from-github" className="underline">
|
|
See the manual steps
|
|
</Link>
|
|
.
|
|
</p>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function statusLabel(status: RepoStatus | undefined): string {
|
|
switch (status) {
|
|
case 'migrating':
|
|
return 'Moving…'
|
|
case 'migrated':
|
|
return 'Done'
|
|
case 'skipped':
|
|
return 'Already there'
|
|
case 'failed':
|
|
return 'Failed'
|
|
default:
|
|
return ''
|
|
}
|
|
}
|