CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
components.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 | import type { FC } from "hono/jsx"; |
| 06d5ffe | 2 | import { html } from "hono/html"; |
| fc1817a | 3 | import type { GitCommit, GitTreeEntry, GitDiffFile } from "../git/repository"; |
| 06d5ffe | 4 | import type { Repository } from "../db/schema"; |
| fc1817a | 5 | |
| 8c790e0 | 6 | /** |
| 7 | * Describes the most recent push to a repo, used by RepoHeader to render | |
| 8 | * the Push Watch discoverability indicator. | |
| 9 | * | |
| 10 | * - ageMs < 5 min \u2192 pulsing red "\u25cf Live" badge | |
| 11 | * - ageMs < 24 hr \u2192 dimmer "\u25cb Watch" link | |
| 12 | * - otherwise \u2192 nothing shown | |
| 13 | */ | |
| 14 | export interface RecentPush { | |
| 15 | sha: string; | |
| 16 | ageMs: number; | |
| 17 | } | |
| 18 | ||
| 06d5ffe | 19 | export const RepoHeader: FC<{ |
| 20 | owner: string; | |
| 21 | repo: string; | |
| 22 | starCount?: number; | |
| 23 | starred?: boolean; | |
| c81ab7a | 24 | forkCount?: number; |
| 06d5ffe | 25 | currentUser?: string | null; |
| c81ab7a | 26 | forkedFrom?: string | null; |
| 71cd5ec | 27 | archived?: boolean; |
| 28 | isTemplate?: boolean; | |
| 8c790e0 | 29 | /** Most recent push info for Push Watch discoverability indicator. */ |
| 30 | recentPush?: RecentPush | null; | |
| 71cd5ec | 31 | }> = ({ |
| 32 | owner, | |
| 33 | repo, | |
| 34 | starCount, | |
| 35 | starred, | |
| 36 | forkCount, | |
| 37 | currentUser, | |
| 38 | forkedFrom, | |
| 39 | archived, | |
| 40 | isTemplate, | |
| 8c790e0 | 41 | recentPush, |
| 42 | }) => { | |
| 43 | const FIVE_MIN = 5 * 60 * 1000; | |
| 44 | const TWENTY_FOUR_HR = 24 * 60 * 60 * 1000; | |
| 45 | const isLive = recentPush != null && recentPush.ageMs < FIVE_MIN; | |
| 46 | const isRecent = recentPush != null && recentPush.ageMs < TWENTY_FOUR_HR; | |
| 47 | ||
| 48 | return ( | |
| 49 | <div class="repo-header"> | |
| 50 | <div> | |
| 51 | <div class="repo-header-title"> | |
| 52 | <a href={`/${owner}`} class="owner"> | |
| 53 | {owner} | |
| 54 | </a> | |
| 55 | <span class="separator">/</span> | |
| 56 | <a href={`/${owner}/${repo}`} class="name"> | |
| 57 | {repo} | |
| 58 | </a> | |
| 59 | {archived && ( | |
| 60 | <span | |
| 61 | class="repo-header-pill repo-header-pill-archived" | |
| 62 | title="Read-only: pushes and new issues/PRs disabled" | |
| 63 | > | |
| 64 | Archived | |
| 65 | </span> | |
| 66 | )} | |
| 67 | {isTemplate && ( | |
| 68 | <span | |
| 69 | class="repo-header-pill repo-header-pill-template" | |
| 70 | title="This repository can be used as a template" | |
| 71 | > | |
| 72 | Template | |
| 73 | </span> | |
| 74 | )} | |
| 75 | {isLive && recentPush && ( | |
| 76 | <a | |
| 77 | href={`/${owner}/${repo}/push/${recentPush.sha}`} | |
| 78 | class="repo-header-live-badge repo-header-live-badge--live" | |
| 79 | title="Push in progress \u2014 watch live gate + deploy status" | |
| 80 | aria-label="Live push \u2014 click to watch status" | |
| 81 | > | |
| 82 | <span class="repo-header-live-dot" aria-hidden="true">{"\u25cf"}</span> | |
| 83 | Live | |
| 84 | </a> | |
| 85 | )} | |
| 86 | {!isLive && isRecent && recentPush && ( | |
| 87 | <a | |
| 88 | href={`/${owner}/${repo}/push/${recentPush.sha}`} | |
| 89 | class="repo-header-live-badge repo-header-live-badge--recent" | |
| 90 | title="Watch the most recent push's gate + deploy results" | |
| 91 | aria-label="Watch most recent push" | |
| 92 | > | |
| 93 | <span aria-hidden="true">{"\u25cb"}</span> | |
| 94 | Watch | |
| 95 | </a> | |
| 96 | )} | |
| 97 | </div> | |
| 98 | {forkedFrom && ( | |
| 99 | <div class="repo-header-fork"> | |
| 100 | forked from <a href={`/${forkedFrom}`}>{forkedFrom}</a> | |
| 101 | </div> | |
| 71cd5ec | 102 | )} |
| c81ab7a | 103 | </div> |
| 8c790e0 | 104 | <div class="repo-header-actions"> |
| 105 | {currentUser && currentUser !== owner && ( | |
| 106 | <form method="post" action={`/${owner}/${repo}/fork`} style="display:inline"> | |
| 107 | <button type="submit" class="star-btn"> | |
| 108 | {"\u2442"} Fork {forkCount !== undefined && forkCount > 0 ? forkCount : ""} | |
| 06d5ffe | 109 | </button> |
| 110 | </form> | |
| 8c790e0 | 111 | )} |
| 112 | {starCount !== undefined && ( | |
| 113 | currentUser ? ( | |
| 114 | <form method="post" action={`/${owner}/${repo}/star`} style="display:inline"> | |
| 115 | <button | |
| 116 | type="submit" | |
| 117 | class={`star-btn${starred ? " starred" : ""}`} | |
| 118 | > | |
| 119 | {starred ? "\u2605" : "\u2606"} {starCount} | |
| 120 | </button> | |
| 121 | </form> | |
| 122 | ) : ( | |
| 123 | <span class="star-btn"> | |
| 124 | {"\u2606"} {starCount} | |
| 125 | </span> | |
| 126 | ) | |
| 127 | )} | |
| 128 | </div> | |
| 06d5ffe | 129 | </div> |
| 8c790e0 | 130 | ); |
| 131 | }; | |
| fc1817a | 132 | |
| 133 | export const RepoNav: FC<{ | |
| 134 | owner: string; | |
| 135 | repo: string; | |
| 3ef4c9d | 136 | active: |
| 137 | | "code" | |
| 138 | | "commits" | |
| 139 | | "issues" | |
| 140 | | "pulls" | |
| 141 | | "releases" | |
| eafe8c6 | 142 | | "actions" |
| 3ef4c9d | 143 | | "gates" |
| 3cbe3d6 | 144 | | "insights" |
| 145 | | "explain" | |
| 146 | | "changelog" | |
| 1e162a8 | 147 | | "semantic" |
| 148 | | "wiki" | |
| 0316dbb | 149 | | "projects" |
| ef3fd93 | 150 | | "agents" |
| c645a86 | 151 | | "discussions" |
| da3fc18 | 152 | | "security" |
| bcc4020 | 153 | | "settings" |
| 154 | | "debt-map"; | |
| fc1817a | 155 | }> = ({ owner, repo, active }) => ( |
| 156 | <div class="repo-nav"> | |
| 06d5ffe | 157 | <a href={`/${owner}/${repo}`} class={active === "code" ? "active" : ""}> |
| fc1817a | 158 | Code |
| 159 | </a> | |
| 79136bb | 160 | <a |
| 161 | href={`/${owner}/${repo}/issues`} | |
| 162 | class={active === "issues" ? "active" : ""} | |
| 163 | > | |
| 164 | Issues | |
| 165 | </a> | |
| c645a86 | 166 | <a |
| 167 | href={`/${owner}/${repo}/discussions`} | |
| 168 | class={active === "discussions" ? "active" : ""} | |
| 169 | > | |
| 170 | Discussions | |
| 171 | </a> | |
| 1e162a8 | 172 | <a |
| 173 | href={`/${owner}/${repo}/wiki`} | |
| 174 | class={active === "wiki" ? "active" : ""} | |
| 175 | > | |
| 176 | Wiki | |
| 177 | </a> | |
| 0074234 | 178 | <a |
| 179 | href={`/${owner}/${repo}/pulls`} | |
| 180 | class={active === "pulls" ? "active" : ""} | |
| 181 | > | |
| 182 | Pull Requests | |
| 183 | </a> | |
| 1e162a8 | 184 | <a |
| 185 | href={`/${owner}/${repo}/projects`} | |
| 186 | class={active === "projects" ? "active" : ""} | |
| 187 | > | |
| 188 | Projects | |
| 189 | </a> | |
| fc1817a | 190 | <a |
| 191 | href={`/${owner}/${repo}/commits`} | |
| 192 | class={active === "commits" ? "active" : ""} | |
| 193 | > | |
| 194 | Commits | |
| 195 | </a> | |
| eafe8c6 | 196 | <a |
| 197 | href={`/${owner}/${repo}/actions`} | |
| 198 | class={active === "actions" ? "active" : ""} | |
| 199 | > | |
| 200 | Actions | |
| 201 | </a> | |
| 3ef4c9d | 202 | <a |
| 203 | href={`/${owner}/${repo}/releases`} | |
| 204 | class={active === "releases" ? "active" : ""} | |
| 205 | > | |
| 206 | Releases | |
| 207 | </a> | |
| 208 | <a | |
| 209 | href={`/${owner}/${repo}/gates`} | |
| 210 | class={active === "gates" ? "active" : ""} | |
| 211 | > | |
| 212 | {"\u25CF"} Gates | |
| 213 | </a> | |
| da3fc18 | 214 | <a |
| 215 | href={`/${owner}/${repo}/security/vulnerabilities`} | |
| 216 | class={active === "security" ? "active" : ""} | |
| 217 | > | |
| 218 | Security | |
| 219 | </a> | |
| c9ed210 | 220 | <a |
| 221 | href={`/${owner}/${repo}/cloud-deployments`} | |
| 222 | class={active === "deployments" ? "active" : ""} | |
| 223 | > | |
| 224 | Deployments | |
| 225 | </a> | |
| 3ef4c9d | 226 | <a |
| 227 | href={`/${owner}/${repo}/insights`} | |
| 228 | class={active === "insights" ? "active" : ""} | |
| 229 | > | |
| 230 | Insights | |
| 231 | </a> | |
| ef3fd93 | 232 | <a |
| 233 | href={`/${owner}/${repo}/agents`} | |
| 234 | class={active === "agents" ? "active" : ""} | |
| 235 | > | |
| 236 | Agents | |
| 237 | </a> | |
| 3cbe3d6 | 238 | <a |
| 239 | href={`/${owner}/${repo}/explain`} | |
| debcf27 | 240 | class={`repo-nav-ai${active === "explain" ? " active" : ""}`} |
| 241 | style="margin-left: auto" | |
| 3cbe3d6 | 242 | > |
| 243 | {"\u2728"} Explain | |
| 244 | </a> | |
| debcf27 | 245 | <a href={`/${owner}/${repo}/ask`} class="repo-nav-ai"> |
| 3ef4c9d | 246 | {"\u2728"} Ask AI |
| 247 | </a> | |
| 14c3cc8 | 248 | <a |
| 249 | href={`/${owner}/${repo}/spec`} | |
| debcf27 | 250 | class="repo-nav-ai" |
| 14c3cc8 | 251 | title="Spec to PR — paste a feature spec, AI opens a draft PR" |
| 252 | > | |
| 253 | {"\u2728"} Spec | |
| 254 | </a> | |
| d8ef5ef | 255 | <a |
| 256 | href={`/${owner}/${repo}/ai/tests`} | |
| debcf27 | 257 | class="repo-nav-ai" |
| d8ef5ef | 258 | title="AI Tests \u2014 generate failing test stubs from a source file" |
| 259 | > | |
| 260 | {"\u2728"} Tests | |
| 261 | </a> | |
| bcc4020 | 262 | <a |
| 263 | href={`/${owner}/${repo}/debt-map`} | |
| 264 | class={`repo-nav-ai${active === "debt-map" ? " active" : ""}`} | |
| 265 | title="AI Debt Map \u2014 visual technical debt graph with Claude analysis" | |
| 266 | > | |
| 267 | {"\u2593"} Debt Map | |
| 268 | </a> | |
| fc1817a | 269 | </div> |
| 270 | ); | |
| 271 | ||
| 06d5ffe | 272 | export const BranchSwitcher: FC<{ |
| 273 | owner: string; | |
| 274 | repo: string; | |
| 275 | currentRef: string; | |
| 276 | branches: string[]; | |
| 277 | pathType: "tree" | "blob" | "commits"; | |
| 278 | subPath?: string; | |
| 279 | }> = ({ owner, repo, currentRef, branches, pathType, subPath }) => { | |
| 280 | if (branches.length <= 1) { | |
| 281 | return <div class="branch-selector">{currentRef}</div>; | |
| 282 | } | |
| 283 | ||
| 284 | return ( | |
| 285 | <div class="branch-dropdown"> | |
| 286 | <button class="branch-selector" type="button"> | |
| 287 | {currentRef} ▾ | |
| 288 | </button> | |
| 289 | <div class="branch-dropdown-content"> | |
| 290 | {branches.map((branch) => { | |
| 291 | let href: string; | |
| 292 | if (pathType === "commits") { | |
| 293 | href = `/${owner}/${repo}/commits/${branch}`; | |
| 294 | } else if (subPath) { | |
| 295 | href = `/${owner}/${repo}/${pathType}/${branch}/${subPath}`; | |
| 296 | } else { | |
| 297 | href = `/${owner}/${repo}/tree/${branch}`; | |
| 298 | } | |
| 299 | return ( | |
| 300 | <a | |
| 301 | href={href} | |
| 302 | class={branch === currentRef ? "active-branch" : ""} | |
| 303 | > | |
| 304 | {branch} | |
| 305 | </a> | |
| 306 | ); | |
| 307 | })} | |
| 308 | </div> | |
| 309 | </div> | |
| 310 | ); | |
| 311 | }; | |
| 312 | ||
| fc1817a | 313 | export const Breadcrumb: FC<{ |
| 314 | owner: string; | |
| 315 | repo: string; | |
| 316 | ref: string; | |
| 317 | path: string; | |
| 318 | }> = ({ owner, repo, ref, path }) => { | |
| 319 | const parts = path.split("/").filter(Boolean); | |
| 320 | const crumbs: { name: string; href: string }[] = [ | |
| 321 | { name: repo, href: `/${owner}/${repo}/tree/${ref}` }, | |
| 322 | ]; | |
| 323 | let accumulated = ""; | |
| 324 | for (const part of parts) { | |
| 325 | accumulated += (accumulated ? "/" : "") + part; | |
| 326 | crumbs.push({ | |
| 327 | name: part, | |
| 328 | href: `/${owner}/${repo}/tree/${ref}/${accumulated}`, | |
| 329 | }); | |
| 330 | } | |
| 331 | return ( | |
| 332 | <div class="breadcrumb"> | |
| 333 | {crumbs.map((crumb, i) => ( | |
| 334 | <> | |
| 335 | {i > 0 && <span>/</span>} | |
| 336 | {i === crumbs.length - 1 ? ( | |
| 337 | <strong>{crumb.name}</strong> | |
| 338 | ) : ( | |
| 339 | <a href={crumb.href}>{crumb.name}</a> | |
| 340 | )} | |
| 341 | </> | |
| 342 | ))} | |
| 343 | </div> | |
| 344 | ); | |
| 345 | }; | |
| 346 | ||
| 347 | export const FileTable: FC<{ | |
| 348 | entries: GitTreeEntry[]; | |
| 349 | owner: string; | |
| 350 | repo: string; | |
| 351 | ref: string; | |
| 352 | path: string; | |
| 353 | }> = ({ entries, owner, repo, ref, path }) => ( | |
| 354 | <table class="file-table"> | |
| 355 | <tbody> | |
| 356 | {entries.map((entry) => { | |
| 357 | const fullPath = path ? `${path}/${entry.name}` : entry.name; | |
| 358 | const href = | |
| 359 | entry.type === "tree" | |
| 360 | ? `/${owner}/${repo}/tree/${ref}/${fullPath}` | |
| 361 | : `/${owner}/${repo}/blob/${ref}/${fullPath}`; | |
| 362 | return ( | |
| 363 | <tr> | |
| 364 | <td class="file-icon"> | |
| 365 | {entry.type === "tree" ? "\u{1F4C1}" : "\u{1F4C4}"} | |
| 366 | </td> | |
| 367 | <td class="file-name"> | |
| 368 | <a href={href}>{entry.name}</a> | |
| 369 | </td> | |
| 370 | <td style="text-align: right; color: var(--text-muted); font-size: 13px;"> | |
| 371 | {entry.size !== undefined ? formatSize(entry.size) : ""} | |
| 372 | </td> | |
| 373 | </tr> | |
| 374 | ); | |
| 375 | })} | |
| 376 | </tbody> | |
| 377 | </table> | |
| 378 | ); | |
| 379 | ||
| 06d5ffe | 380 | export const HighlightedCode: FC<{ |
| 381 | highlightedHtml: string; | |
| 382 | lineCount: number; | |
| 383 | }> = ({ highlightedHtml, lineCount }) => { | |
| 384 | const lineNums = Array.from({ length: lineCount }, (_, i) => i + 1); | |
| 385 | return ( | |
| 386 | <div class="blob-code"> | |
| 387 | <table> | |
| 388 | <tbody> | |
| 389 | <tr> | |
| 390 | <td class="line-num" style="vertical-align: top; padding-top: 0; padding-bottom: 0"> | |
| 391 | <pre style="margin: 0; line-height: 1.6; font-size: 13px"> | |
| 392 | {lineNums.map((n) => ( | |
| 393 | <> | |
| 394 | <span>{n}</span> | |
| 395 | {"\n"} | |
| 396 | </> | |
| 397 | ))} | |
| 398 | </pre> | |
| 399 | </td> | |
| 400 | <td class="line-content" style="vertical-align: top; padding-top: 0; padding-bottom: 0"> | |
| 401 | <pre style="margin: 0; line-height: 1.6; font-size: 13px">{html([highlightedHtml] as unknown as TemplateStringsArray)}</pre> | |
| 402 | </td> | |
| 403 | </tr> | |
| 404 | </tbody> | |
| 405 | </table> | |
| 406 | </div> | |
| 407 | ); | |
| 408 | }; | |
| 409 | ||
| 410 | export const PlainCode: FC<{ lines: string[] }> = ({ lines }) => ( | |
| 411 | <div class="blob-code"> | |
| 412 | <table> | |
| 413 | <tbody> | |
| 414 | {lines.map((line, i) => ( | |
| 415 | <tr> | |
| 416 | <td class="line-num">{i + 1}</td> | |
| 417 | <td class="line-content">{line}</td> | |
| 418 | </tr> | |
| 419 | ))} | |
| 420 | </tbody> | |
| 421 | </table> | |
| 422 | </div> | |
| 423 | ); | |
| 424 | ||
| fc1817a | 425 | export const CommitList: FC<{ |
| 426 | commits: GitCommit[]; | |
| 427 | owner: string; | |
| 428 | repo: string; | |
| 3951454 | 429 | verifications?: Record<string, { verified: boolean; reason: string }>; |
| 430 | }> = ({ commits, owner, repo, verifications }) => ( | |
| fc1817a | 431 | <div class="commit-list"> |
| 3951454 | 432 | {commits.map((commit) => { |
| 433 | const v = verifications?.[commit.sha]; | |
| 434 | return ( | |
| 435 | <div class="commit-item"> | |
| 436 | <div> | |
| 437 | <div class="commit-message"> | |
| 438 | <a href={`/${owner}/${repo}/commit/${commit.sha}`}> | |
| 439 | {commit.message} | |
| 440 | </a> | |
| 441 | {v?.verified && ( | |
| 442 | <span | |
| 443 | title="Signed with a registered key" | |
| 444 | style="margin-left:8px;font-size:10px;padding:1px 6px;border-radius:3px;background:var(--green,#2ea043);color:#fff;text-transform:uppercase;letter-spacing:.4px" | |
| 445 | > | |
| 446 | Verified | |
| 447 | </span> | |
| 448 | )} | |
| 449 | </div> | |
| 450 | <div class="commit-meta"> | |
| 451 | {commit.author} committed {formatRelativeDate(commit.date)} | |
| 452 | </div> | |
| fc1817a | 453 | </div> |
| 3951454 | 454 | <a |
| 455 | href={`/${owner}/${repo}/commit/${commit.sha}`} | |
| 456 | class="commit-sha" | |
| 457 | > | |
| 458 | {commit.sha.slice(0, 7)} | |
| 459 | </a> | |
| fc1817a | 460 | </div> |
| 3951454 | 461 | ); |
| 462 | })} | |
| fc1817a | 463 | </div> |
| 464 | ); | |
| 465 | ||
| 466 | export const DiffView: FC<{ raw: string; files: GitDiffFile[] }> = ({ | |
| 467 | raw, | |
| 468 | files, | |
| 469 | }) => { | |
| 470 | const sections = parseDiff(raw); | |
| 471 | ||
| 472 | return ( | |
| 473 | <div class="diff-view"> | |
| 474 | <div style="margin-bottom: 16px; font-size: 14px; color: var(--text-muted);"> | |
| 475 | Showing{" "} | |
| 476 | <strong style="color: var(--text)">{files.length}</strong> changed | |
| 477 | file{files.length !== 1 ? "s" : ""} with{" "} | |
| 478 | <span class="stat-add"> | |
| 479 | +{files.reduce((s, f) => s + f.additions, 0)} | |
| 480 | </span>{" "} | |
| 481 | and{" "} | |
| 482 | <span class="stat-del"> | |
| 483 | -{files.reduce((s, f) => s + f.deletions, 0)} | |
| 484 | </span> | |
| 485 | </div> | |
| 486 | {sections.map((section) => ( | |
| 487 | <div class="diff-file"> | |
| 488 | <div class="diff-file-header">{section.path}</div> | |
| 489 | <div class="diff-content"> | |
| 490 | {section.lines.map((line) => { | |
| 491 | let cls = "line"; | |
| 492 | if (line.startsWith("+")) cls += " line-add"; | |
| 493 | else if (line.startsWith("-")) cls += " line-del"; | |
| 494 | else if (line.startsWith("@@")) cls += " line-hunk"; | |
| 495 | return <span class={cls}>{line + "\n"}</span>; | |
| 496 | })} | |
| 497 | </div> | |
| 498 | </div> | |
| 499 | ))} | |
| 500 | </div> | |
| 501 | ); | |
| 502 | }; | |
| 503 | ||
| 06d5ffe | 504 | export const RepoCard: FC<{ repo: Repository; ownerName: string }> = ({ |
| 505 | repo, | |
| 506 | ownerName, | |
| 507 | }) => ( | |
| 508 | <div class="card"> | |
| 509 | <h3> | |
| 510 | <a href={`/${ownerName}/${repo.name}`}>{repo.name}</a> | |
| 511 | </h3> | |
| 512 | {repo.description && <p>{repo.description}</p>} | |
| 513 | <div class="card-meta"> | |
| 514 | {repo.isPrivate && <span class="badge">Private</span>} | |
| 515 | <span>{"\u2606"} {repo.starCount}</span> | |
| 516 | {repo.pushedAt && ( | |
| 517 | <span>Updated {formatRelativeDate(repo.pushedAt.toString())}</span> | |
| 518 | )} | |
| 519 | </div> | |
| 520 | </div> | |
| 521 | ); | |
| 522 | ||
| fc1817a | 523 | function parseDiff(raw: string): Array<{ path: string; lines: string[] }> { |
| 524 | const sections: Array<{ path: string; lines: string[] }> = []; | |
| 525 | const diffRegex = /^diff --git a\/(.+?) b\/.+$/; | |
| 526 | let current: { path: string; lines: string[] } | null = null; | |
| 527 | ||
| 528 | for (const line of raw.split("\n")) { | |
| 529 | const match = line.match(diffRegex); | |
| 530 | if (match) { | |
| 531 | if (current) sections.push(current); | |
| 532 | current = { path: match[1], lines: [] }; | |
| 533 | continue; | |
| 534 | } | |
| 535 | if (current && !line.startsWith("diff --git")) { | |
| 536 | if ( | |
| 537 | line.startsWith("index ") || | |
| 538 | line.startsWith("--- ") || | |
| 539 | line.startsWith("+++ ") || | |
| 540 | line.startsWith("new file") || | |
| 541 | line.startsWith("deleted file") || | |
| 542 | line.startsWith("old mode") || | |
| 543 | line.startsWith("new mode") | |
| 544 | ) { | |
| 545 | continue; | |
| 546 | } | |
| 547 | current.lines.push(line); | |
| 548 | } | |
| 549 | } | |
| 550 | if (current) sections.push(current); | |
| 551 | return sections; | |
| 552 | } | |
| 553 | ||
| 554 | function formatSize(bytes: number): string { | |
| 555 | if (bytes < 1024) return `${bytes} B`; | |
| 556 | if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; | |
| 557 | return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; | |
| 558 | } | |
| 559 | ||
| 560 | function formatRelativeDate(dateStr: string): string { | |
| 561 | const date = new Date(dateStr); | |
| 562 | const now = new Date(); | |
| 563 | const diffMs = now.getTime() - date.getTime(); | |
| 564 | const diffMins = Math.floor(diffMs / 60000); | |
| 565 | if (diffMins < 1) return "just now"; | |
| 566 | if (diffMins < 60) return `${diffMins} minute${diffMins > 1 ? "s" : ""} ago`; | |
| 567 | const diffHours = Math.floor(diffMins / 60); | |
| 568 | if (diffHours < 24) | |
| 569 | return `${diffHours} hour${diffHours > 1 ? "s" : ""} ago`; | |
| 570 | const diffDays = Math.floor(diffHours / 24); | |
| 571 | if (diffDays < 30) return `${diffDays} day${diffDays > 1 ? "s" : ""} ago`; | |
| 572 | return date.toLocaleDateString("en-US", { | |
| 573 | month: "short", | |
| 574 | day: "numeric", | |
| 575 | year: "numeric", | |
| 576 | }); | |
| 577 | } |