CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | import type { FC } from "hono/jsx";
import type { GitCommit, GitTreeEntry, GitDiffFile } from "../git/repository";
export const RepoHeader: FC<{ owner: string; repo: string }> = ({
owner,
repo,
}) => (
<div class="repo-header">
<a href={`/${owner}`} class="owner">
{owner}
</a>
<span class="separator">/</span>
<a href={`/${owner}/${repo}`} class="name">
{repo}
</a>
</div>
);
export const RepoNav: FC<{
owner: string;
repo: string;
active: "code" | "commits";
}> = ({ owner, repo, active }) => (
<div class="repo-nav">
<a
href={`/${owner}/${repo}`}
class={active === "code" ? "active" : ""}
>
Code
</a>
<a
href={`/${owner}/${repo}/commits`}
class={active === "commits" ? "active" : ""}
>
Commits
</a>
</div>
);
export const Breadcrumb: FC<{
owner: string;
repo: string;
ref: string;
path: string;
}> = ({ owner, repo, ref, path }) => {
const parts = path.split("/").filter(Boolean);
const crumbs: { name: string; href: string }[] = [
{ name: repo, href: `/${owner}/${repo}/tree/${ref}` },
];
let accumulated = "";
for (const part of parts) {
accumulated += (accumulated ? "/" : "") + part;
crumbs.push({
name: part,
href: `/${owner}/${repo}/tree/${ref}/${accumulated}`,
});
}
return (
<div class="breadcrumb">
{crumbs.map((crumb, i) => (
<>
{i > 0 && <span>/</span>}
{i === crumbs.length - 1 ? (
<strong>{crumb.name}</strong>
) : (
<a href={crumb.href}>{crumb.name}</a>
)}
</>
))}
</div>
);
};
export const FileTable: FC<{
entries: GitTreeEntry[];
owner: string;
repo: string;
ref: string;
path: string;
}> = ({ entries, owner, repo, ref, path }) => (
<table class="file-table">
<tbody>
{entries.map((entry) => {
const fullPath = path ? `${path}/${entry.name}` : entry.name;
const href =
entry.type === "tree"
? `/${owner}/${repo}/tree/${ref}/${fullPath}`
: `/${owner}/${repo}/blob/${ref}/${fullPath}`;
return (
<tr>
<td class="file-icon">
{entry.type === "tree" ? "\u{1F4C1}" : "\u{1F4C4}"}
</td>
<td class="file-name">
<a href={href}>{entry.name}</a>
</td>
<td style="text-align: right; color: var(--text-muted); font-size: 13px;">
{entry.size !== undefined ? formatSize(entry.size) : ""}
</td>
</tr>
);
})}
</tbody>
</table>
);
export const CommitList: FC<{
commits: GitCommit[];
owner: string;
repo: string;
}> = ({ commits, owner, repo }) => (
<div class="commit-list">
{commits.map((commit) => (
<div class="commit-item">
<div>
<div class="commit-message">
<a href={`/${owner}/${repo}/commit/${commit.sha}`}>
{commit.message}
</a>
</div>
<div class="commit-meta">
{commit.author} committed{" "}
{formatRelativeDate(commit.date)}
</div>
</div>
<a
href={`/${owner}/${repo}/commit/${commit.sha}`}
class="commit-sha"
>
{commit.sha.slice(0, 7)}
</a>
</div>
))}
</div>
);
export const DiffView: FC<{ raw: string; files: GitDiffFile[] }> = ({
raw,
files,
}) => {
// Parse unified diff into per-file sections
const sections = parseDiff(raw);
return (
<div class="diff-view">
<div style="margin-bottom: 16px; font-size: 14px; color: var(--text-muted);">
Showing{" "}
<strong style="color: var(--text)">{files.length}</strong> changed
file{files.length !== 1 ? "s" : ""} with{" "}
<span class="stat-add">
+{files.reduce((s, f) => s + f.additions, 0)}
</span>{" "}
and{" "}
<span class="stat-del">
-{files.reduce((s, f) => s + f.deletions, 0)}
</span>
</div>
{sections.map((section) => (
<div class="diff-file">
<div class="diff-file-header">{section.path}</div>
<div class="diff-content">
{section.lines.map((line) => {
let cls = "line";
if (line.startsWith("+")) cls += " line-add";
else if (line.startsWith("-")) cls += " line-del";
else if (line.startsWith("@@")) cls += " line-hunk";
return <span class={cls}>{line + "\n"}</span>;
})}
</div>
</div>
))}
</div>
);
};
function parseDiff(raw: string): Array<{ path: string; lines: string[] }> {
const sections: Array<{ path: string; lines: string[] }> = [];
const diffRegex = /^diff --git a\/(.+?) b\/.+$/;
let current: { path: string; lines: string[] } | null = null;
for (const line of raw.split("\n")) {
const match = line.match(diffRegex);
if (match) {
if (current) sections.push(current);
current = { path: match[1], lines: [] };
continue;
}
if (current && !line.startsWith("diff --git")) {
// Skip index/--- /+++ header lines from display
if (
line.startsWith("index ") ||
line.startsWith("--- ") ||
line.startsWith("+++ ") ||
line.startsWith("new file") ||
line.startsWith("deleted file") ||
line.startsWith("old mode") ||
line.startsWith("new mode")
) {
continue;
}
current.lines.push(line);
}
}
if (current) sections.push(current);
return sections;
}
function formatSize(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}
function formatRelativeDate(dateStr: string): string {
const date = new Date(dateStr);
const now = new Date();
const diffMs = now.getTime() - date.getTime();
const diffMins = Math.floor(diffMs / 60000);
if (diffMins < 1) return "just now";
if (diffMins < 60) return `${diffMins} minute${diffMins > 1 ? "s" : ""} ago`;
const diffHours = Math.floor(diffMins / 60);
if (diffHours < 24)
return `${diffHours} hour${diffHours > 1 ? "s" : ""} ago`;
const diffDays = Math.floor(diffHours / 24);
if (diffDays < 30) return `${diffDays} day${diffDays > 1 ? "s" : ""} ago`;
return date.toLocaleDateString("en-US", {
month: "short",
day: "numeric",
year: "numeric",
});
}
|