feat: Phase 1 — 项目骨架搭建,集成 Gin、SQLite 和设置页面
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN" class="h-full">
|
||||
{{template "head" .}}
|
||||
<body class="h-full bg-gray-50 text-gray-900">
|
||||
<div class="min-h-full flex flex-col">
|
||||
{{template "nav" .}}
|
||||
<main class="flex-1">
|
||||
<div class="max-w-3xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||
<!-- Hero -->
|
||||
<div class="text-center mb-10">
|
||||
<h1 class="text-3xl font-bold text-gray-900 mb-3">PR-Helper</h1>
|
||||
<p class="text-gray-500">输入 Git 仓库 URL,自动生成 PR 描述并进行 AI 代码审查</p>
|
||||
</div>
|
||||
<!-- Clone Form -->
|
||||
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6 mb-8">
|
||||
<h2 class="text-lg font-semibold mb-4">克隆仓库</h2>
|
||||
<form id="clone-form" class="flex gap-3">
|
||||
<input type="text" id="repo-url" name="url" placeholder="https://github.com/user/repo.git"
|
||||
class="flex-1 rounded-md border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500" required>
|
||||
<button type="submit" id="clone-btn"
|
||||
class="bg-indigo-600 text-white px-5 py-2 rounded-md text-sm font-medium hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
|
||||
克隆
|
||||
</button>
|
||||
</form>
|
||||
<div id="clone-progress" class="hidden mt-4">
|
||||
<div class="flex items-center gap-3 mb-2">
|
||||
<div class="animate-spin rounded-full h-4 w-4 border-2 border-indigo-600 border-t-transparent"></div>
|
||||
<span id="clone-status" class="text-sm text-gray-600">准备中...</span>
|
||||
</div>
|
||||
<div class="w-full bg-gray-200 rounded-full h-2">
|
||||
<div id="clone-bar" class="bg-indigo-600 h-2 rounded-full transition-all duration-300" style="width:0%"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="clone-error" class="hidden mt-3 text-sm text-red-600"></div>
|
||||
</div>
|
||||
<!-- Cached Repos -->
|
||||
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
|
||||
<div class="flex justify-between items-center mb-4">
|
||||
<h2 class="text-lg font-semibold">已缓存仓库</h2>
|
||||
<button hx-post="/api/repos/cleanup" hx-swap="none"
|
||||
class="text-sm text-gray-500 hover:text-red-600"
|
||||
hx-on::after-request="window.location.reload()">
|
||||
清理过期缓存
|
||||
</button>
|
||||
</div>
|
||||
<div id="repos-list">
|
||||
{{if .Repos}}
|
||||
<div class="divide-y divide-gray-100">
|
||||
{{range .Repos}}
|
||||
<div class="py-3 flex items-center justify-between">
|
||||
<div>
|
||||
<a href="/repo/{{.ID}}" class="text-sm font-medium text-indigo-600 hover:text-indigo-800">{{.URL}}</a>
|
||||
<p class="text-xs text-gray-400 mt-1">最后使用: {{.LastUsed}}</p>
|
||||
</div>
|
||||
<button hx-delete="/api/repos/{{.ID}}" hx-confirm="确定删除此仓库缓存?"
|
||||
hx-swap="none" hx-on::after-request="window.location.reload()"
|
||||
class="text-xs text-red-500 hover:text-red-700">删除</button>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{else}}
|
||||
<p class="text-sm text-gray-400 text-center py-6">暂无缓存仓库</p>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
{{template "footer" .}}
|
||||
</div>
|
||||
<script>
|
||||
document.getElementById('clone-form').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
const url = document.getElementById('repo-url').value.trim();
|
||||
if (!url) return;
|
||||
const btn = document.getElementById('clone-btn');
|
||||
const progress = document.getElementById('clone-progress');
|
||||
const status = document.getElementById('clone-status');
|
||||
const bar = document.getElementById('clone-bar');
|
||||
const errorEl = document.getElementById('clone-error');
|
||||
btn.disabled = true;
|
||||
progress.classList.remove('hidden');
|
||||
errorEl.classList.add('hidden');
|
||||
bar.style.width = '0%';
|
||||
try {
|
||||
const resp = await fetch('/api/repos', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({url: url})
|
||||
});
|
||||
if (!resp.ok) { const data = await resp.json(); throw new Error(data.error || 'clone failed'); }
|
||||
const reader = resp.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let buffer = '';
|
||||
while (true) {
|
||||
const {done, value} = await reader.read();
|
||||
if (done) break;
|
||||
buffer += decoder.decode(value, {stream: true});
|
||||
const lines = buffer.split('\n');
|
||||
buffer = lines.pop() || '';
|
||||
for (const line of lines) {
|
||||
if (line.startsWith('data: ')) {
|
||||
try {
|
||||
const data = JSON.parse(line.slice(6));
|
||||
if (data.progress !== undefined) bar.style.width = data.progress + '%';
|
||||
if (data.message) status.textContent = data.message;
|
||||
if (data.done) { window.location.href = '/repo/' + data.repo_id; return; }
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
errorEl.textContent = err.message;
|
||||
errorEl.classList.remove('hidden');
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user