CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
mirrors.tsx
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 4a0dea1 | 1 | /** |
| 2 | * Block I9 — Repository mirroring. | |
| 3 | * | |
| 4 | * GET /:owner/:repo/settings/mirror — config form + recent runs | |
| 5 | * POST /:owner/:repo/settings/mirror — save upstream URL + interval | |
| 6 | * POST /:owner/:repo/settings/mirror/delete — remove mirror config | |
| 7 | * POST /:owner/:repo/settings/mirror/sync — run one sync now (owner-only) | |
| 8 | * POST /admin/mirrors/sync-all — site admin, run all due mirrors | |
| 93812e4 | 9 | * |
| 10 | * 2026 polish: scoped `.mirror-*` class system mirrors the gradient hero + | |
| 11 | * card patterns from admin-integrations.tsx and admin-ops.tsx. The hero | |
| 12 | * lives inside the page (below RepoHeader); the recent-run list is | |
| 13 | * card-per-row with status pill, tabular-nums timing, mono SHA/URL. All | |
| 14 | * form actions, query params, and POST handlers preserved verbatim. | |
| 4a0dea1 | 15 | */ |
| 16 | ||
| 17 | import { Hono } from "hono"; | |
| 18 | import { and, eq } from "drizzle-orm"; | |
| 19 | import { db } from "../db"; | |
| 20 | import { repositories, users } from "../db/schema"; | |
| 21 | import { Layout } from "../views/layout"; | |
| ae2a071 | 22 | import { RepoHeader, RepoNav } from "../views/components"; |
| 4127ecf | 23 | import { formatRelative } from "../views/ui"; |
| 4a0dea1 | 24 | import { softAuth, requireAuth } from "../middleware/auth"; |
| 25 | import type { AuthEnv } from "../middleware/auth"; | |
| 26 | import { isSiteAdmin } from "../lib/admin"; | |
| 27 | import { audit } from "../lib/notify"; | |
| 28 | import { | |
| 29 | deleteMirror, | |
| 30 | getMirrorForRepo, | |
| 31 | listRecentRuns, | |
| 32 | runMirrorSync, | |
| 33 | safeUrlForLog, | |
| 34 | syncAllDue, | |
| 35 | upsertMirror, | |
| 36 | validateUpstreamUrl, | |
| 37 | } from "../lib/mirrors"; | |
| 38 | ||
| 39 | const mirrors = new Hono<AuthEnv>(); | |
| 40 | mirrors.use("*", softAuth); | |
| 41 | ||
| 93812e4 | 42 | /* ───────────────────────────────────────────────────────────────────────── |
| 43 | * Scoped CSS — every class prefixed `.mirror-*` so the surface can't bleed | |
| 44 | * into RepoHeader / nav above. Tokens reused from the layout | |
| 45 | * (--bg-elevated, --border, --text-strong, --space-*, --font-*). | |
| 46 | * ───────────────────────────────────────────────────────────────────── */ | |
| 47 | const mirrorStyles = ` | |
| eed4684 | 48 | .mirror-wrap { max-width: 1680px; margin: 0 auto; padding: var(--space-5) var(--space-4) var(--space-8); } |
| 93812e4 | 49 | |
| 50 | /* ─── Hero ─── */ | |
| 51 | .mirror-hero { | |
| 52 | position: relative; | |
| 53 | margin-bottom: var(--space-5); | |
| 54 | padding: var(--space-5) var(--space-6); | |
| 55 | background: var(--bg-elevated); | |
| 56 | border: 1px solid var(--border); | |
| 57 | border-radius: 16px; | |
| 58 | overflow: hidden; | |
| 59 | } | |
| 60 | .mirror-hero::before { | |
| 61 | content: ''; | |
| 62 | position: absolute; | |
| 63 | top: 0; left: 0; right: 0; | |
| 64 | height: 2px; | |
| 6fd5915 | 65 | background: linear-gradient(90deg, transparent 0%, #5b6ee8 30%, #5f8fa0 70%, transparent 100%); |
| 93812e4 | 66 | opacity: 0.7; |
| 67 | pointer-events: none; | |
| 68 | } | |
| 69 | .mirror-hero-orb { | |
| 70 | position: absolute; | |
| 71 | inset: -20% -10% auto auto; | |
| 72 | width: 380px; height: 380px; | |
| 6fd5915 | 73 | background: radial-gradient(circle, rgba(91,110,232,0.20), rgba(95,143,160,0.10) 45%, transparent 70%); |
| 93812e4 | 74 | filter: blur(80px); |
| 75 | opacity: 0.7; | |
| 76 | pointer-events: none; | |
| 77 | z-index: 0; | |
| 78 | } | |
| 79 | .mirror-hero-inner { | |
| 80 | position: relative; | |
| 81 | z-index: 1; | |
| 82 | display: flex; | |
| 83 | align-items: flex-end; | |
| 84 | justify-content: space-between; | |
| 85 | gap: var(--space-4); | |
| 86 | flex-wrap: wrap; | |
| 87 | } | |
| 88 | .mirror-hero-text { max-width: 720px; flex: 1; min-width: 240px; } | |
| 89 | .mirror-eyebrow { | |
| 90 | display: inline-flex; | |
| 91 | align-items: center; | |
| 92 | gap: 8px; | |
| 93 | text-transform: uppercase; | |
| 94 | font-family: var(--font-mono); | |
| 95 | font-size: 11px; | |
| 96 | letter-spacing: 0.16em; | |
| 97 | color: var(--text-muted); | |
| 98 | font-weight: 600; | |
| 99 | margin-bottom: 10px; | |
| 100 | } | |
| 101 | .mirror-eyebrow-dot { | |
| 102 | width: 8px; height: 8px; | |
| 103 | border-radius: 9999px; | |
| 6fd5915 | 104 | background: linear-gradient(135deg, #5b6ee8, #5f8fa0); |
| 105 | box-shadow: 0 0 0 3px rgba(91,110,232,0.18); | |
| 93812e4 | 106 | } |
| 107 | .mirror-title { | |
| 108 | font-family: var(--font-display); | |
| 109 | font-size: clamp(28px, 4vw, 40px); | |
| 110 | font-weight: 800; | |
| 111 | letter-spacing: -0.028em; | |
| 112 | line-height: 1.05; | |
| 113 | margin: 0 0 var(--space-2); | |
| 114 | color: var(--text-strong); | |
| 115 | } | |
| 116 | .mirror-title-grad { | |
| 6fd5915 | 117 | background-image: linear-gradient(135deg, #5b6ee8 0%, #5b6ee8 50%, #5f8fa0 100%); |
| 93812e4 | 118 | -webkit-background-clip: text; |
| 119 | background-clip: text; | |
| 120 | -webkit-text-fill-color: transparent; | |
| 121 | color: transparent; | |
| 122 | } | |
| 123 | .mirror-sub { | |
| 124 | font-size: 15px; | |
| 125 | color: var(--text-muted); | |
| 126 | margin: 0; | |
| 127 | line-height: 1.5; | |
| 128 | max-width: 620px; | |
| 129 | } | |
| 130 | .mirror-sub code { | |
| 131 | font-family: var(--font-mono); | |
| 132 | font-size: 13px; | |
| 133 | background: var(--bg-tertiary); | |
| 134 | padding: 1px 5px; | |
| 135 | border-radius: 4px; | |
| 136 | } | |
| 137 | .mirror-hero-cta { | |
| 138 | display: inline-flex; | |
| 139 | align-items: center; | |
| 140 | gap: 6px; | |
| 141 | padding: 10px 18px; | |
| 142 | font-size: 13.5px; | |
| 143 | font-weight: 600; | |
| 144 | border-radius: 10px; | |
| 145 | border: 1px solid transparent; | |
| 146 | cursor: pointer; | |
| 147 | font: inherit; | |
| 148 | line-height: 1; | |
| 149 | white-space: nowrap; | |
| 150 | text-decoration: none; | |
| 151 | color: #ffffff; | |
| 6fd5915 | 152 | background: linear-gradient(135deg, #5b6ee8 0%, #5f8fa0 100%); |
| 153 | box-shadow: 0 6px 18px -6px rgba(91,110,232,0.50), inset 0 1px 0 rgba(255,255,255,0.16); | |
| 93812e4 | 154 | transition: transform 120ms ease, box-shadow 120ms ease; |
| 155 | } | |
| 156 | .mirror-hero-cta:hover { | |
| 157 | transform: translateY(-1px); | |
| 6fd5915 | 158 | box-shadow: 0 10px 24px -8px rgba(91,110,232,0.60), inset 0 1px 0 rgba(255,255,255,0.20); |
| 93812e4 | 159 | text-decoration: none; |
| 160 | color: #ffffff; | |
| 161 | } | |
| 162 | ||
| 163 | /* ─── Banners ─── */ | |
| 164 | .mirror-banner { | |
| 165 | margin-bottom: var(--space-4); | |
| 166 | padding: 10px 14px; | |
| 167 | border-radius: 10px; | |
| 168 | font-size: 13.5px; | |
| 169 | border: 1px solid var(--border); | |
| 170 | background: rgba(255,255,255,0.025); | |
| 171 | color: var(--text); | |
| 172 | display: flex; | |
| 173 | align-items: center; | |
| 174 | gap: 10px; | |
| 175 | } | |
| 176 | .mirror-banner.is-ok { | |
| 177 | border-color: rgba(52,211,153,0.40); | |
| 178 | background: rgba(52,211,153,0.08); | |
| 179 | color: #bbf7d0; | |
| 180 | } | |
| 181 | .mirror-banner.is-error { | |
| 182 | border-color: rgba(248,113,113,0.40); | |
| 183 | background: rgba(248,113,113,0.08); | |
| 184 | color: #fecaca; | |
| 185 | } | |
| 186 | .mirror-banner-dot { | |
| 187 | width: 8px; height: 8px; | |
| 188 | border-radius: 9999px; | |
| 189 | background: currentColor; | |
| 190 | flex-shrink: 0; | |
| 191 | } | |
| 192 | ||
| 193 | /* ─── Section cards ─── */ | |
| 194 | .mirror-section { | |
| 195 | margin-bottom: var(--space-5); | |
| 196 | background: var(--bg-elevated); | |
| 197 | border: 1px solid var(--border); | |
| 198 | border-radius: 14px; | |
| 199 | overflow: hidden; | |
| 200 | position: relative; | |
| 201 | } | |
| 202 | .mirror-section::before { | |
| 203 | content: ''; | |
| 204 | position: absolute; | |
| 205 | top: 0; left: 0; right: 0; | |
| 206 | height: 2px; | |
| 6fd5915 | 207 | background: linear-gradient(90deg, transparent 0%, #5b6ee8 30%, #5f8fa0 70%, transparent 100%); |
| 93812e4 | 208 | opacity: 0.45; |
| 209 | pointer-events: none; | |
| 210 | } | |
| 211 | .mirror-section-head { | |
| 212 | padding: var(--space-4) var(--space-5); | |
| 213 | border-bottom: 1px solid var(--border); | |
| 214 | display: flex; | |
| 215 | align-items: flex-start; | |
| 216 | justify-content: space-between; | |
| 217 | gap: var(--space-3); | |
| 218 | flex-wrap: wrap; | |
| 219 | } | |
| 220 | .mirror-section-title { | |
| 221 | margin: 0; | |
| 222 | font-family: var(--font-display); | |
| 223 | font-size: 16px; | |
| 224 | font-weight: 700; | |
| 225 | letter-spacing: -0.018em; | |
| 226 | color: var(--text-strong); | |
| 227 | display: flex; | |
| 228 | align-items: center; | |
| 229 | gap: 10px; | |
| 230 | } | |
| 231 | .mirror-section-title-icon { | |
| 232 | display: inline-flex; | |
| 233 | align-items: center; | |
| 234 | justify-content: center; | |
| 235 | width: 26px; height: 26px; | |
| 236 | border-radius: 8px; | |
| 6fd5915 | 237 | background: rgba(91,110,232,0.12); |
| 238 | color: #5b6ee8; | |
| 239 | box-shadow: inset 0 0 0 1px rgba(91,110,232,0.28); | |
| 93812e4 | 240 | flex-shrink: 0; |
| 241 | } | |
| 242 | .mirror-section-sub { | |
| 243 | margin: 6px 0 0 36px; | |
| 244 | font-size: 12.5px; | |
| 245 | color: var(--text-muted); | |
| 246 | line-height: 1.45; | |
| 247 | } | |
| 248 | .mirror-section-body { padding: var(--space-4) var(--space-5); } | |
| 249 | ||
| 250 | /* ─── Form ─── */ | |
| 251 | .mirror-field { margin-bottom: var(--space-4); } | |
| 252 | .mirror-field:last-child { margin-bottom: 0; } | |
| 253 | .mirror-field-label { | |
| 254 | display: block; | |
| 255 | font-size: 11.5px; | |
| 256 | color: var(--text-muted); | |
| 257 | font-weight: 600; | |
| 258 | text-transform: uppercase; | |
| 259 | letter-spacing: 0.06em; | |
| 260 | margin-bottom: 6px; | |
| 261 | } | |
| 262 | .mirror-input { | |
| 263 | width: 100%; | |
| 264 | box-sizing: border-box; | |
| 265 | padding: 9px 12px; | |
| 266 | font: inherit; | |
| 267 | font-size: 13.5px; | |
| 268 | color: var(--text); | |
| 269 | background: rgba(255,255,255,0.03); | |
| 270 | border: 1px solid var(--border-strong); | |
| 271 | border-radius: 10px; | |
| 272 | transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease; | |
| 273 | font-family: var(--font-mono); | |
| 274 | } | |
| 275 | .mirror-input:focus { | |
| 276 | outline: none; | |
| 6fd5915 | 277 | border-color: rgba(91,110,232,0.55); |
| 93812e4 | 278 | background: rgba(255,255,255,0.05); |
| 6fd5915 | 279 | box-shadow: 0 0 0 3px rgba(91,110,232,0.18); |
| 93812e4 | 280 | } |
| 281 | .mirror-input.is-num { max-width: 180px; font-family: var(--font-mono); font-variant-numeric: tabular-nums; } | |
| 282 | .mirror-checkbox-row { | |
| 283 | display: inline-flex; | |
| 284 | align-items: center; | |
| 285 | gap: 9px; | |
| 286 | padding: 8px 12px; | |
| 287 | border-radius: 9999px; | |
| 288 | background: rgba(255,255,255,0.025); | |
| 289 | border: 1px solid var(--border); | |
| 290 | font-size: 13px; | |
| 291 | color: var(--text); | |
| 292 | cursor: pointer; | |
| 293 | } | |
| 6fd5915 | 294 | .mirror-checkbox-row input { accent-color: #5b6ee8; } |
| 93812e4 | 295 | |
| 296 | /* ─── Buttons ─── */ | |
| 297 | .mirror-btn { | |
| 298 | display: inline-flex; | |
| 299 | align-items: center; | |
| 300 | justify-content: center; | |
| 301 | gap: 6px; | |
| 302 | padding: 9px 16px; | |
| 303 | border-radius: 10px; | |
| 304 | font-size: 13px; | |
| 305 | font-weight: 600; | |
| 306 | text-decoration: none; | |
| 307 | border: 1px solid transparent; | |
| 308 | cursor: pointer; | |
| 309 | font: inherit; | |
| 310 | transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease, border-color 120ms ease, color 120ms ease; | |
| 311 | line-height: 1; | |
| 312 | white-space: nowrap; | |
| 313 | } | |
| 314 | .mirror-btn-primary { | |
| 6fd5915 | 315 | background: linear-gradient(135deg, #5b6ee8 0%, #5f8fa0 100%); |
| 93812e4 | 316 | color: #ffffff; |
| 6fd5915 | 317 | box-shadow: 0 6px 18px -6px rgba(91,110,232,0.50), inset 0 1px 0 rgba(255,255,255,0.16); |
| 93812e4 | 318 | } |
| 319 | .mirror-btn-primary:hover { | |
| 320 | transform: translateY(-1px); | |
| 6fd5915 | 321 | box-shadow: 0 10px 24px -8px rgba(91,110,232,0.60), inset 0 1px 0 rgba(255,255,255,0.20); |
| 93812e4 | 322 | color: #ffffff; |
| 323 | text-decoration: none; | |
| 324 | } | |
| 325 | .mirror-btn-ghost { | |
| 326 | background: transparent; | |
| 327 | color: var(--text); | |
| 328 | border-color: var(--border-strong); | |
| 329 | } | |
| 330 | .mirror-btn-ghost:hover { | |
| 6fd5915 | 331 | background: rgba(91,110,232,0.06); |
| 332 | border-color: rgba(91,110,232,0.45); | |
| 93812e4 | 333 | color: var(--text-strong); |
| 334 | text-decoration: none; | |
| 335 | } | |
| 336 | .mirror-btn-danger { | |
| 337 | background: transparent; | |
| 338 | color: #fca5a5; | |
| 339 | border-color: rgba(248,113,113,0.35); | |
| 340 | } | |
| 341 | .mirror-btn-danger:hover { | |
| 342 | border-style: dashed; | |
| 343 | border-color: rgba(248,113,113,0.70); | |
| 344 | background: rgba(248,113,113,0.06); | |
| 345 | color: #fecaca; | |
| 346 | text-decoration: none; | |
| 347 | } | |
| 348 | .mirror-action-row { display: flex; gap: 10px; flex-wrap: wrap; } | |
| 349 | .mirror-action-row form { margin: 0; } | |
| 350 | ||
| 351 | /* ─── Status pills ─── */ | |
| 352 | .mirror-pill { | |
| 353 | display: inline-flex; | |
| 354 | align-items: center; | |
| 355 | gap: 6px; | |
| 356 | padding: 3px 9px; | |
| 357 | border-radius: 9999px; | |
| 358 | font-size: 11px; | |
| 359 | font-weight: 600; | |
| 360 | letter-spacing: 0.04em; | |
| 361 | text-transform: uppercase; | |
| 362 | } | |
| 363 | .mirror-pill .dot { width: 6px; height: 6px; border-radius: 9999px; background: currentColor; } | |
| 364 | .mirror-pill.is-ok { | |
| 365 | background: rgba(52,211,153,0.14); | |
| 366 | color: #6ee7b7; | |
| 367 | box-shadow: inset 0 0 0 1px rgba(52,211,153,0.32); | |
| 368 | } | |
| 369 | .mirror-pill.is-error { | |
| 370 | background: rgba(248,113,113,0.14); | |
| 371 | color: #fca5a5; | |
| 372 | box-shadow: inset 0 0 0 1px rgba(248,113,113,0.32); | |
| 373 | } | |
| 374 | .mirror-pill.is-pending { | |
| 375 | background: rgba(251,191,36,0.12); | |
| 376 | color: #fde68a; | |
| 377 | box-shadow: inset 0 0 0 1px rgba(251,191,36,0.32); | |
| 378 | } | |
| 379 | .mirror-pill.is-neutral { | |
| 380 | background: rgba(148,163,184,0.16); | |
| 381 | color: #cbd5e1; | |
| 382 | box-shadow: inset 0 0 0 1px rgba(148,163,184,0.30); | |
| 383 | } | |
| 384 | ||
| 385 | /* ─── Run row cards ─── */ | |
| 386 | .mirror-run-list { display: flex; flex-direction: column; gap: 8px; } | |
| 387 | .mirror-run-card { | |
| 388 | display: flex; | |
| 389 | align-items: center; | |
| 390 | gap: 14px; | |
| 391 | padding: 12px 14px; | |
| 392 | background: rgba(255,255,255,0.018); | |
| 393 | border: 1px solid var(--border); | |
| 394 | border-radius: 12px; | |
| 395 | transition: border-color 120ms ease, background 120ms ease; | |
| 396 | } | |
| 397 | .mirror-run-card:hover { | |
| 398 | border-color: var(--border-strong); | |
| 399 | background: rgba(255,255,255,0.03); | |
| 400 | } | |
| 401 | .mirror-run-meta { | |
| 402 | flex: 1; | |
| 403 | min-width: 0; | |
| 404 | display: flex; | |
| 405 | align-items: center; | |
| 406 | gap: 10px; | |
| 407 | flex-wrap: wrap; | |
| 408 | font-size: 12.5px; | |
| 409 | color: var(--text-muted); | |
| 410 | font-variant-numeric: tabular-nums; | |
| 411 | } | |
| 412 | .mirror-run-meta .sep { opacity: 0.45; } | |
| 413 | .mirror-run-msg { | |
| 414 | font-size: 12.5px; | |
| 415 | color: var(--text-muted); | |
| 416 | max-width: 360px; | |
| 417 | overflow: hidden; | |
| 418 | text-overflow: ellipsis; | |
| 419 | white-space: nowrap; | |
| 420 | font-family: var(--font-mono); | |
| 421 | } | |
| 422 | ||
| 423 | /* ─── Last-run summary ─── */ | |
| 424 | .mirror-last { | |
| 425 | display: flex; | |
| 426 | align-items: flex-start; | |
| 427 | gap: 14px; | |
| 428 | flex-wrap: wrap; | |
| 429 | } | |
| 430 | .mirror-last-left { flex: 1; min-width: 220px; } | |
| 431 | .mirror-last-stamp { | |
| 432 | font-family: var(--font-mono); | |
| 433 | font-size: 12.5px; | |
| 434 | color: var(--text-muted); | |
| 435 | font-variant-numeric: tabular-nums; | |
| 436 | margin-top: 4px; | |
| 437 | } | |
| 438 | .mirror-last-error { | |
| 439 | margin-top: 10px; | |
| 440 | padding: 10px 12px; | |
| 441 | background: rgba(248,113,113,0.06); | |
| 442 | border: 1px solid rgba(248,113,113,0.32); | |
| 443 | border-radius: 10px; | |
| 444 | font-family: var(--font-mono); | |
| 445 | font-size: 12px; | |
| 446 | color: #fecaca; | |
| 447 | overflow-x: auto; | |
| 448 | white-space: pre-wrap; | |
| 449 | word-break: break-word; | |
| 450 | line-height: 1.45; | |
| 451 | } | |
| 452 | .mirror-upstream-foot { | |
| 453 | margin-top: var(--space-3); | |
| 454 | padding: 10px 12px; | |
| 455 | border-radius: 10px; | |
| 456 | background: rgba(255,255,255,0.02); | |
| 457 | border: 1px dashed var(--border); | |
| 458 | font-size: 12px; | |
| 459 | color: var(--text-muted); | |
| 460 | line-height: 1.5; | |
| 461 | } | |
| 462 | .mirror-upstream-foot code { | |
| 463 | font-family: var(--font-mono); | |
| 464 | font-size: 12px; | |
| 465 | color: var(--text); | |
| 466 | background: var(--bg-tertiary); | |
| 467 | padding: 1px 5px; | |
| 468 | border-radius: 4px; | |
| 469 | } | |
| 470 | ||
| 471 | /* ─── Empty state ─── */ | |
| 472 | .mirror-empty { | |
| 473 | position: relative; | |
| 474 | overflow: hidden; | |
| 475 | padding: clamp(28px, 5vw, 48px) clamp(20px, 4vw, 36px); | |
| 476 | text-align: center; | |
| 477 | background: var(--bg-elevated); | |
| 478 | border: 1px dashed var(--border-strong); | |
| 479 | border-radius: 16px; | |
| 480 | } | |
| 481 | .mirror-empty-orb { | |
| 482 | position: absolute; | |
| 483 | inset: -40% 30% auto 30%; | |
| 484 | height: 280px; | |
| 6fd5915 | 485 | background: radial-gradient(circle, rgba(91,110,232,0.18), rgba(95,143,160,0.10) 45%, transparent 70%); |
| 93812e4 | 486 | filter: blur(70px); |
| 487 | opacity: 0.7; | |
| 488 | pointer-events: none; | |
| 489 | z-index: 0; | |
| 490 | } | |
| 491 | .mirror-empty-inner { position: relative; z-index: 1; } | |
| 492 | .mirror-empty-icon { | |
| 493 | width: 56px; height: 56px; | |
| 494 | border-radius: 9999px; | |
| 6fd5915 | 495 | background: linear-gradient(135deg, rgba(91,110,232,0.25), rgba(95,143,160,0.20)); |
| 496 | box-shadow: inset 0 0 0 1px rgba(91,110,232,0.40); | |
| 93812e4 | 497 | display: inline-flex; |
| 498 | align-items: center; | |
| 499 | justify-content: center; | |
| 500 | color: #c4b5fd; | |
| 501 | margin-bottom: 14px; | |
| 502 | } | |
| 503 | .mirror-empty-title { | |
| 504 | font-family: var(--font-display); | |
| 505 | font-size: 18px; | |
| 506 | font-weight: 700; | |
| 507 | margin: 0 0 6px; | |
| 508 | color: var(--text-strong); | |
| 509 | } | |
| 510 | .mirror-empty-sub { | |
| 511 | margin: 0 auto 0; | |
| 512 | font-size: 13.5px; | |
| 513 | color: var(--text-muted); | |
| 514 | max-width: 460px; | |
| 515 | line-height: 1.5; | |
| 516 | } | |
| 517 | ||
| 518 | .mirror-403 { | |
| 519 | max-width: 540px; | |
| 520 | margin: var(--space-12) auto; | |
| 521 | padding: var(--space-6); | |
| 522 | text-align: center; | |
| 523 | background: var(--bg-elevated); | |
| 524 | border: 1px solid var(--border); | |
| 525 | border-radius: 16px; | |
| 526 | } | |
| 527 | .mirror-403 h2 { | |
| 528 | font-family: var(--font-display); | |
| 529 | font-size: 22px; | |
| 530 | margin: 0 0 8px; | |
| 531 | color: var(--text-strong); | |
| 532 | } | |
| 533 | .mirror-403 p { color: var(--text-muted); margin: 0; font-size: 14px; } | |
| 534 | `; | |
| 535 | ||
| 536 | function IconMirror() { | |
| 537 | return ( | |
| 538 | <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> | |
| 539 | <polyline points="17 1 21 5 17 9" /> | |
| 540 | <path d="M3 11V9a4 4 0 0 1 4-4h14" /> | |
| 541 | <polyline points="7 23 3 19 7 15" /> | |
| 542 | <path d="M21 13v2a4 4 0 0 1-4 4H3" /> | |
| 543 | </svg> | |
| 544 | ); | |
| 545 | } | |
| 546 | function IconClock() { | |
| 547 | return ( | |
| 548 | <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> | |
| 549 | <circle cx="12" cy="12" r="10" /> | |
| 550 | <polyline points="12 6 12 12 16 14" /> | |
| 551 | </svg> | |
| 552 | ); | |
| 553 | } | |
| 554 | ||
| 555 | function renderForbidden(user: any) { | |
| 556 | return ( | |
| 557 | <Layout title="Forbidden" user={user}> | |
| 558 | <div class="mirror-wrap"> | |
| 559 | <div class="mirror-403"> | |
| 560 | <h2>403 — Forbidden</h2> | |
| 561 | <p>Only the repository owner can configure mirroring.</p> | |
| 562 | </div> | |
| 563 | </div> | |
| 564 | <style dangerouslySetInnerHTML={{ __html: mirrorStyles }} /> | |
| 565 | </Layout> | |
| 566 | ); | |
| 567 | } | |
| 568 | ||
| 4a0dea1 | 569 | async function ownerGate(c: any): Promise< |
| 570 | | Response | |
| 571 | | { | |
| 572 | user: any; | |
| 573 | ownerName: string; | |
| 574 | repoName: string; | |
| 575 | repo: typeof repositories.$inferSelect; | |
| 576 | } | |
| 577 | > { | |
| 578 | const user = c.get("user"); | |
| 579 | if (!user) return c.redirect("/login"); | |
| 580 | const { owner: ownerName, repo: repoName } = c.req.param(); | |
| 581 | const [owner] = await db | |
| 582 | .select() | |
| 583 | .from(users) | |
| 584 | .where(eq(users.username, ownerName)) | |
| 585 | .limit(1); | |
| 586 | if (!owner || owner.id !== user.id) { | |
| 93812e4 | 587 | return c.html(renderForbidden(user), 403); |
| 4a0dea1 | 588 | } |
| 589 | const [repo] = await db | |
| 590 | .select() | |
| 591 | .from(repositories) | |
| 592 | .where( | |
| 593 | and(eq(repositories.ownerId, owner.id), eq(repositories.name, repoName)) | |
| 594 | ) | |
| 595 | .limit(1); | |
| 596 | if (!repo) return c.notFound(); | |
| 597 | return { user, ownerName, repoName, repo }; | |
| 598 | } | |
| 599 | ||
| 93812e4 | 600 | function statusPill(status: string | null | undefined) { |
| 601 | const s = (status || "").toLowerCase(); | |
| 602 | if (s === "ok" || s === "success") { | |
| 603 | return ( | |
| 604 | <span class="mirror-pill is-ok"> | |
| 605 | <span class="dot" aria-hidden="true" /> | |
| 606 | Success | |
| 607 | </span> | |
| 608 | ); | |
| 609 | } | |
| 610 | if (s === "error" || s === "failed") { | |
| 611 | return ( | |
| 612 | <span class="mirror-pill is-error"> | |
| 613 | <span class="dot" aria-hidden="true" /> | |
| 614 | Error | |
| 615 | </span> | |
| 616 | ); | |
| 617 | } | |
| 618 | if (s === "pending" || s === "running") { | |
| 619 | return ( | |
| 620 | <span class="mirror-pill is-pending"> | |
| 621 | <span class="dot" aria-hidden="true" /> | |
| 622 | {s === "running" ? "Running" : "Pending"} | |
| 623 | </span> | |
| 624 | ); | |
| 625 | } | |
| 626 | return ( | |
| 627 | <span class="mirror-pill is-neutral"> | |
| 628 | <span class="dot" aria-hidden="true" /> | |
| 629 | {s || "Unknown"} | |
| 630 | </span> | |
| 631 | ); | |
| 632 | } | |
| 633 | ||
| 4a0dea1 | 634 | // ---------- Config page ---------- |
| 635 | ||
| 636 | mirrors.get("/:owner/:repo/settings/mirror", requireAuth, async (c) => { | |
| 637 | const g = await ownerGate(c); | |
| 638 | if (g instanceof Response) return g; | |
| 639 | const { user, ownerName, repoName, repo } = g; | |
| 640 | ||
| 641 | const mirror = await getMirrorForRepo(repo.id); | |
| 642 | const runs = mirror ? await listRecentRuns(mirror.id, 20) : []; | |
| 643 | ||
| 644 | const success = c.req.query("success"); | |
| 645 | const error = c.req.query("error"); | |
| 646 | ||
| 647 | return c.html( | |
| 648 | <Layout title={`Mirror — ${ownerName}/${repoName}`} user={user}> | |
| 649 | <RepoHeader owner={ownerName} repo={repoName} /> | |
| ae2a071 | 650 | <RepoNav owner={ownerName} repo={repoName} active="settings" /> |
| 93812e4 | 651 | <div class="mirror-wrap"> |
| 652 | <section class="mirror-hero"> | |
| 653 | <div class="mirror-hero-orb" aria-hidden="true" /> | |
| 654 | <div class="mirror-hero-inner"> | |
| 655 | <div class="mirror-hero-text"> | |
| 656 | <div class="mirror-eyebrow"> | |
| 657 | <span class="mirror-eyebrow-dot" aria-hidden="true" /> | |
| 658 | Repository · Mirror | |
| 659 | </div> | |
| 660 | <h1 class="mirror-title"> | |
| 661 | <span class="mirror-title-grad">Track an upstream.</span> | |
| 662 | </h1> | |
| 663 | <p class="mirror-sub"> | |
| 664 | Periodically <code>git fetch --prune</code> from an upstream URL. | |
| 665 | Only <code>https://</code>, <code>http://</code>, and{" "} | |
| 666 | <code>git://</code> are accepted — SSH and local paths are not. | |
| 667 | </p> | |
| 668 | </div> | |
| 669 | {mirror && ( | |
| 4a0dea1 | 670 | <form |
| cce7944 | 671 | method="post" |
| 4a0dea1 | 672 | action={`/${ownerName}/${repoName}/settings/mirror/sync`} |
| 673 | > | |
| 93812e4 | 674 | <button type="submit" class="mirror-hero-cta"> |
| 675 | <IconMirror /> | |
| 4a0dea1 | 676 | Sync now |
| 677 | </button> | |
| 678 | </form> | |
| 93812e4 | 679 | )} |
| 680 | </div> | |
| 681 | </section> | |
| 682 | ||
| 683 | {success && ( | |
| 684 | <div class="mirror-banner is-ok" role="status"> | |
| 685 | <span class="mirror-banner-dot" aria-hidden="true" /> | |
| 686 | {decodeURIComponent(success)} | |
| 687 | </div> | |
| 688 | )} | |
| 689 | {error && ( | |
| 690 | <div class="mirror-banner is-error" role="alert"> | |
| 691 | <span class="mirror-banner-dot" aria-hidden="true" /> | |
| 692 | {decodeURIComponent(error)} | |
| 693 | </div> | |
| 694 | )} | |
| 695 | ||
| 696 | <section class="mirror-section"> | |
| 697 | <header class="mirror-section-head"> | |
| 698 | <div> | |
| 699 | <h2 class="mirror-section-title"> | |
| 700 | <span class="mirror-section-title-icon" aria-hidden="true"> | |
| 701 | <IconMirror /> | |
| 702 | </span> | |
| 703 | Mirror configuration | |
| 704 | </h2> | |
| 705 | <p class="mirror-section-sub"> | |
| 706 | Set the upstream URL and a sync cadence between 5 minutes and | |
| 707 | 30 days. Disable to keep the config but pause auto-sync. | |
| 708 | </p> | |
| 4a0dea1 | 709 | </div> |
| 93812e4 | 710 | </header> |
| 711 | <div class="mirror-section-body"> | |
| 712 | <form | |
| 713 | method="post" | |
| 714 | action={`/${ownerName}/${repoName}/settings/mirror`} | |
| 715 | > | |
| 716 | <div class="mirror-field"> | |
| 717 | <label class="mirror-field-label" for="upstream_url"> | |
| 718 | Upstream URL | |
| 719 | </label> | |
| 720 | <input | |
| 721 | type="text" | |
| 722 | id="upstream_url" | |
| 723 | name="upstream_url" | |
| 724 | value={mirror?.upstreamUrl || ""} | |
| 725 | placeholder="https://github.com/torvalds/linux.git" | |
| 726 | required | |
| 727 | class="mirror-input" | |
| 728 | autocomplete="off" | |
| 729 | spellcheck={false} | |
| 730 | /> | |
| 731 | </div> | |
| 732 | <div class="mirror-field"> | |
| 733 | <label class="mirror-field-label" for="interval_minutes"> | |
| 734 | Sync interval (minutes) | |
| 735 | </label> | |
| 736 | <input | |
| 737 | type="number" | |
| 738 | id="interval_minutes" | |
| 739 | name="interval_minutes" | |
| 740 | value={mirror?.intervalMinutes ?? 1440} | |
| 741 | min="5" | |
| 742 | max="43200" | |
| 743 | class="mirror-input is-num" | |
| 744 | /> | |
| 745 | </div> | |
| 746 | <div class="mirror-field"> | |
| 747 | <label class="mirror-checkbox-row"> | |
| 748 | <input | |
| 749 | type="checkbox" | |
| 750 | name="is_enabled" | |
| 751 | value="1" | |
| 752 | checked={mirror ? mirror.isEnabled : true} | |
| 753 | aria-label="Enabled" | |
| 754 | /> | |
| 755 | <span>Enabled</span> | |
| 756 | </label> | |
| 757 | </div> | |
| 758 | <div class="mirror-action-row"> | |
| 759 | <button type="submit" class="mirror-btn mirror-btn-primary"> | |
| 760 | {mirror ? "Update mirror" : "Enable mirror"} | |
| 761 | </button> | |
| 762 | {mirror && ( | |
| 763 | <form | |
| 764 | method="post" | |
| 765 | action={`/${ownerName}/${repoName}/settings/mirror/delete`} | |
| 766 | onsubmit="return confirm('Remove mirror configuration?')" | |
| 767 | > | |
| 768 | <button type="submit" class="mirror-btn mirror-btn-danger"> | |
| 769 | Remove mirror | |
| 770 | </button> | |
| 771 | </form> | |
| 772 | )} | |
| 773 | </div> | |
| 774 | </form> | |
| 775 | </div> | |
| 776 | </section> | |
| 4a0dea1 | 777 | |
| 93812e4 | 778 | {mirror && ( |
| 779 | <section class="mirror-section"> | |
| 780 | <header class="mirror-section-head"> | |
| 781 | <div> | |
| 782 | <h2 class="mirror-section-title"> | |
| 783 | <span class="mirror-section-title-icon" aria-hidden="true"> | |
| 784 | <IconClock /> | |
| 785 | </span> | |
| 786 | Last run | |
| 787 | </h2> | |
| 788 | <p class="mirror-section-sub"> | |
| 789 | Most recent fetch outcome. Errors include the raw stderr. | |
| 790 | </p> | |
| 791 | </div> | |
| 792 | </header> | |
| 793 | <div class="mirror-section-body"> | |
| 4a0dea1 | 794 | {mirror.lastSyncedAt ? ( |
| 93812e4 | 795 | <div class="mirror-last"> |
| 796 | <div class="mirror-last-left"> | |
| 797 | {statusPill(mirror.lastStatus || "ok")} | |
| 798 | <div class="mirror-last-stamp"> | |
| 799 | {formatRelative(mirror.lastSyncedAt as unknown as string)} | |
| 800 | </div> | |
| 801 | {mirror.lastError && ( | |
| 802 | <pre class="mirror-last-error">{mirror.lastError}</pre> | |
| 4127ecf | 803 | )} |
| 4a0dea1 | 804 | </div> |
| 805 | </div> | |
| 806 | ) : ( | |
| 93812e4 | 807 | <div style="color:var(--text-muted);font-size:13.5px"> |
| 808 | Never synced. Hit <em>Sync now</em> above to run the first fetch. | |
| 809 | </div> | |
| 4a0dea1 | 810 | )} |
| 811 | </div> | |
| 93812e4 | 812 | </section> |
| 813 | )} | |
| 4a0dea1 | 814 | |
| 93812e4 | 815 | {mirror && ( |
| 816 | <section class="mirror-section"> | |
| 817 | <header class="mirror-section-head"> | |
| 818 | <div> | |
| 819 | <h2 class="mirror-section-title"> | |
| 820 | <span class="mirror-section-title-icon" aria-hidden="true"> | |
| 821 | <IconClock /> | |
| 822 | </span> | |
| 823 | Recent runs | |
| 824 | <span style="font-family:var(--font-mono);font-size:12px;color:var(--text-muted);font-weight:500;font-variant-numeric:tabular-nums"> | |
| 825 | {" "}({runs.length}) | |
| 826 | </span> | |
| 827 | </h2> | |
| 828 | <p class="mirror-section-sub"> | |
| 829 | Latest 20 fetches, newest first. | |
| 830 | </p> | |
| 831 | </div> | |
| 832 | </header> | |
| 833 | <div class="mirror-section-body"> | |
| 4a0dea1 | 834 | {runs.length === 0 ? ( |
| 93812e4 | 835 | <div class="mirror-empty"> |
| 836 | <div class="mirror-empty-orb" aria-hidden="true" /> | |
| 837 | <div class="mirror-empty-inner"> | |
| 838 | <div class="mirror-empty-icon" aria-hidden="true"> | |
| 839 | <IconClock /> | |
| 4a0dea1 | 840 | </div> |
| 93812e4 | 841 | <h3 class="mirror-empty-title">No runs yet</h3> |
| 842 | <p class="mirror-empty-sub"> | |
| 843 | Once a sync fires (manually or on schedule) it will land | |
| 844 | here with its status and timing. | |
| 845 | </p> | |
| 4a0dea1 | 846 | </div> |
| 93812e4 | 847 | </div> |
| 848 | ) : ( | |
| 849 | <div class="mirror-run-list"> | |
| 850 | {runs.map((r) => ( | |
| 851 | <div class="mirror-run-card"> | |
| 852 | {statusPill(r.status)} | |
| 853 | <div class="mirror-run-meta"> | |
| 854 | <span>{formatRelative(r.startedAt as unknown as string)}</span> | |
| 855 | </div> | |
| 856 | {r.message && ( | |
| 857 | <span class="mirror-run-msg" title={r.message}> | |
| 858 | {r.message.split("\n")[0]} | |
| 859 | </span> | |
| 860 | )} | |
| 861 | </div> | |
| 862 | ))} | |
| 863 | </div> | |
| 4a0dea1 | 864 | )} |
| 93812e4 | 865 | <div class="mirror-upstream-foot"> |
| 866 | Upstream (logged, credentials redacted):{" "} | |
| 867 | <code>{safeUrlForLog(mirror.upstreamUrl)}</code> | |
| 868 | </div> | |
| 4a0dea1 | 869 | </div> |
| 93812e4 | 870 | </section> |
| 4a0dea1 | 871 | )} |
| 872 | </div> | |
| 93812e4 | 873 | <style dangerouslySetInnerHTML={{ __html: mirrorStyles }} /> |
| 4a0dea1 | 874 | </Layout> |
| 875 | ); | |
| 876 | }); | |
| 877 | ||
| 878 | // ---------- Save config ---------- | |
| 879 | ||
| 880 | mirrors.post("/:owner/:repo/settings/mirror", requireAuth, async (c) => { | |
| 881 | const g = await ownerGate(c); | |
| 882 | if (g instanceof Response) return g; | |
| 883 | const { user, ownerName, repoName, repo } = g; | |
| 884 | const body = await c.req.parseBody(); | |
| 885 | const upstreamUrl = String(body.upstream_url || "").trim(); | |
| 886 | const intervalRaw = Number(body.interval_minutes || 1440); | |
| 887 | const interval = Math.max(5, Math.min(43200, Math.floor(intervalRaw || 1440))); | |
| 888 | const isEnabled = String(body.is_enabled || "") === "1"; | |
| 889 | ||
| 890 | const v = validateUpstreamUrl(upstreamUrl); | |
| 891 | if (!v.ok) { | |
| 892 | return c.redirect( | |
| 893 | `/${ownerName}/${repoName}/settings/mirror?error=${encodeURIComponent( | |
| 894 | v.error || "Invalid URL" | |
| 895 | )}` | |
| 896 | ); | |
| 897 | } | |
| 898 | ||
| 899 | const result = await upsertMirror({ | |
| 900 | repositoryId: repo.id, | |
| 901 | upstreamUrl, | |
| 902 | intervalMinutes: interval, | |
| 903 | isEnabled, | |
| 904 | }); | |
| 905 | if (!result.ok) { | |
| 906 | return c.redirect( | |
| 907 | `/${ownerName}/${repoName}/settings/mirror?error=${encodeURIComponent( | |
| 908 | result.error | |
| 909 | )}` | |
| 910 | ); | |
| 911 | } | |
| 912 | ||
| 913 | await audit({ | |
| 914 | userId: user.id, | |
| 915 | repositoryId: repo.id, | |
| 916 | action: "mirror.configure", | |
| 917 | metadata: { | |
| 918 | upstream: safeUrlForLog(upstreamUrl), | |
| 919 | intervalMinutes: interval, | |
| 920 | isEnabled, | |
| 921 | }, | |
| 922 | }); | |
| 923 | ||
| 924 | return c.redirect( | |
| 925 | `/${ownerName}/${repoName}/settings/mirror?success=${encodeURIComponent( | |
| 926 | "Mirror configuration saved." | |
| 927 | )}` | |
| 928 | ); | |
| 929 | }); | |
| 930 | ||
| 931 | // ---------- Delete ---------- | |
| 932 | ||
| 933 | mirrors.post("/:owner/:repo/settings/mirror/delete", requireAuth, async (c) => { | |
| 934 | const g = await ownerGate(c); | |
| 935 | if (g instanceof Response) return g; | |
| 936 | const { user, ownerName, repoName, repo } = g; | |
| 937 | ||
| 938 | await deleteMirror(repo.id); | |
| 939 | await audit({ | |
| 940 | userId: user.id, | |
| 941 | repositoryId: repo.id, | |
| 942 | action: "mirror.delete", | |
| 943 | }); | |
| 944 | ||
| 945 | return c.redirect( | |
| 946 | `/${ownerName}/${repoName}/settings/mirror?success=${encodeURIComponent( | |
| 947 | "Mirror removed." | |
| 948 | )}` | |
| 949 | ); | |
| 950 | }); | |
| 951 | ||
| 952 | // ---------- Sync now ---------- | |
| 953 | ||
| 954 | mirrors.post("/:owner/:repo/settings/mirror/sync", requireAuth, async (c) => { | |
| 955 | const g = await ownerGate(c); | |
| 956 | if (g instanceof Response) return g; | |
| 957 | const { user, ownerName, repoName, repo } = g; | |
| 958 | const mirror = await getMirrorForRepo(repo.id); | |
| 959 | if (!mirror) { | |
| 960 | return c.redirect( | |
| 961 | `/${ownerName}/${repoName}/settings/mirror?error=${encodeURIComponent( | |
| 962 | "No mirror configured" | |
| 963 | )}` | |
| 964 | ); | |
| 965 | } | |
| 966 | ||
| 967 | const result = await runMirrorSync(mirror.id); | |
| 968 | await audit({ | |
| 969 | userId: user.id, | |
| 970 | repositoryId: repo.id, | |
| 971 | action: "mirror.sync", | |
| 972 | metadata: { ok: result.ok, exitCode: result.exitCode }, | |
| 973 | }); | |
| 974 | const msg = result.ok | |
| 975 | ? "Mirror sync completed." | |
| 976 | : `Sync failed: ${result.message.split("\n")[0]}`; | |
| 977 | return c.redirect( | |
| 978 | `/${ownerName}/${repoName}/settings/mirror?${ | |
| 979 | result.ok ? "success" : "error" | |
| 980 | }=${encodeURIComponent(msg)}` | |
| 981 | ); | |
| 982 | }); | |
| 983 | ||
| 984 | // ---------- Admin: sync all due ---------- | |
| 985 | ||
| 986 | mirrors.post("/admin/mirrors/sync-all", requireAuth, async (c) => { | |
| 987 | const user = c.get("user")!; | |
| 988 | if (!(await isSiteAdmin(user.id))) { | |
| 989 | return c.html( | |
| 990 | <Layout title="Forbidden" user={user}> | |
| 93812e4 | 991 | <div class="mirror-wrap"> |
| 992 | <div class="mirror-403"> | |
| 993 | <h2>403 — Forbidden</h2> | |
| 994 | <p>Site admin only.</p> | |
| 995 | </div> | |
| 4a0dea1 | 996 | </div> |
| 93812e4 | 997 | <style dangerouslySetInnerHTML={{ __html: mirrorStyles }} /> |
| 4a0dea1 | 998 | </Layout>, |
| 999 | 403 | |
| 1000 | ); | |
| 1001 | } | |
| 1002 | const summary = await syncAllDue(); | |
| 1003 | await audit({ | |
| 1004 | userId: user.id, | |
| 1005 | action: "admin.mirrors.sync-all", | |
| 1006 | metadata: summary, | |
| 1007 | }); | |
| 1008 | return c.redirect( | |
| 1009 | `/admin?message=${encodeURIComponent( | |
| 1010 | `Mirror sync: ${summary.total} due, ${summary.ok} ok, ${summary.failed} failed.` | |
| 1011 | )}` | |
| 1012 | ); | |
| 1013 | }); | |
| 1014 | ||
| 1015 | export default mirrors; |