Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesPull RequestsActionsSecurityInsightsSettings
✨ AI
More
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.

web.tsxBlame1239 lines · 1 contributor
fc1817aClaude1/**
2 * Web UI routes — browse repositories, code, commits, diffs.
06d5ffeClaude3 * Now auth-aware with user profiles, repo creation, stars, and syntax highlighting.
fc1817aClaude4 */
5
6import { Hono } from "hono";
79136bbClaude7import { html } from "hono/html";
3951454Claude8import { eq, and, desc, inArray } from "drizzle-orm";
06d5ffeClaude9import { db } from "../db";
3951454Claude10import {
11 users,
12 repositories,
13 stars,
14 commitVerifications,
15} from "../db/schema";
fc1817aClaude16import { Layout } from "../views/layout";
17import {
18 RepoHeader,
19 RepoNav,
20 Breadcrumb,
21 FileTable,
22 CommitList,
23 DiffView,
06d5ffeClaude24 RepoCard,
25 BranchSwitcher,
26 HighlightedCode,
27 PlainCode,
fc1817aClaude28} from "../views/components";
29import {
30 getTree,
31 getBlob,
32 listCommits,
33 getCommit,
34 getCommitFullMessage,
35 getDiff,
36 getReadme,
37 getDefaultBranch,
38 listBranches,
39 repoExists,
06d5ffeClaude40 initBareRepo,
79136bbClaude41 getBlame,
42 getRawBlob,
43 searchCode,
fc1817aClaude44} from "../git/repository";
79136bbClaude45import { renderMarkdown, markdownCss } from "../lib/markdown";
06d5ffeClaude46import { highlightCode } from "../lib/highlight";
47import { softAuth, requireAuth } from "../middleware/auth";
48import type { AuthEnv } from "../middleware/auth";
8f50ed0Claude49import { trackByName } from "../lib/traffic";
fc1817aClaude50
06d5ffeClaude51const web = new Hono<AuthEnv>();
52
53// Soft auth on all web routes — c.get("user") available but may be null
54web.use("*", softAuth);
fc1817aClaude55
56// Home page
06d5ffeClaude57web.get("/", async (c) => {
58 const user = c.get("user");
59
60 if (user) {
3ef4c9dClaude61 const { renderDashboard } = await import("./dashboard");
62 return renderDashboard(c);
06d5ffeClaude63 }
64
fc1817aClaude65 return c.html(
06d5ffeClaude66 <Layout user={null}>
fc1817aClaude67 <div class="empty-state">
68 <h2>gluecron</h2>
69 <p>AI-native code intelligence platform</p>
06d5ffeClaude70 <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
fc1817aClaude79curl -X POST http://localhost:3000/api/setup \\
80 -H 'Content-Type: application/json' \\
81 -d '{"username":"you","email":"you@dev.com","repoName":"hello"}'
82
83git remote add gluecron http://localhost:3000/you/hello.git
84git push gluecron main`}</pre>
85 </div>
86 </Layout>
87 );
88});
89
06d5ffeClaude90// New repository form
91web.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>}
001af43Claude100 <form method="post" action="/new">
06d5ffeClaude101 <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
147web.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
3ef4c9dClaude168 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 }
06d5ffeClaude187
188 return c.redirect(`/${user.username}/${name}`);
189});
190
191// User profile
fc1817aClaude192web.get("/:owner", async (c) => {
06d5ffeClaude193 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
7aa8b99Claude234 // 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
d412586Claude255 // 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
fc1817aClaude275 return c.html(
06d5ffeClaude276 <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>}
7aa8b99Claude285 <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
001af43Claude308 method="post"
7aa8b99Claude309 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>
06d5ffeClaude324 </div>
325 </div>
d412586Claude326 {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 )}
06d5ffeClaude333 <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 )}
fc1817aClaude343 </Layout>
344 );
345});
346
06d5ffeClaude347// Star/unstar a repo
348web.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
fc1817aClaude404// Repository overview — file tree at HEAD
405web.get("/:owner/:repo", async (c) => {
406 const { owner, repo } = c.req.param();
06d5ffeClaude407 const user = c.get("user");
fc1817aClaude408
8f50ed0Claude409 // 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
fc1817aClaude418 if (!(await repoExists(owner, repo))) {
419 return c.html(
06d5ffeClaude420 <Layout title="Not Found" user={user}>
fc1817aClaude421 <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
05b973eClaude432 // 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);
71cd5ecClaude447 if (!ownerUser)
448 return {
449 starCount: 0,
450 starred: false,
451 archived: false,
452 isTemplate: false,
453 };
05b973eClaude454 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 )
06d5ffeClaude462 )
05b973eClaude463 .limit(1);
71cd5ecClaude464 if (!repoRow)
465 return {
466 starCount: 0,
467 starred: false,
468 archived: false,
469 isTemplate: false,
470 };
05b973eClaude471 let starred = false;
06d5ffeClaude472 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 }
71cd5ecClaude485 return {
486 starCount: repoRow.starCount,
487 starred,
488 archived: repoRow.isArchived,
489 isTemplate: repoRow.isTemplate,
490 };
05b973eClaude491 } catch {
71cd5ecClaude492 return {
493 starCount: 0,
494 starred: false,
495 archived: false,
496 isTemplate: false,
497 };
06d5ffeClaude498 }
05b973eClaude499 })(),
500 ]);
71cd5ecClaude501 const { starCount, starred, archived, isTemplate } = starInfo;
06d5ffeClaude502
fc1817aClaude503 if (tree.length === 0) {
504 return c.html(
06d5ffeClaude505 <Layout title={`${owner}/${repo}`} user={user}>
506 <RepoHeader
507 owner={owner}
508 repo={repo}
509 starCount={starCount}
510 starred={starred}
511 currentUser={user?.username}
71cd5ecClaude512 archived={archived}
513 isTemplate={isTemplate}
06d5ffeClaude514 />
fc1817aClaude515 <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
520git 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(
06d5ffeClaude529 <Layout title={`${owner}/${repo}`} user={user}>
530 <RepoHeader
531 owner={owner}
532 repo={repo}
533 starCount={starCount}
534 starred={starred}
535 currentUser={user?.username}
71cd5ecClaude536 archived={archived}
537 isTemplate={isTemplate}
06d5ffeClaude538 />
71cd5ecClaude539 {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
001af43Claude549 method="post"
71cd5ecClaude550 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 )}
fc1817aClaude566 <RepoNav owner={owner} repo={repo} active="code" />
06d5ffeClaude567 <BranchSwitcher
568 owner={owner}
569 repo={repo}
570 currentRef={defaultBranch}
571 branches={branches}
572 pathType="tree"
573 />
fc1817aClaude574 <FileTable
575 entries={tree}
576 owner={owner}
577 repo={repo}
578 ref={defaultBranch}
579 path=""
580 />
79136bbClaude581 {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>
fc1817aClaude590 </div>
79136bbClaude591 );
592 })()}
fc1817aClaude593 </Layout>
594 );
595});
596
597// Browse tree at ref/path
598web.get("/:owner/:repo/tree/:ref{.+$}", async (c) => {
599 const { owner, repo } = c.req.param();
06d5ffeClaude600 const user = c.get("user");
fc1817aClaude601 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(
06d5ffeClaude628 <Layout title={`${treePath || "/"} — ${owner}/${repo}`} user={user}>
fc1817aClaude629 <RepoHeader owner={owner} repo={repo} />
630 <RepoNav owner={owner} repo={repo} active="code" />
06d5ffeClaude631 <BranchSwitcher
632 owner={owner}
633 repo={repo}
634 currentRef={ref}
635 branches={branches}
636 pathType="tree"
637 subPath={treePath}
638 />
fc1817aClaude639 <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
06d5ffeClaude651// View file blob with syntax highlighting
fc1817aClaude652web.get("/:owner/:repo/blob/:ref{.+$}", async (c) => {
653 const { owner, repo } = c.req.param();
06d5ffeClaude654 const user = c.get("user");
fc1817aClaude655 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(
06d5ffeClaude679 <Layout title="Not Found" user={user}>
fc1817aClaude680 <div class="empty-state">
681 <h2>File not found</h2>
682 </div>
683 </Layout>,
684 404
685 );
686 }
687
06d5ffeClaude688 const fileName = filePath.split("/").pop() || filePath;
fc1817aClaude689
690 return c.html(
06d5ffeClaude691 <Layout title={`${filePath} — ${owner}/${repo}`} user={user}>
fc1817aClaude692 <RepoHeader owner={owner} repo={repo} />
693 <RepoNav owner={owner} repo={repo} active="code" />
06d5ffeClaude694 <BranchSwitcher
695 owner={owner}
696 repo={repo}
697 currentRef={ref}
698 branches={branches}
699 pathType="blob"
700 subPath={filePath}
701 />
fc1817aClaude702 <Breadcrumb owner={owner} repo={repo} ref={ref} path={filePath} />
703 <div class="blob-view">
704 <div class="blob-header">
06d5ffeClaude705 <span>{fileName} — {blob.size} bytes</span>
79136bbClaude706 <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>
16b325cClaude713 <a href={`/${owner}/${repo}/timeline/${ref}/${filePath}`} style="font-size: 12px">
714 History
715 </a>
0074234Claude716 {user && (
717 <a href={`/${owner}/${repo}/edit/${ref}/${filePath}`} style="font-size: 12px">
718 Edit
719 </a>
720 )}
79136bbClaude721 </span>
fc1817aClaude722 </div>
723 {blob.isBinary ? (
724 <div style="padding: 16px; color: var(--text-muted)">
725 Binary file not shown.
726 </div>
06d5ffeClaude727 ) : (() => {
728 const { html: highlighted, language } = highlightCode(
729 blob.content,
730 fileName
731 );
732 const lineCount = blob.content.split("\n").length;
733 // Trim trailing newline from count
734 const adjustedCount =
735 blob.content.endsWith("\n") ? lineCount - 1 : lineCount;
736
737 if (language) {
738 return (
739 <HighlightedCode
740 highlightedHtml={highlighted}
741 lineCount={adjustedCount}
742 />
743 );
744 }
745 const lines = blob.content.split("\n");
746 if (lines[lines.length - 1] === "") lines.pop();
747 return <PlainCode lines={lines} />;
748 })()}
fc1817aClaude749 </div>
750 </Layout>
751 );
752});
753
754// Commit log
755web.get("/:owner/:repo/commits/:ref?", async (c) => {
756 const { owner, repo } = c.req.param();
06d5ffeClaude757 const user = c.get("user");
fc1817aClaude758 const ref =
759 c.req.param("ref") || (await getDefaultBranch(owner, repo)) || "main";
06d5ffeClaude760 const branches = await listBranches(owner, repo);
fc1817aClaude761
762 const commits = await listCommits(owner, repo, ref, 50);
763
3951454Claude764 // Block J3 — batch-fetch cached verification results for the page.
765 let verifications: Record<string, { verified: boolean; reason: string }> = {};
766 try {
767 const [ownerRow] = await db
768 .select()
769 .from(users)
770 .where(eq(users.username, owner))
771 .limit(1);
772 if (ownerRow) {
773 const [repoRow] = await db
774 .select()
775 .from(repositories)
776 .where(
777 and(
778 eq(repositories.ownerId, ownerRow.id),
779 eq(repositories.name, repo)
780 )
781 )
782 .limit(1);
783 if (repoRow && commits.length > 0) {
784 const rows = await db
785 .select()
786 .from(commitVerifications)
787 .where(
788 and(
789 eq(commitVerifications.repositoryId, repoRow.id),
790 inArray(
791 commitVerifications.commitSha,
792 commits.map((c) => c.sha)
793 )
794 )
795 );
796 for (const r of rows) {
797 verifications[r.commitSha] = {
798 verified: r.verified,
799 reason: r.reason,
800 };
801 }
802 }
803 }
804 } catch {
805 // DB unavailable — skip the badges gracefully.
806 }
807
fc1817aClaude808 return c.html(
06d5ffeClaude809 <Layout title={`Commits — ${owner}/${repo}`} user={user}>
fc1817aClaude810 <RepoHeader owner={owner} repo={repo} />
811 <RepoNav owner={owner} repo={repo} active="commits" />
06d5ffeClaude812 <BranchSwitcher
813 owner={owner}
814 repo={repo}
815 currentRef={ref}
816 branches={branches}
817 pathType="commits"
818 />
fc1817aClaude819 {commits.length === 0 ? (
820 <div class="empty-state">
821 <p>No commits yet.</p>
822 </div>
823 ) : (
3951454Claude824 <CommitList
825 commits={commits}
826 owner={owner}
827 repo={repo}
828 verifications={verifications}
829 />
fc1817aClaude830 )}
831 </Layout>
832 );
833});
834
835// Single commit with diff
836web.get("/:owner/:repo/commit/:sha", async (c) => {
837 const { owner, repo, sha } = c.req.param();
06d5ffeClaude838 const user = c.get("user");
fc1817aClaude839
05b973eClaude840 // Fetch commit, full message, and diff in parallel
841 const [commit, fullMessage, diffResult] = await Promise.all([
842 getCommit(owner, repo, sha),
843 getCommitFullMessage(owner, repo, sha),
844 getDiff(owner, repo, sha),
845 ]);
fc1817aClaude846 if (!commit) {
847 return c.html(
06d5ffeClaude848 <Layout title="Not Found" user={user}>
fc1817aClaude849 <div class="empty-state">
850 <h2>Commit not found</h2>
851 </div>
852 </Layout>,
853 404
854 );
855 }
856
3951454Claude857 // Block J3 — try to verify this commit's signature.
858 let verification:
859 | { verified: boolean; reason: string; signatureType: string | null }
860 | null = null;
0cdfd89Claude861 // Block J8 — external CI commit statuses rollup.
862 let statusCombined:
863 | {
864 state: "pending" | "success" | "failure";
865 total: number;
866 contexts: Array<{
867 context: string;
868 state: string;
869 description: string | null;
870 targetUrl: string | null;
871 }>;
872 }
873 | null = null;
3951454Claude874 try {
875 const [ownerRow] = await db
876 .select()
877 .from(users)
878 .where(eq(users.username, owner))
879 .limit(1);
880 if (ownerRow) {
881 const [repoRow] = await db
882 .select()
883 .from(repositories)
884 .where(
885 and(
886 eq(repositories.ownerId, ownerRow.id),
887 eq(repositories.name, repo)
888 )
889 )
890 .limit(1);
891 if (repoRow) {
892 const { verifyCommit } = await import("../lib/signatures");
893 const v = await verifyCommit(repoRow.id, owner, repo, commit.sha);
894 verification = {
895 verified: v.verified,
896 reason: v.reason,
897 signatureType: v.signatureType,
898 };
0cdfd89Claude899 try {
900 const { combinedStatus } = await import("../lib/commit-statuses");
901 const combined = await combinedStatus(repoRow.id, commit.sha);
902 if (combined.total > 0) {
903 statusCombined = {
904 state: combined.state as any,
905 total: combined.total,
906 contexts: combined.contexts.map((c) => ({
907 context: c.context,
908 state: c.state,
909 description: c.description,
910 targetUrl: c.targetUrl,
911 })),
912 };
913 }
914 } catch {
915 statusCombined = null;
916 }
3951454Claude917 }
918 }
919 } catch {
920 verification = null;
921 }
922
05b973eClaude923 const { files, raw } = diffResult;
fc1817aClaude924
925 return c.html(
06d5ffeClaude926 <Layout title={`${commit.message} — ${owner}/${repo}`} user={user}>
fc1817aClaude927 <RepoHeader owner={owner} repo={repo} />
928 <div
929 style="background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 20px"
930 >
931 <div style="font-size: 18px; font-weight: 600; margin-bottom: 8px">
932 {commit.message}
933 </div>
934 {fullMessage !== commit.message && (
935 <div style="white-space: pre-wrap; color: var(--text-muted); font-size: 14px; margin-bottom: 12px">
936 {fullMessage}
937 </div>
938 )}
939 <div style="font-size: 13px; color: var(--text-muted)">
940 <strong style="color: var(--text)">{commit.author}</strong>{" "}
941 committed on{" "}
942 {new Date(commit.date).toLocaleDateString("en-US", {
943 month: "long",
944 day: "numeric",
945 year: "numeric",
946 })}
3951454Claude947 {verification && verification.reason !== "unsigned" && (
948 <span
949 style={`margin-left:10px;font-size:10px;padding:1px 6px;border-radius:3px;text-transform:uppercase;letter-spacing:.4px;color:#fff;background:${
950 verification.verified
951 ? "var(--green,#2ea043)"
952 : "var(--yellow,#d29922)"
953 }`}
954 title={`${verification.signatureType?.toUpperCase() || ""} · ${verification.reason}`}
955 >
956 {verification.verified ? "Verified" : verification.reason}
957 </span>
958 )}
fc1817aClaude959 </div>
960 <div style="margin-top: 8px">
961 <span class="commit-sha">{commit.sha}</span>
962 {commit.parentShas.length > 0 && (
963 <span style="margin-left: 12px; font-size: 13px; color: var(--text-muted)">
964 Parent:{" "}
965 {commit.parentShas.map((p) => (
966 <a
967 href={`/${owner}/${repo}/commit/${p}`}
968 class="commit-sha"
969 style="margin-left: 4px"
970 >
971 {p.slice(0, 7)}
972 </a>
973 ))}
974 </span>
975 )}
976 </div>
0cdfd89Claude977 {statusCombined && (
978 <div style="margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 13px">
979 <strong style="color: var(--text)">Checks</strong>
980 <span style="margin-left: 8px; color: var(--text-muted)">
981 {statusCombined.total} total —{" "}
982 <span
983 style={`color:${
984 statusCombined.state === "success"
985 ? "var(--green,#2ea043)"
986 : statusCombined.state === "failure"
987 ? "var(--red,#da3633)"
988 : "var(--yellow,#d29922)"
989 }`}
990 >
991 {statusCombined.state}
992 </span>
993 </span>
994 <div style="margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px">
995 {statusCombined.contexts.map((cx) => (
996 <span
997 style={`font-size:11px;padding:2px 6px;border-radius:3px;color:#fff;background:${
998 cx.state === "success"
999 ? "var(--green,#2ea043)"
1000 : cx.state === "pending"
1001 ? "var(--yellow,#d29922)"
1002 : "var(--red,#da3633)"
1003 }`}
1004 title={cx.description || cx.context}
1005 >
1006 {cx.targetUrl ? (
1007 <a
1008 href={cx.targetUrl}
1009 style="color: inherit; text-decoration: none"
1010 rel="noopener"
1011 >
1012 {cx.context}: {cx.state}
1013 </a>
1014 ) : (
1015 <>
1016 {cx.context}: {cx.state}
1017 </>
1018 )}
1019 </span>
1020 ))}
1021 </div>
1022 </div>
1023 )}
fc1817aClaude1024 </div>
1025 <DiffView raw={raw} files={files} />
1026 </Layout>
1027 );
1028});
1029
79136bbClaude1030// Raw file download
1031web.get("/:owner/:repo/raw/:ref{.+$}", async (c) => {
1032 const { owner, repo } = c.req.param();
1033 const refAndPath = c.req.param("ref");
1034
1035 const branches = await listBranches(owner, repo);
1036 let ref = "";
1037 let filePath = "";
1038
1039 for (const branch of branches) {
1040 if (refAndPath.startsWith(branch + "/")) {
1041 ref = branch;
1042 filePath = refAndPath.slice(branch.length + 1);
1043 break;
1044 }
1045 }
1046
1047 if (!ref) {
1048 const slashIdx = refAndPath.indexOf("/");
1049 if (slashIdx === -1) return c.text("Not found", 404);
1050 ref = refAndPath.slice(0, slashIdx);
1051 filePath = refAndPath.slice(slashIdx + 1);
1052 }
1053
1054 const data = await getRawBlob(owner, repo, ref, filePath);
1055 if (!data) return c.text("Not found", 404);
1056
1057 const fileName = filePath.split("/").pop() || "file";
772a24fClaude1058 return new Response(data as BodyInit, {
79136bbClaude1059 headers: {
1060 "Content-Type": "application/octet-stream",
1061 "Content-Disposition": `attachment; filename="${fileName}"`,
05b973eClaude1062 "Cache-Control": "public, max-age=300, stale-while-revalidate=60",
79136bbClaude1063 },
1064 });
1065});
1066
1067// Blame view
1068web.get("/:owner/:repo/blame/:ref{.+$}", async (c) => {
1069 const { owner, repo } = c.req.param();
1070 const user = c.get("user");
1071 const refAndPath = c.req.param("ref");
1072
1073 const branches = await listBranches(owner, repo);
1074 let ref = "";
1075 let filePath = "";
1076
1077 for (const branch of branches) {
1078 if (refAndPath.startsWith(branch + "/")) {
1079 ref = branch;
1080 filePath = refAndPath.slice(branch.length + 1);
1081 break;
1082 }
1083 }
1084
1085 if (!ref) {
1086 const slashIdx = refAndPath.indexOf("/");
1087 if (slashIdx === -1) return c.text("Not found", 404);
1088 ref = refAndPath.slice(0, slashIdx);
1089 filePath = refAndPath.slice(slashIdx + 1);
1090 }
1091
1092 const blameLines = await getBlame(owner, repo, ref, filePath);
1093 if (blameLines.length === 0) {
1094 return c.html(
1095 <Layout title="Not Found" user={user}>
1096 <div class="empty-state">
1097 <h2>File not found</h2>
1098 </div>
1099 </Layout>,
1100 404
1101 );
1102 }
1103
1104 const fileName = filePath.split("/").pop() || filePath;
1105
1106 return c.html(
1107 <Layout title={`Blame: ${filePath} — ${owner}/${repo}`} user={user}>
1108 <RepoHeader owner={owner} repo={repo} />
1109 <RepoNav owner={owner} repo={repo} active="code" />
1110 <Breadcrumb owner={owner} repo={repo} ref={ref} path={filePath} />
1111 <div class="blob-view">
1112 <div class="blob-header">
1113 <span>{fileName} — blame</span>
1114 <a href={`/${owner}/${repo}/blob/${ref}/${filePath}`} style="font-size: 12px">
1115 Normal view
1116 </a>
1117 </div>
1118 <div class="blob-code" style="overflow-x: auto">
1119 <table style="width: 100%; border-collapse: collapse; font-size: 13px; font-family: var(--font-mono)">
1120 <tbody>
1121 {blameLines.map((line, i) => {
1122 const showInfo =
1123 i === 0 || blameLines[i - 1].sha !== line.sha;
1124 return (
1125 <tr style="border-bottom: 1px solid var(--border)">
1126 <td
1127 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)" : ""}`}
1128 >
1129 {showInfo && (
1130 <>
1131 <a
1132 href={`/${owner}/${repo}/commit/${line.sha}`}
1133 style="color: var(--text-link); font-family: var(--font-mono)"
1134 >
1135 {line.sha.slice(0, 7)}
1136 </a>{" "}
1137 <span>{line.author}</span>
1138 </>
1139 )}
1140 </td>
1141 <td class="line-num">{line.lineNum}</td>
1142 <td class="line-content">{line.content}</td>
1143 </tr>
1144 );
1145 })}
1146 </tbody>
1147 </table>
1148 </div>
1149 </div>
1150 </Layout>
1151 );
1152});
1153
1154// Search
1155web.get("/:owner/:repo/search", async (c) => {
1156 const { owner, repo } = c.req.param();
1157 const user = c.get("user");
1158 const q = c.req.query("q") || "";
1159
1160 if (!(await repoExists(owner, repo))) return c.notFound();
1161
1162 const defaultBranch = (await getDefaultBranch(owner, repo)) || "main";
1163 let results: Array<{ file: string; lineNum: number; line: string }> = [];
1164
1165 if (q.trim()) {
1166 results = await searchCode(owner, repo, defaultBranch, q.trim());
1167 }
1168
1169 return c.html(
1170 <Layout title={`Search — ${owner}/${repo}`} user={user}>
1171 <RepoHeader owner={owner} repo={repo} />
1172 <RepoNav owner={owner} repo={repo} active="code" />
1173 <form
001af43Claude1174 method="get"
79136bbClaude1175 action={`/${owner}/${repo}/search`}
1176 style="margin-bottom: 20px"
1177 >
1178 <div style="display: flex; gap: 8px">
1179 <input
1180 type="text"
1181 name="q"
1182 value={q}
1183 placeholder="Search code..."
1184 style="flex: 1; padding: 8px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 14px"
1185 />
1186 <button type="submit" class="btn btn-primary">
1187 Search
1188 </button>
1189 </div>
1190 </form>
1191 {q && (
1192 <p style="font-size: 14px; color: var(--text-muted); margin-bottom: 16px">
1193 {results.length} result{results.length !== 1 ? "s" : ""} for{" "}
1194 <strong style="color: var(--text)">"{q}"</strong>
1195 </p>
1196 )}
1197 {results.length > 0 && (
1198 <div class="search-results">
1199 {(() => {
1200 // Group by file
1201 const grouped: Record<
1202 string,
1203 Array<{ lineNum: number; line: string }>
1204 > = {};
1205 for (const r of results) {
1206 if (!grouped[r.file]) grouped[r.file] = [];
1207 grouped[r.file].push({ lineNum: r.lineNum, line: r.line });
1208 }
1209 return Object.entries(grouped).map(([file, matches]) => (
1210 <div class="diff-file" style="margin-bottom: 12px">
1211 <div class="diff-file-header">
1212 <a
1213 href={`/${owner}/${repo}/blob/${defaultBranch}/${file}`}
1214 >
1215 {file}
1216 </a>
1217 </div>
1218 <div class="blob-code">
1219 <table>
1220 <tbody>
1221 {matches.map((m) => (
1222 <tr>
1223 <td class="line-num">{m.lineNum}</td>
1224 <td class="line-content">{m.line}</td>
1225 </tr>
1226 ))}
1227 </tbody>
1228 </table>
1229 </div>
1230 </div>
1231 ));
1232 })()}
1233 </div>
1234 )}
1235 </Layout>
1236 );
1237});
1238
fc1817aClaude1239export default web;