CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
web.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.
| fc1817a | 1 | /** |
| 2 | * Web UI routes — browse repositories, code, commits, diffs. | |
| 06d5ffe | 3 | * Now auth-aware with user profiles, repo creation, stars, and syntax highlighting. |
| fc1817a | 4 | */ |
| 5 | ||
| 6 | import { Hono } from "hono"; | |
| 79136bb | 7 | import { html } from "hono/html"; |
| 3951454 | 8 | import { eq, and, desc, inArray } from "drizzle-orm"; |
| 06d5ffe | 9 | import { db } from "../db"; |
| 3951454 | 10 | import { |
| 11 | users, | |
| 12 | repositories, | |
| 13 | stars, | |
| 14 | commitVerifications, | |
| 15 | } from "../db/schema"; | |
| fc1817a | 16 | import { Layout } from "../views/layout"; |
| 17 | import { | |
| 18 | RepoHeader, | |
| 19 | RepoNav, | |
| 20 | Breadcrumb, | |
| 21 | FileTable, | |
| 22 | CommitList, | |
| 23 | DiffView, | |
| 06d5ffe | 24 | RepoCard, |
| 25 | BranchSwitcher, | |
| 26 | HighlightedCode, | |
| 27 | PlainCode, | |
| fc1817a | 28 | } from "../views/components"; |
| 29 | import { | |
| 30 | getTree, | |
| 31 | getBlob, | |
| 32 | listCommits, | |
| 33 | getCommit, | |
| 34 | getCommitFullMessage, | |
| 35 | getDiff, | |
| 36 | getReadme, | |
| 37 | getDefaultBranch, | |
| 38 | listBranches, | |
| 39 | repoExists, | |
| 06d5ffe | 40 | initBareRepo, |
| 79136bb | 41 | getBlame, |
| 42 | getRawBlob, | |
| 43 | searchCode, | |
| fc1817a | 44 | } from "../git/repository"; |
| 79136bb | 45 | import { renderMarkdown, markdownCss } from "../lib/markdown"; |
| 06d5ffe | 46 | import { highlightCode } from "../lib/highlight"; |
| 47 | import { softAuth, requireAuth } from "../middleware/auth"; | |
| 48 | import type { AuthEnv } from "../middleware/auth"; | |
| 8f50ed0 | 49 | import { trackByName } from "../lib/traffic"; |
| fc1817a | 50 | |
| 06d5ffe | 51 | const web = new Hono<AuthEnv>(); |
| 52 | ||
| 53 | // Soft auth on all web routes — c.get("user") available but may be null | |
| 54 | web.use("*", softAuth); | |
| fc1817a | 55 | |
| 56 | // Home page | |
| 06d5ffe | 57 | web.get("/", async (c) => { |
| 58 | const user = c.get("user"); | |
| 59 | ||
| 60 | if (user) { | |
| 3ef4c9d | 61 | const { renderDashboard } = await import("./dashboard"); |
| 62 | return renderDashboard(c); | |
| 06d5ffe | 63 | } |
| 64 | ||
| fc1817a | 65 | return c.html( |
| 06d5ffe | 66 | <Layout user={null}> |
| fc1817a | 67 | <div class="empty-state"> |
| 68 | <h2>gluecron</h2> | |
| 69 | <p>AI-native code intelligence platform</p> | |
| 06d5ffe | 70 | <div style="margin-top: 24px; display: flex; gap: 12px; justify-content: center"> |
| 71 | <a href="/register" class="btn btn-primary"> | |
| 72 | Get started | |
| 73 | </a> | |
| 74 | <a href="/login" class="btn"> | |
| 75 | Sign in | |
| 76 | </a> | |
| 77 | </div> | |
| 78 | <pre style="margin-top: 32px">{`# Quick start | |
| fc1817a | 79 | curl -X POST http://localhost:3000/api/setup \\ |
| 80 | -H 'Content-Type: application/json' \\ | |
| 81 | -d '{"username":"you","email":"you@dev.com","repoName":"hello"}' | |
| 82 | ||
| 83 | git remote add gluecron http://localhost:3000/you/hello.git | |
| 84 | git push gluecron main`}</pre> | |
| 85 | </div> | |
| 86 | </Layout> | |
| 87 | ); | |
| 88 | }); | |
| 89 | ||
| 06d5ffe | 90 | // New repository form |
| 91 | web.get("/new", requireAuth, (c) => { | |
| 92 | const user = c.get("user")!; | |
| 93 | const error = c.req.query("error"); | |
| 94 | ||
| 95 | return c.html( | |
| 96 | <Layout title="New repository" user={user}> | |
| 97 | <div class="new-repo-form"> | |
| 98 | <h2>Create a new repository</h2> | |
| 99 | {error && <div class="auth-error">{decodeURIComponent(error)}</div>} | |
| 9837657 | 100 | <form method="post" action="/new"> |
| 06d5ffe | 101 | <div class="form-group"> |
| 102 | <label>Owner</label> | |
| 103 | <input type="text" value={user.username} disabled class="input-disabled" /> | |
| 104 | </div> | |
| 105 | <div class="form-group"> | |
| 106 | <label for="name">Repository name</label> | |
| 107 | <input | |
| 108 | type="text" | |
| 109 | id="name" | |
| 110 | name="name" | |
| 111 | required | |
| 112 | pattern="^[a-zA-Z0-9._-]+$" | |
| 113 | placeholder="my-project" | |
| 114 | autocomplete="off" | |
| 115 | /> | |
| 116 | </div> | |
| 117 | <div class="form-group"> | |
| 118 | <label for="description">Description (optional)</label> | |
| 119 | <input | |
| 120 | type="text" | |
| 121 | id="description" | |
| 122 | name="description" | |
| 123 | placeholder="A short description of your repository" | |
| 124 | /> | |
| 125 | </div> | |
| 126 | <div class="visibility-options"> | |
| 127 | <label class="visibility-option"> | |
| 128 | <input type="radio" name="visibility" value="public" checked /> | |
| 129 | <div class="vis-label">Public</div> | |
| 130 | <div class="vis-desc">Anyone can see this repository</div> | |
| 131 | </label> | |
| 132 | <label class="visibility-option"> | |
| 133 | <input type="radio" name="visibility" value="private" /> | |
| 134 | <div class="vis-label">Private</div> | |
| 135 | <div class="vis-desc">Only you can see this repository</div> | |
| 136 | </label> | |
| 137 | </div> | |
| 138 | <button type="submit" class="btn btn-primary"> | |
| 139 | Create repository | |
| 140 | </button> | |
| 141 | </form> | |
| 142 | </div> | |
| 143 | </Layout> | |
| 144 | ); | |
| 145 | }); | |
| 146 | ||
| 147 | web.post("/new", requireAuth, async (c) => { | |
| 148 | const user = c.get("user")!; | |
| 149 | const body = await c.req.parseBody(); | |
| 150 | const name = String(body.name || "").trim(); | |
| 151 | const description = String(body.description || "").trim(); | |
| 152 | const isPrivate = body.visibility === "private"; | |
| 153 | ||
| 154 | if (!name) { | |
| 155 | return c.redirect("/new?error=Repository+name+is+required"); | |
| 156 | } | |
| 157 | ||
| 158 | if (!/^[a-zA-Z0-9._-]+$/.test(name)) { | |
| 159 | return c.redirect("/new?error=Invalid+repository+name"); | |
| 160 | } | |
| 161 | ||
| 162 | if (await repoExists(user.username, name)) { | |
| 163 | return c.redirect("/new?error=Repository+already+exists"); | |
| 164 | } | |
| 165 | ||
| 166 | const diskPath = await initBareRepo(user.username, name); | |
| 167 | ||
| 3ef4c9d | 168 | const [newRepo] = await db |
| 169 | .insert(repositories) | |
| 170 | .values({ | |
| 171 | name, | |
| 172 | ownerId: user.id, | |
| 173 | description: description || null, | |
| 174 | isPrivate, | |
| 175 | diskPath, | |
| 176 | }) | |
| 177 | .returning(); | |
| 178 | ||
| 179 | if (newRepo) { | |
| 180 | const { bootstrapRepository } = await import("../lib/repo-bootstrap"); | |
| 181 | await bootstrapRepository({ | |
| 182 | repositoryId: newRepo.id, | |
| 183 | ownerUserId: user.id, | |
| 184 | defaultBranch: "main", | |
| 185 | }); | |
| 186 | } | |
| 06d5ffe | 187 | |
| 188 | return c.redirect(`/${user.username}/${name}`); | |
| 189 | }); | |
| 190 | ||
| 191 | // User profile | |
| fc1817a | 192 | web.get("/:owner", async (c) => { |
| 06d5ffe | 193 | const { owner: ownerName } = c.req.param(); |
| 194 | const user = c.get("user"); | |
| 195 | ||
| 196 | // Avoid clashing with fixed routes | |
| 197 | if ( | |
| 198 | ["login", "register", "logout", "new", "settings", "api"].includes( | |
| 199 | ownerName | |
| 200 | ) | |
| 201 | ) { | |
| 202 | return c.notFound(); | |
| 203 | } | |
| 204 | ||
| 205 | let ownerUser; | |
| 206 | try { | |
| 207 | const [found] = await db | |
| 208 | .select() | |
| 209 | .from(users) | |
| 210 | .where(eq(users.username, ownerName)) | |
| 211 | .limit(1); | |
| 212 | ownerUser = found; | |
| 213 | } catch { | |
| 214 | // DB not available — check if repos exist on disk | |
| 215 | ownerUser = null; | |
| 216 | } | |
| 217 | ||
| 218 | // Even without DB, show repos if they exist on disk | |
| 219 | let repos: any[] = []; | |
| 220 | if (ownerUser) { | |
| 221 | const allRepos = await db | |
| 222 | .select() | |
| 223 | .from(repositories) | |
| 224 | .where(eq(repositories.ownerId, ownerUser.id)) | |
| 225 | .orderBy(desc(repositories.updatedAt)); | |
| 226 | ||
| 227 | // Show public repos to everyone, private only to owner | |
| 228 | repos = | |
| 229 | user?.id === ownerUser.id | |
| 230 | ? allRepos | |
| 231 | : allRepos.filter((r) => !r.isPrivate); | |
| 232 | } | |
| 233 | ||
| 7aa8b99 | 234 | // Block J4 — follow counts + viewer's follow state |
| 235 | let followState = { | |
| 236 | followers: 0, | |
| 237 | following: 0, | |
| 238 | viewerFollows: false, | |
| 239 | }; | |
| 240 | if (ownerUser) { | |
| 241 | try { | |
| 242 | const { followCounts, isFollowing } = await import("../lib/follows"); | |
| 243 | const counts = await followCounts(ownerUser.id); | |
| 244 | followState.followers = counts.followers; | |
| 245 | followState.following = counts.following; | |
| 246 | if (user && user.id !== ownerUser.id) { | |
| 247 | followState.viewerFollows = await isFollowing(user.id, ownerUser.id); | |
| 248 | } | |
| 249 | } catch { | |
| 250 | // DB hiccup — fall back to zeros. | |
| 251 | } | |
| 252 | } | |
| 253 | const canFollow = !!user && !!ownerUser && user.id !== ownerUser.id; | |
| 254 | ||
| d412586 | 255 | // Block J5 — profile README. Render owner/owner repo's README on the |
| 256 | // profile page (GitHub convention). Tries "<user>/<user>" first, falling | |
| 257 | // back to "<user>/.github" for org-style profile repos. | |
| 258 | let profileReadmeHtml: string | null = null; | |
| 259 | try { | |
| 260 | const candidates = [ownerName, ".github"]; | |
| 261 | for (const rname of candidates) { | |
| 262 | if (await repoExists(ownerName, rname)) { | |
| 263 | const ref = (await getDefaultBranch(ownerName, rname)) || "main"; | |
| 264 | const md = await getReadme(ownerName, rname, ref); | |
| 265 | if (md) { | |
| 266 | profileReadmeHtml = renderMarkdown(md); | |
| 267 | break; | |
| 268 | } | |
| 269 | } | |
| 270 | } | |
| 271 | } catch { | |
| 272 | profileReadmeHtml = null; | |
| 273 | } | |
| 274 | ||
| fc1817a | 275 | return c.html( |
| 06d5ffe | 276 | <Layout title={ownerName} user={user}> |
| 277 | <div class="user-profile"> | |
| 278 | <div class="user-avatar"> | |
| 279 | {(ownerUser?.displayName || ownerName)[0].toUpperCase()} | |
| 280 | </div> | |
| 281 | <div class="user-info"> | |
| 282 | <h2>{ownerUser?.displayName || ownerName}</h2> | |
| 283 | <div class="username">@{ownerName}</div> | |
| 284 | {ownerUser?.bio && <div class="bio">{ownerUser.bio}</div>} | |
| 7aa8b99 | 285 | <div |
| 286 | style="margin-top:8px;display:flex;gap:12px;align-items:center;flex-wrap:wrap;font-size:13px" | |
| 287 | > | |
| 288 | <a | |
| 289 | href={`/${ownerName}/followers`} | |
| 290 | style="color:var(--text-muted)" | |
| 291 | > | |
| 292 | <strong style="color:var(--text)"> | |
| 293 | {followState.followers} | |
| 294 | </strong>{" "} | |
| 295 | follower{followState.followers === 1 ? "" : "s"} | |
| 296 | </a> | |
| 297 | <a | |
| 298 | href={`/${ownerName}/following`} | |
| 299 | style="color:var(--text-muted)" | |
| 300 | > | |
| 301 | <strong style="color:var(--text)"> | |
| 302 | {followState.following} | |
| 303 | </strong>{" "} | |
| 304 | following | |
| 305 | </a> | |
| 306 | {canFollow && ( | |
| 307 | <form | |
| 9837657 | 308 | method="post" |
| 7aa8b99 | 309 | action={`/${ownerName}/${ |
| 310 | followState.viewerFollows ? "unfollow" : "follow" | |
| 311 | }`} | |
| 312 | > | |
| 313 | <button | |
| 314 | type="submit" | |
| 315 | class={`btn ${ | |
| 316 | followState.viewerFollows ? "" : "btn-primary" | |
| 317 | } btn-sm`} | |
| 318 | > | |
| 319 | {followState.viewerFollows ? "Unfollow" : "Follow"} | |
| 320 | </button> | |
| 321 | </form> | |
| 322 | )} | |
| 323 | </div> | |
| 06d5ffe | 324 | </div> |
| 325 | </div> | |
| d412586 | 326 | {profileReadmeHtml && ( |
| 327 | <div | |
| 328 | class="markdown-body" | |
| 329 | style="background:var(--bg-secondary);border:1px solid var(--border);border-radius:var(--radius);padding:20px 24px;margin-bottom:24px" | |
| 330 | dangerouslySetInnerHTML={{ __html: profileReadmeHtml }} | |
| 331 | /> | |
| 332 | )} | |
| 06d5ffe | 333 | <h3 style="margin-bottom: 16px">Repositories</h3> |
| 334 | {repos.length === 0 ? ( | |
| 335 | <p style="color: var(--text-muted)">No repositories yet.</p> | |
| 336 | ) : ( | |
| 337 | <div class="card-grid"> | |
| 338 | {repos.map((repo) => ( | |
| 339 | <RepoCard repo={repo} ownerName={ownerName} /> | |
| 340 | ))} | |
| 341 | </div> | |
| 342 | )} | |
| fc1817a | 343 | </Layout> |
| 344 | ); | |
| 345 | }); | |
| 346 | ||
| 06d5ffe | 347 | // Star/unstar a repo |
| 348 | web.post("/:owner/:repo/star", requireAuth, async (c) => { | |
| 349 | const { owner: ownerName, repo: repoName } = c.req.param(); | |
| 350 | const user = c.get("user")!; | |
| 351 | ||
| 352 | try { | |
| 353 | const [ownerUser] = await db | |
| 354 | .select() | |
| 355 | .from(users) | |
| 356 | .where(eq(users.username, ownerName)) | |
| 357 | .limit(1); | |
| 358 | if (!ownerUser) return c.redirect(`/${ownerName}/${repoName}`); | |
| 359 | ||
| 360 | const [repo] = await db | |
| 361 | .select() | |
| 362 | .from(repositories) | |
| 363 | .where( | |
| 364 | and( | |
| 365 | eq(repositories.ownerId, ownerUser.id), | |
| 366 | eq(repositories.name, repoName) | |
| 367 | ) | |
| 368 | ) | |
| 369 | .limit(1); | |
| 370 | if (!repo) return c.redirect(`/${ownerName}/${repoName}`); | |
| 371 | ||
| 372 | // Toggle star | |
| 373 | const [existing] = await db | |
| 374 | .select() | |
| 375 | .from(stars) | |
| 376 | .where( | |
| 377 | and(eq(stars.userId, user.id), eq(stars.repositoryId, repo.id)) | |
| 378 | ) | |
| 379 | .limit(1); | |
| 380 | ||
| 381 | if (existing) { | |
| 382 | await db.delete(stars).where(eq(stars.id, existing.id)); | |
| 383 | await db | |
| 384 | .update(repositories) | |
| 385 | .set({ starCount: Math.max(0, repo.starCount - 1) }) | |
| 386 | .where(eq(repositories.id, repo.id)); | |
| 387 | } else { | |
| 388 | await db.insert(stars).values({ | |
| 389 | userId: user.id, | |
| 390 | repositoryId: repo.id, | |
| 391 | }); | |
| 392 | await db | |
| 393 | .update(repositories) | |
| 394 | .set({ starCount: repo.starCount + 1 }) | |
| 395 | .where(eq(repositories.id, repo.id)); | |
| 396 | } | |
| 397 | } catch { | |
| 398 | // DB error — ignore | |
| 399 | } | |
| 400 | ||
| 401 | return c.redirect(`/${ownerName}/${repoName}`); | |
| 402 | }); | |
| 403 | ||
| fc1817a | 404 | // Repository overview — file tree at HEAD |
| 405 | web.get("/:owner/:repo", async (c) => { | |
| 406 | const { owner, repo } = c.req.param(); | |
| 06d5ffe | 407 | const user = c.get("user"); |
| fc1817a | 408 | |
| 8f50ed0 | 409 | // F1 — fire-and-forget traffic tracking. Never awaits; never throws. |
| 410 | trackByName(owner, repo, "view", { | |
| 411 | userId: user?.id || null, | |
| 412 | path: `/${owner}/${repo}`, | |
| 413 | ip: c.req.header("x-forwarded-for") || c.req.header("x-real-ip") || null, | |
| 414 | userAgent: c.req.header("user-agent") || null, | |
| 415 | referer: c.req.header("referer") || null, | |
| 416 | }).catch(() => {}); | |
| 417 | ||
| fc1817a | 418 | if (!(await repoExists(owner, repo))) { |
| 419 | return c.html( | |
| 06d5ffe | 420 | <Layout title="Not Found" user={user}> |
| fc1817a | 421 | <div class="empty-state"> |
| 422 | <h2>Repository not found</h2> | |
| 423 | <p> | |
| 424 | {owner}/{repo} does not exist. | |
| 425 | </p> | |
| 426 | </div> | |
| 427 | </Layout>, | |
| 428 | 404 | |
| 429 | ); | |
| 430 | } | |
| 431 | ||
| 05b973e | 432 | // Parallelize all independent operations |
| 433 | const [defaultBranch, branches] = await Promise.all([ | |
| 434 | getDefaultBranch(owner, repo).then((b) => b || "main"), | |
| 435 | listBranches(owner, repo), | |
| 436 | ]); | |
| 437 | const [tree, starInfo] = await Promise.all([ | |
| 438 | getTree(owner, repo, defaultBranch), | |
| 439 | // Star info fetched in parallel with tree | |
| 440 | (async () => { | |
| 441 | try { | |
| 442 | const [ownerUser] = await db | |
| 443 | .select() | |
| 444 | .from(users) | |
| 445 | .where(eq(users.username, owner)) | |
| 446 | .limit(1); | |
| 71cd5ec | 447 | if (!ownerUser) |
| 448 | return { | |
| 449 | starCount: 0, | |
| 450 | starred: false, | |
| 451 | archived: false, | |
| 452 | isTemplate: false, | |
| 453 | }; | |
| 05b973e | 454 | const [repoRow] = await db |
| 455 | .select() | |
| 456 | .from(repositories) | |
| 457 | .where( | |
| 458 | and( | |
| 459 | eq(repositories.ownerId, ownerUser.id), | |
| 460 | eq(repositories.name, repo) | |
| 461 | ) | |
| 06d5ffe | 462 | ) |
| 05b973e | 463 | .limit(1); |
| 71cd5ec | 464 | if (!repoRow) |
| 465 | return { | |
| 466 | starCount: 0, | |
| 467 | starred: false, | |
| 468 | archived: false, | |
| 469 | isTemplate: false, | |
| 470 | }; | |
| 05b973e | 471 | let starred = false; |
| 06d5ffe | 472 | if (user) { |
| 473 | const [star] = await db | |
| 474 | .select() | |
| 475 | .from(stars) | |
| 476 | .where( | |
| 477 | and( | |
| 478 | eq(stars.userId, user.id), | |
| 479 | eq(stars.repositoryId, repoRow.id) | |
| 480 | ) | |
| 481 | ) | |
| 482 | .limit(1); | |
| 483 | starred = !!star; | |
| 484 | } | |
| 71cd5ec | 485 | return { |
| 486 | starCount: repoRow.starCount, | |
| 487 | starred, | |
| 488 | archived: repoRow.isArchived, | |
| 489 | isTemplate: repoRow.isTemplate, | |
| 490 | }; | |
| 05b973e | 491 | } catch { |
| 71cd5ec | 492 | return { |
| 493 | starCount: 0, | |
| 494 | starred: false, | |
| 495 | archived: false, | |
| 496 | isTemplate: false, | |
| 497 | }; | |
| 06d5ffe | 498 | } |
| 05b973e | 499 | })(), |
| 500 | ]); | |
| 71cd5ec | 501 | const { starCount, starred, archived, isTemplate } = starInfo; |
| 06d5ffe | 502 | |
| fc1817a | 503 | if (tree.length === 0) { |
| 504 | return c.html( | |
| 06d5ffe | 505 | <Layout title={`${owner}/${repo}`} user={user}> |
| 506 | <RepoHeader | |
| 507 | owner={owner} | |
| 508 | repo={repo} | |
| 509 | starCount={starCount} | |
| 510 | starred={starred} | |
| 511 | currentUser={user?.username} | |
| 71cd5ec | 512 | archived={archived} |
| 513 | isTemplate={isTemplate} | |
| 06d5ffe | 514 | /> |
| fc1817a | 515 | <RepoNav owner={owner} repo={repo} active="code" /> |
| 516 | <div class="empty-state"> | |
| 517 | <h2>Empty repository</h2> | |
| 518 | <p>Get started by pushing code:</p> | |
| 519 | <pre>{`git remote add gluecron http://localhost:3000/${owner}/${repo}.git | |
| 520 | git push -u gluecron main`}</pre> | |
| 521 | </div> | |
| 522 | </Layout> | |
| 523 | ); | |
| 524 | } | |
| 525 | ||
| 526 | const readme = await getReadme(owner, repo, defaultBranch); | |
| 527 | ||
| 528 | return c.html( | |
| 06d5ffe | 529 | <Layout title={`${owner}/${repo}`} user={user}> |
| 530 | <RepoHeader | |
| 531 | owner={owner} | |
| 532 | repo={repo} | |
| 533 | starCount={starCount} | |
| 534 | starred={starred} | |
| 535 | currentUser={user?.username} | |
| 71cd5ec | 536 | archived={archived} |
| 537 | isTemplate={isTemplate} | |
| 06d5ffe | 538 | /> |
| 71cd5ec | 539 | {isTemplate && user && user.username !== owner && ( |
| 540 | <div | |
| 541 | class="panel" | |
| 542 | style="margin-bottom:16px;padding:12px;display:flex;align-items:center;justify-content:space-between;gap:12px" | |
| 543 | > | |
| 544 | <div style="font-size:13px"> | |
| 545 | <strong>Template repository.</strong> Create a new repository from | |
| 546 | this template's files. | |
| 547 | </div> | |
| 548 | <form | |
| 9837657 | 549 | method="post" |
| 71cd5ec | 550 | action={`/${owner}/${repo}/use-template`} |
| 551 | style="display:flex;gap:8px;align-items:center" | |
| 552 | > | |
| 553 | <input | |
| 554 | type="text" | |
| 555 | name="name" | |
| 556 | placeholder="new-repo-name" | |
| 557 | required | |
| 558 | style="width:200px" | |
| 559 | /> | |
| 560 | <button type="submit" class="btn btn-primary"> | |
| 561 | Use this template | |
| 562 | </button> | |
| 563 | </form> | |
| 564 | </div> | |
| 565 | )} | |
| fc1817a | 566 | <RepoNav owner={owner} repo={repo} active="code" /> |
| 06d5ffe | 567 | <BranchSwitcher |
| 568 | owner={owner} | |
| 569 | repo={repo} | |
| 570 | currentRef={defaultBranch} | |
| 571 | branches={branches} | |
| 572 | pathType="tree" | |
| 573 | /> | |
| fc1817a | 574 | <FileTable |
| 575 | entries={tree} | |
| 576 | owner={owner} | |
| 577 | repo={repo} | |
| 578 | ref={defaultBranch} | |
| 579 | path="" | |
| 580 | /> | |
| 79136bb | 581 | {readme && (() => { |
| 582 | const readmeHtml = renderMarkdown(readme); | |
| 583 | return ( | |
| 584 | <div class="blob-view" style="margin-top: 20px"> | |
| 585 | <div class="blob-header">README.md</div> | |
| 586 | <style>{markdownCss}</style> | |
| 587 | <div class="markdown-body"> | |
| 588 | {html([readmeHtml] as unknown as TemplateStringsArray)} | |
| 589 | </div> | |
| fc1817a | 590 | </div> |
| 79136bb | 591 | ); |
| 592 | })()} | |
| fc1817a | 593 | </Layout> |
| 594 | ); | |
| 595 | }); | |
| 596 | ||
| 597 | // Browse tree at ref/path | |
| 598 | web.get("/:owner/:repo/tree/:ref{.+$}", async (c) => { | |
| 599 | const { owner, repo } = c.req.param(); | |
| 06d5ffe | 600 | const user = c.get("user"); |
| fc1817a | 601 | const refAndPath = c.req.param("ref"); |
| 602 | ||
| 603 | const branches = await listBranches(owner, repo); | |
| 604 | let ref = ""; | |
| 605 | let treePath = ""; | |
| 606 | ||
| 607 | for (const branch of branches) { | |
| 608 | if (refAndPath === branch || refAndPath.startsWith(branch + "/")) { | |
| 609 | ref = branch; | |
| 610 | treePath = refAndPath.slice(branch.length + 1); | |
| 611 | break; | |
| 612 | } | |
| 613 | } | |
| 614 | ||
| 615 | if (!ref) { | |
| 616 | const slashIdx = refAndPath.indexOf("/"); | |
| 617 | if (slashIdx === -1) { | |
| 618 | ref = refAndPath; | |
| 619 | } else { | |
| 620 | ref = refAndPath.slice(0, slashIdx); | |
| 621 | treePath = refAndPath.slice(slashIdx + 1); | |
| 622 | } | |
| 623 | } | |
| 624 | ||
| 625 | const tree = await getTree(owner, repo, ref, treePath); | |
| 626 | ||
| 627 | return c.html( | |
| 06d5ffe | 628 | <Layout title={`${treePath || "/"} — ${owner}/${repo}`} user={user}> |
| fc1817a | 629 | <RepoHeader owner={owner} repo={repo} /> |
| 630 | <RepoNav owner={owner} repo={repo} active="code" /> | |
| 06d5ffe | 631 | <BranchSwitcher |
| 632 | owner={owner} | |
| 633 | repo={repo} | |
| 634 | currentRef={ref} | |
| 635 | branches={branches} | |
| 636 | pathType="tree" | |
| 637 | subPath={treePath} | |
| 638 | /> | |
| fc1817a | 639 | <Breadcrumb owner={owner} repo={repo} ref={ref} path={treePath} /> |
| 640 | <FileTable | |
| 641 | entries={tree} | |
| 642 | owner={owner} | |
| 643 | repo={repo} | |
| 644 | ref={ref} | |
| 645 | path={treePath} | |
| 646 | /> | |
| 647 | </Layout> | |
| 648 | ); | |
| 649 | }); | |
| 650 | ||
| 06d5ffe | 651 | // View file blob with syntax highlighting |
| fc1817a | 652 | web.get("/:owner/:repo/blob/:ref{.+$}", async (c) => { |
| 653 | const { owner, repo } = c.req.param(); | |
| 06d5ffe | 654 | const user = c.get("user"); |
| fc1817a | 655 | const refAndPath = c.req.param("ref"); |
| 656 | ||
| 657 | const branches = await listBranches(owner, repo); | |
| 658 | let ref = ""; | |
| 659 | let filePath = ""; | |
| 660 | ||
| 661 | for (const branch of branches) { | |
| 662 | if (refAndPath.startsWith(branch + "/")) { | |
| 663 | ref = branch; | |
| 664 | filePath = refAndPath.slice(branch.length + 1); | |
| 665 | break; | |
| 666 | } | |
| 667 | } | |
| 668 | ||
| 669 | if (!ref) { | |
| 670 | const slashIdx = refAndPath.indexOf("/"); | |
| 671 | if (slashIdx === -1) return c.text("Not found", 404); | |
| 672 | ref = refAndPath.slice(0, slashIdx); | |
| 673 | filePath = refAndPath.slice(slashIdx + 1); | |
| 674 | } | |
| 675 | ||
| 676 | const blob = await getBlob(owner, repo, ref, filePath); | |
| 677 | if (!blob) { | |
| 678 | return c.html( | |
| 06d5ffe | 679 | <Layout title="Not Found" user={user}> |
| fc1817a | 680 | <div class="empty-state"> |
| 681 | <h2>File not found</h2> | |
| 682 | </div> | |
| 683 | </Layout>, | |
| 684 | 404 | |
| 685 | ); | |
| 686 | } | |
| 687 | ||
| 06d5ffe | 688 | const fileName = filePath.split("/").pop() || filePath; |
| fc1817a | 689 | |
| 690 | return c.html( | |
| 06d5ffe | 691 | <Layout title={`${filePath} — ${owner}/${repo}`} user={user}> |
| fc1817a | 692 | <RepoHeader owner={owner} repo={repo} /> |
| 693 | <RepoNav owner={owner} repo={repo} active="code" /> | |
| 06d5ffe | 694 | <BranchSwitcher |
| 695 | owner={owner} | |
| 696 | repo={repo} | |
| 697 | currentRef={ref} | |
| 698 | branches={branches} | |
| 699 | pathType="blob" | |
| 700 | subPath={filePath} | |
| 701 | /> | |
| fc1817a | 702 | <Breadcrumb owner={owner} repo={repo} ref={ref} path={filePath} /> |
| 703 | <div class="blob-view"> | |
| 704 | <div class="blob-header"> | |
| 06d5ffe | 705 | <span>{fileName} — {blob.size} bytes</span> |
| 79136bb | 706 | <span style="display: flex; gap: 12px"> |
| 707 | <a href={`/${owner}/${repo}/raw/${ref}/${filePath}`} style="font-size: 12px"> | |
| 708 | Raw | |
| 709 | </a> | |
| 710 | <a href={`/${owner}/${repo}/blame/${ref}/${filePath}`} style="font-size: 12px"> | |
| 711 | Blame | |
| 712 | </a> | |
| 0074234 | 713 | {user && ( |
| 714 | <a href={`/${owner}/${repo}/edit/${ref}/${filePath}`} style="font-size: 12px"> | |
| 715 | Edit | |
| 716 | </a> | |
| 717 | )} | |
| 79136bb | 718 | </span> |
| fc1817a | 719 | </div> |
| 720 | {blob.isBinary ? ( | |
| 721 | <div style="padding: 16px; color: var(--text-muted)"> | |
| 722 | Binary file not shown. | |
| 723 | </div> | |
| 06d5ffe | 724 | ) : (() => { |
| 725 | const { html: highlighted, language } = highlightCode( | |
| 726 | blob.content, | |
| 727 | fileName | |
| 728 | ); | |
| 729 | const lineCount = blob.content.split("\n").length; | |
| 730 | // Trim trailing newline from count | |
| 731 | const adjustedCount = | |
| 732 | blob.content.endsWith("\n") ? lineCount - 1 : lineCount; | |
| 733 | ||
| 734 | if (language) { | |
| 735 | return ( | |
| 736 | <HighlightedCode | |
| 737 | highlightedHtml={highlighted} | |
| 738 | lineCount={adjustedCount} | |
| 739 | /> | |
| 740 | ); | |
| 741 | } | |
| 742 | const lines = blob.content.split("\n"); | |
| 743 | if (lines[lines.length - 1] === "") lines.pop(); | |
| 744 | return <PlainCode lines={lines} />; | |
| 745 | })()} | |
| fc1817a | 746 | </div> |
| 747 | </Layout> | |
| 748 | ); | |
| 749 | }); | |
| 750 | ||
| 751 | // Commit log | |
| 752 | web.get("/:owner/:repo/commits/:ref?", async (c) => { | |
| 753 | const { owner, repo } = c.req.param(); | |
| 06d5ffe | 754 | const user = c.get("user"); |
| fc1817a | 755 | const ref = |
| 756 | c.req.param("ref") || (await getDefaultBranch(owner, repo)) || "main"; | |
| 06d5ffe | 757 | const branches = await listBranches(owner, repo); |
| fc1817a | 758 | |
| 759 | const commits = await listCommits(owner, repo, ref, 50); | |
| 760 | ||
| 3951454 | 761 | // Block J3 — batch-fetch cached verification results for the page. |
| 762 | let verifications: Record<string, { verified: boolean; reason: string }> = {}; | |
| 763 | try { | |
| 764 | const [ownerRow] = await db | |
| 765 | .select() | |
| 766 | .from(users) | |
| 767 | .where(eq(users.username, owner)) | |
| 768 | .limit(1); | |
| 769 | if (ownerRow) { | |
| 770 | const [repoRow] = await db | |
| 771 | .select() | |
| 772 | .from(repositories) | |
| 773 | .where( | |
| 774 | and( | |
| 775 | eq(repositories.ownerId, ownerRow.id), | |
| 776 | eq(repositories.name, repo) | |
| 777 | ) | |
| 778 | ) | |
| 779 | .limit(1); | |
| 780 | if (repoRow && commits.length > 0) { | |
| 781 | const rows = await db | |
| 782 | .select() | |
| 783 | .from(commitVerifications) | |
| 784 | .where( | |
| 785 | and( | |
| 786 | eq(commitVerifications.repositoryId, repoRow.id), | |
| 787 | inArray( | |
| 788 | commitVerifications.commitSha, | |
| 789 | commits.map((c) => c.sha) | |
| 790 | ) | |
| 791 | ) | |
| 792 | ); | |
| 793 | for (const r of rows) { | |
| 794 | verifications[r.commitSha] = { | |
| 795 | verified: r.verified, | |
| 796 | reason: r.reason, | |
| 797 | }; | |
| 798 | } | |
| 799 | } | |
| 800 | } | |
| 801 | } catch { | |
| 802 | // DB unavailable — skip the badges gracefully. | |
| 803 | } | |
| 804 | ||
| fc1817a | 805 | return c.html( |
| 06d5ffe | 806 | <Layout title={`Commits — ${owner}/${repo}`} user={user}> |
| fc1817a | 807 | <RepoHeader owner={owner} repo={repo} /> |
| 808 | <RepoNav owner={owner} repo={repo} active="commits" /> | |
| 06d5ffe | 809 | <BranchSwitcher |
| 810 | owner={owner} | |
| 811 | repo={repo} | |
| 812 | currentRef={ref} | |
| 813 | branches={branches} | |
| 814 | pathType="commits" | |
| 815 | /> | |
| fc1817a | 816 | {commits.length === 0 ? ( |
| 817 | <div class="empty-state"> | |
| 818 | <p>No commits yet.</p> | |
| 819 | </div> | |
| 820 | ) : ( | |
| 3951454 | 821 | <CommitList |
| 822 | commits={commits} | |
| 823 | owner={owner} | |
| 824 | repo={repo} | |
| 825 | verifications={verifications} | |
| 826 | /> | |
| fc1817a | 827 | )} |
| 828 | </Layout> | |
| 829 | ); | |
| 830 | }); | |
| 831 | ||
| 832 | // Single commit with diff | |
| 833 | web.get("/:owner/:repo/commit/:sha", async (c) => { | |
| 834 | const { owner, repo, sha } = c.req.param(); | |
| 06d5ffe | 835 | const user = c.get("user"); |
| fc1817a | 836 | |
| 05b973e | 837 | // Fetch commit, full message, and diff in parallel |
| 838 | const [commit, fullMessage, diffResult] = await Promise.all([ | |
| 839 | getCommit(owner, repo, sha), | |
| 840 | getCommitFullMessage(owner, repo, sha), | |
| 841 | getDiff(owner, repo, sha), | |
| 842 | ]); | |
| fc1817a | 843 | if (!commit) { |
| 844 | return c.html( | |
| 06d5ffe | 845 | <Layout title="Not Found" user={user}> |
| fc1817a | 846 | <div class="empty-state"> |
| 847 | <h2>Commit not found</h2> | |
| 848 | </div> | |
| 849 | </Layout>, | |
| 850 | 404 | |
| 851 | ); | |
| 852 | } | |
| 853 | ||
| 3951454 | 854 | // Block J3 — try to verify this commit's signature. |
| 855 | let verification: | |
| 856 | | { verified: boolean; reason: string; signatureType: string | null } | |
| 857 | | null = null; | |
| 0cdfd89 | 858 | // Block J8 — external CI commit statuses rollup. |
| 859 | let statusCombined: | |
| 860 | | { | |
| 861 | state: "pending" | "success" | "failure"; | |
| 862 | total: number; | |
| 863 | contexts: Array<{ | |
| 864 | context: string; | |
| 865 | state: string; | |
| 866 | description: string | null; | |
| 867 | targetUrl: string | null; | |
| 868 | }>; | |
| 869 | } | |
| 870 | | null = null; | |
| 3951454 | 871 | try { |
| 872 | const [ownerRow] = await db | |
| 873 | .select() | |
| 874 | .from(users) | |
| 875 | .where(eq(users.username, owner)) | |
| 876 | .limit(1); | |
| 877 | if (ownerRow) { | |
| 878 | const [repoRow] = await db | |
| 879 | .select() | |
| 880 | .from(repositories) | |
| 881 | .where( | |
| 882 | and( | |
| 883 | eq(repositories.ownerId, ownerRow.id), | |
| 884 | eq(repositories.name, repo) | |
| 885 | ) | |
| 886 | ) | |
| 887 | .limit(1); | |
| 888 | if (repoRow) { | |
| 889 | const { verifyCommit } = await import("../lib/signatures"); | |
| 890 | const v = await verifyCommit(repoRow.id, owner, repo, commit.sha); | |
| 891 | verification = { | |
| 892 | verified: v.verified, | |
| 893 | reason: v.reason, | |
| 894 | signatureType: v.signatureType, | |
| 895 | }; | |
| 0cdfd89 | 896 | try { |
| 897 | const { combinedStatus } = await import("../lib/commit-statuses"); | |
| 898 | const combined = await combinedStatus(repoRow.id, commit.sha); | |
| 899 | if (combined.total > 0) { | |
| 900 | statusCombined = { | |
| 901 | state: combined.state as any, | |
| 902 | total: combined.total, | |
| 903 | contexts: combined.contexts.map((c) => ({ | |
| 904 | context: c.context, | |
| 905 | state: c.state, | |
| 906 | description: c.description, | |
| 907 | targetUrl: c.targetUrl, | |
| 908 | })), | |
| 909 | }; | |
| 910 | } | |
| 911 | } catch { | |
| 912 | statusCombined = null; | |
| 913 | } | |
| 3951454 | 914 | } |
| 915 | } | |
| 916 | } catch { | |
| 917 | verification = null; | |
| 918 | } | |
| 919 | ||
| 05b973e | 920 | const { files, raw } = diffResult; |
| fc1817a | 921 | |
| 922 | return c.html( | |
| 06d5ffe | 923 | <Layout title={`${commit.message} — ${owner}/${repo}`} user={user}> |
| fc1817a | 924 | <RepoHeader owner={owner} repo={repo} /> |
| 925 | <div | |
| 926 | style="background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 20px" | |
| 927 | > | |
| 928 | <div style="font-size: 18px; font-weight: 600; margin-bottom: 8px"> | |
| 929 | {commit.message} | |
| 930 | </div> | |
| 931 | {fullMessage !== commit.message && ( | |
| 932 | <div style="white-space: pre-wrap; color: var(--text-muted); font-size: 14px; margin-bottom: 12px"> | |
| 933 | {fullMessage} | |
| 934 | </div> | |
| 935 | )} | |
| 936 | <div style="font-size: 13px; color: var(--text-muted)"> | |
| 937 | <strong style="color: var(--text)">{commit.author}</strong>{" "} | |
| 938 | committed on{" "} | |
| 939 | {new Date(commit.date).toLocaleDateString("en-US", { | |
| 940 | month: "long", | |
| 941 | day: "numeric", | |
| 942 | year: "numeric", | |
| 943 | })} | |
| 3951454 | 944 | {verification && verification.reason !== "unsigned" && ( |
| 945 | <span | |
| 946 | style={`margin-left:10px;font-size:10px;padding:1px 6px;border-radius:3px;text-transform:uppercase;letter-spacing:.4px;color:#fff;background:${ | |
| 947 | verification.verified | |
| 948 | ? "var(--green,#2ea043)" | |
| 949 | : "var(--yellow,#d29922)" | |
| 950 | }`} | |
| 951 | title={`${verification.signatureType?.toUpperCase() || ""} · ${verification.reason}`} | |
| 952 | > | |
| 953 | {verification.verified ? "Verified" : verification.reason} | |
| 954 | </span> | |
| 955 | )} | |
| fc1817a | 956 | </div> |
| 957 | <div style="margin-top: 8px"> | |
| 958 | <span class="commit-sha">{commit.sha}</span> | |
| 959 | {commit.parentShas.length > 0 && ( | |
| 960 | <span style="margin-left: 12px; font-size: 13px; color: var(--text-muted)"> | |
| 961 | Parent:{" "} | |
| 962 | {commit.parentShas.map((p) => ( | |
| 963 | <a | |
| 964 | href={`/${owner}/${repo}/commit/${p}`} | |
| 965 | class="commit-sha" | |
| 966 | style="margin-left: 4px" | |
| 967 | > | |
| 968 | {p.slice(0, 7)} | |
| 969 | </a> | |
| 970 | ))} | |
| 971 | </span> | |
| 972 | )} | |
| 973 | </div> | |
| 0cdfd89 | 974 | {statusCombined && ( |
| 975 | <div style="margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 13px"> | |
| 976 | <strong style="color: var(--text)">Checks</strong> | |
| 977 | <span style="margin-left: 8px; color: var(--text-muted)"> | |
| 978 | {statusCombined.total} total —{" "} | |
| 979 | <span | |
| 980 | style={`color:${ | |
| 981 | statusCombined.state === "success" | |
| 982 | ? "var(--green,#2ea043)" | |
| 983 | : statusCombined.state === "failure" | |
| 984 | ? "var(--red,#da3633)" | |
| 985 | : "var(--yellow,#d29922)" | |
| 986 | }`} | |
| 987 | > | |
| 988 | {statusCombined.state} | |
| 989 | </span> | |
| 990 | </span> | |
| 991 | <div style="margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px"> | |
| 992 | {statusCombined.contexts.map((cx) => ( | |
| 993 | <span | |
| 994 | style={`font-size:11px;padding:2px 6px;border-radius:3px;color:#fff;background:${ | |
| 995 | cx.state === "success" | |
| 996 | ? "var(--green,#2ea043)" | |
| 997 | : cx.state === "pending" | |
| 998 | ? "var(--yellow,#d29922)" | |
| 999 | : "var(--red,#da3633)" | |
| 1000 | }`} | |
| 1001 | title={cx.description || cx.context} | |
| 1002 | > | |
| 1003 | {cx.targetUrl ? ( | |
| 1004 | <a | |
| 1005 | href={cx.targetUrl} | |
| 1006 | style="color: inherit; text-decoration: none" | |
| 1007 | rel="noopener" | |
| 1008 | > | |
| 1009 | {cx.context}: {cx.state} | |
| 1010 | </a> | |
| 1011 | ) : ( | |
| 1012 | <> | |
| 1013 | {cx.context}: {cx.state} | |
| 1014 | </> | |
| 1015 | )} | |
| 1016 | </span> | |
| 1017 | ))} | |
| 1018 | </div> | |
| 1019 | </div> | |
| 1020 | )} | |
| fc1817a | 1021 | </div> |
| 1022 | <DiffView raw={raw} files={files} /> | |
| 1023 | </Layout> | |
| 1024 | ); | |
| 1025 | }); | |
| 1026 | ||
| 79136bb | 1027 | // Raw file download |
| 1028 | web.get("/:owner/:repo/raw/:ref{.+$}", async (c) => { | |
| 1029 | const { owner, repo } = c.req.param(); | |
| 1030 | const refAndPath = c.req.param("ref"); | |
| 1031 | ||
| 1032 | const branches = await listBranches(owner, repo); | |
| 1033 | let ref = ""; | |
| 1034 | let filePath = ""; | |
| 1035 | ||
| 1036 | for (const branch of branches) { | |
| 1037 | if (refAndPath.startsWith(branch + "/")) { | |
| 1038 | ref = branch; | |
| 1039 | filePath = refAndPath.slice(branch.length + 1); | |
| 1040 | break; | |
| 1041 | } | |
| 1042 | } | |
| 1043 | ||
| 1044 | if (!ref) { | |
| 1045 | const slashIdx = refAndPath.indexOf("/"); | |
| 1046 | if (slashIdx === -1) return c.text("Not found", 404); | |
| 1047 | ref = refAndPath.slice(0, slashIdx); | |
| 1048 | filePath = refAndPath.slice(slashIdx + 1); | |
| 1049 | } | |
| 1050 | ||
| 1051 | const data = await getRawBlob(owner, repo, ref, filePath); | |
| 1052 | if (!data) return c.text("Not found", 404); | |
| 1053 | ||
| 1054 | const fileName = filePath.split("/").pop() || "file"; | |
| 1055 | return new Response(data, { | |
| 1056 | headers: { | |
| 1057 | "Content-Type": "application/octet-stream", | |
| 1058 | "Content-Disposition": `attachment; filename="${fileName}"`, | |
| 05b973e | 1059 | "Cache-Control": "public, max-age=300, stale-while-revalidate=60", |
| 79136bb | 1060 | }, |
| 1061 | }); | |
| 1062 | }); | |
| 1063 | ||
| 1064 | // Blame view | |
| 1065 | web.get("/:owner/:repo/blame/:ref{.+$}", async (c) => { | |
| 1066 | const { owner, repo } = c.req.param(); | |
| 1067 | const user = c.get("user"); | |
| 1068 | const refAndPath = c.req.param("ref"); | |
| 1069 | ||
| 1070 | const branches = await listBranches(owner, repo); | |
| 1071 | let ref = ""; | |
| 1072 | let filePath = ""; | |
| 1073 | ||
| 1074 | for (const branch of branches) { | |
| 1075 | if (refAndPath.startsWith(branch + "/")) { | |
| 1076 | ref = branch; | |
| 1077 | filePath = refAndPath.slice(branch.length + 1); | |
| 1078 | break; | |
| 1079 | } | |
| 1080 | } | |
| 1081 | ||
| 1082 | if (!ref) { | |
| 1083 | const slashIdx = refAndPath.indexOf("/"); | |
| 1084 | if (slashIdx === -1) return c.text("Not found", 404); | |
| 1085 | ref = refAndPath.slice(0, slashIdx); | |
| 1086 | filePath = refAndPath.slice(slashIdx + 1); | |
| 1087 | } | |
| 1088 | ||
| 1089 | const blameLines = await getBlame(owner, repo, ref, filePath); | |
| 1090 | if (blameLines.length === 0) { | |
| 1091 | return c.html( | |
| 1092 | <Layout title="Not Found" user={user}> | |
| 1093 | <div class="empty-state"> | |
| 1094 | <h2>File not found</h2> | |
| 1095 | </div> | |
| 1096 | </Layout>, | |
| 1097 | 404 | |
| 1098 | ); | |
| 1099 | } | |
| 1100 | ||
| 1101 | const fileName = filePath.split("/").pop() || filePath; | |
| 1102 | ||
| 1103 | return c.html( | |
| 1104 | <Layout title={`Blame: ${filePath} — ${owner}/${repo}`} user={user}> | |
| 1105 | <RepoHeader owner={owner} repo={repo} /> | |
| 1106 | <RepoNav owner={owner} repo={repo} active="code" /> | |
| 1107 | <Breadcrumb owner={owner} repo={repo} ref={ref} path={filePath} /> | |
| 1108 | <div class="blob-view"> | |
| 1109 | <div class="blob-header"> | |
| 1110 | <span>{fileName} — blame</span> | |
| 1111 | <a href={`/${owner}/${repo}/blob/${ref}/${filePath}`} style="font-size: 12px"> | |
| 1112 | Normal view | |
| 1113 | </a> | |
| 1114 | </div> | |
| 1115 | <div class="blob-code" style="overflow-x: auto"> | |
| 1116 | <table style="width: 100%; border-collapse: collapse; font-size: 13px; font-family: var(--font-mono)"> | |
| 1117 | <tbody> | |
| 1118 | {blameLines.map((line, i) => { | |
| 1119 | const showInfo = | |
| 1120 | i === 0 || blameLines[i - 1].sha !== line.sha; | |
| 1121 | return ( | |
| 1122 | <tr style="border-bottom: 1px solid var(--border)"> | |
| 1123 | <td | |
| 1124 | style={`width: 200px; padding: 0 8px; font-size: 11px; color: var(--text-muted); white-space: nowrap; vertical-align: top; ${showInfo ? "border-top: 1px solid var(--border)" : ""}`} | |
| 1125 | > | |
| 1126 | {showInfo && ( | |
| 1127 | <> | |
| 1128 | <a | |
| 1129 | href={`/${owner}/${repo}/commit/${line.sha}`} | |
| 1130 | style="color: var(--text-link); font-family: var(--font-mono)" | |
| 1131 | > | |
| 1132 | {line.sha.slice(0, 7)} | |
| 1133 | </a>{" "} | |
| 1134 | <span>{line.author}</span> | |
| 1135 | </> | |
| 1136 | )} | |
| 1137 | </td> | |
| 1138 | <td class="line-num">{line.lineNum}</td> | |
| 1139 | <td class="line-content">{line.content}</td> | |
| 1140 | </tr> | |
| 1141 | ); | |
| 1142 | })} | |
| 1143 | </tbody> | |
| 1144 | </table> | |
| 1145 | </div> | |
| 1146 | </div> | |
| 1147 | </Layout> | |
| 1148 | ); | |
| 1149 | }); | |
| 1150 | ||
| 1151 | // Search | |
| 1152 | web.get("/:owner/:repo/search", async (c) => { | |
| 1153 | const { owner, repo } = c.req.param(); | |
| 1154 | const user = c.get("user"); | |
| 1155 | const q = c.req.query("q") || ""; | |
| 1156 | ||
| 1157 | if (!(await repoExists(owner, repo))) return c.notFound(); | |
| 1158 | ||
| 1159 | const defaultBranch = (await getDefaultBranch(owner, repo)) || "main"; | |
| 1160 | let results: Array<{ file: string; lineNum: number; line: string }> = []; | |
| 1161 | ||
| 1162 | if (q.trim()) { | |
| 1163 | results = await searchCode(owner, repo, defaultBranch, q.trim()); | |
| 1164 | } | |
| 1165 | ||
| 1166 | return c.html( | |
| 1167 | <Layout title={`Search — ${owner}/${repo}`} user={user}> | |
| 1168 | <RepoHeader owner={owner} repo={repo} /> | |
| 1169 | <RepoNav owner={owner} repo={repo} active="code" /> | |
| 1170 | <form | |
| 9837657 | 1171 | method="get" |
| 79136bb | 1172 | action={`/${owner}/${repo}/search`} |
| 1173 | style="margin-bottom: 20px" | |
| 1174 | > | |
| 1175 | <div style="display: flex; gap: 8px"> | |
| 1176 | <input | |
| 1177 | type="text" | |
| 1178 | name="q" | |
| 1179 | value={q} | |
| 1180 | placeholder="Search code..." | |
| 1181 | style="flex: 1; padding: 8px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 14px" | |
| 1182 | /> | |
| 1183 | <button type="submit" class="btn btn-primary"> | |
| 1184 | Search | |
| 1185 | </button> | |
| 1186 | </div> | |
| 1187 | </form> | |
| 1188 | {q && ( | |
| 1189 | <p style="font-size: 14px; color: var(--text-muted); margin-bottom: 16px"> | |
| 1190 | {results.length} result{results.length !== 1 ? "s" : ""} for{" "} | |
| 1191 | <strong style="color: var(--text)">"{q}"</strong> | |
| 1192 | </p> | |
| 1193 | )} | |
| 1194 | {results.length > 0 && ( | |
| 1195 | <div class="search-results"> | |
| 1196 | {(() => { | |
| 1197 | // Group by file | |
| 1198 | const grouped: Record< | |
| 1199 | string, | |
| 1200 | Array<{ lineNum: number; line: string }> | |
| 1201 | > = {}; | |
| 1202 | for (const r of results) { | |
| 1203 | if (!grouped[r.file]) grouped[r.file] = []; | |
| 1204 | grouped[r.file].push({ lineNum: r.lineNum, line: r.line }); | |
| 1205 | } | |
| 1206 | return Object.entries(grouped).map(([file, matches]) => ( | |
| 1207 | <div class="diff-file" style="margin-bottom: 12px"> | |
| 1208 | <div class="diff-file-header"> | |
| 1209 | <a | |
| 1210 | href={`/${owner}/${repo}/blob/${defaultBranch}/${file}`} | |
| 1211 | > | |
| 1212 | {file} | |
| 1213 | </a> | |
| 1214 | </div> | |
| 1215 | <div class="blob-code"> | |
| 1216 | <table> | |
| 1217 | <tbody> | |
| 1218 | {matches.map((m) => ( | |
| 1219 | <tr> | |
| 1220 | <td class="line-num">{m.lineNum}</td> | |
| 1221 | <td class="line-content">{m.line}</td> | |
| 1222 | </tr> | |
| 1223 | ))} | |
| 1224 | </tbody> | |
| 1225 | </table> | |
| 1226 | </div> | |
| 1227 | </div> | |
| 1228 | )); | |
| 1229 | })()} | |
| 1230 | </div> | |
| 1231 | )} | |
| 1232 | </Layout> | |
| 1233 | ); | |
| 1234 | }); | |
| 1235 | ||
| fc1817a | 1236 | export default web; |