feat: Phase 1 — 项目骨架搭建,集成 Gin、SQLite 和设置页面
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
<!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-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||
<h1 class="text-2xl font-bold mb-6">生成 PR 描述</h1>
|
||||
<!-- Ref Selection -->
|
||||
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6 mb-6">
|
||||
<h2 class="text-lg font-semibold mb-4">选择范围</h2>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Base (基准)</label>
|
||||
<input type="text" id="base-ref" placeholder="main"
|
||||
class="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Head (目标)</label>
|
||||
<input type="text" id="head-ref" placeholder="feature/branch"
|
||||
class="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500">
|
||||
</div>
|
||||
</div>
|
||||
<button id="generate-btn" onclick="generatePR()"
|
||||
class="mt-4 bg-green-600 text-white px-5 py-2 rounded-md text-sm font-medium hover:bg-green-700">
|
||||
生成 PR 描述
|
||||
</button>
|
||||
</div>
|
||||
<!-- Output -->
|
||||
<div id="pr-output" class="hidden 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">PR 描述</h2>
|
||||
<button onclick="copyMarkdown()" class="text-sm text-indigo-600 hover:text-indigo-800">📋 复制 Markdown</button>
|
||||
</div>
|
||||
<div id="pr-title" class="text-xl font-bold mb-2"></div>
|
||||
<div id="pr-type" class="inline-block bg-indigo-100 text-indigo-700 text-xs px-2 py-1 rounded mb-4"></div>
|
||||
<div id="pr-summary" class="text-gray-700 mb-4"></div>
|
||||
<div id="pr-details" class="prose prose-sm max-w-none"></div>
|
||||
<div id="pr-impact" class="mt-4 p-3 bg-yellow-50 rounded text-sm text-yellow-800"></div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
{{template "footer" .}}
|
||||
</div>
|
||||
<script>
|
||||
async function generatePR() {
|
||||
const base = document.getElementById('base-ref').value.trim();
|
||||
const head = document.getElementById('head-ref').value.trim();
|
||||
if (!base || !head) { alert('请填写 base 和 head'); return; }
|
||||
const btn = document.getElementById('generate-btn');
|
||||
const output = document.getElementById('pr-output');
|
||||
btn.disabled = true; btn.textContent = '生成中...';
|
||||
output.classList.remove('hidden');
|
||||
try {
|
||||
const resp = await fetch('/api/repos/{{.ID}}/generate', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({base, head})
|
||||
});
|
||||
if (!resp.ok) { const data = await resp.json(); throw new Error(data.error || '生成失败'); }
|
||||
const reader = resp.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let buffer = '', eventType = '';
|
||||
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('event: ')) eventType = line.slice(7).trim();
|
||||
else if (line.startsWith('data: ')) {
|
||||
try {
|
||||
const data = JSON.parse(line.slice(6));
|
||||
if (eventType === 'title') document.getElementById('pr-title').textContent = data.content;
|
||||
if (eventType === 'type') document.getElementById('pr-type').textContent = data.content;
|
||||
if (eventType === 'summary') document.getElementById('pr-summary').textContent = data.content;
|
||||
if (eventType === 'detail') document.getElementById('pr-details').innerHTML = data.content;
|
||||
if (eventType === 'impact') document.getElementById('pr-impact').textContent = '影响范围: ' + data.content;
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
document.getElementById('pr-summary').textContent = '错误: ' + err.message;
|
||||
} finally {
|
||||
btn.disabled = false; btn.textContent = '生成 PR 描述';
|
||||
}
|
||||
}
|
||||
function copyMarkdown() {
|
||||
const title = document.getElementById('pr-title').textContent;
|
||||
const type = document.getElementById('pr-type').textContent;
|
||||
const summary = document.getElementById('pr-summary').textContent;
|
||||
const details = document.getElementById('pr-details').innerText;
|
||||
const impact = document.getElementById('pr-impact').textContent;
|
||||
const md = '# ' + title + '\n\n**Type:** ' + type + '\n\n## Summary\n' + summary + '\n\n## Details\n' + details + '\n\n## Impact\n' + impact;
|
||||
navigator.clipboard.writeText(md);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user