From d320c3a847fa12dc52cbcf371af571ace1c86c69 Mon Sep 17 00:00:00 2001 From: wonder Date: Fri, 19 Jun 2026 22:23:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=94=9F=E6=88=90/=E5=AE=A1=E6=9F=A5?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=20ref=20=E9=80=89=E6=8B=A9=E5=99=A8?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A0=87=E7=AD=BE=E5=92=8C=E6=9C=80=E8=BF=91?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/pages/generate.html | 78 ++++++++++++++++++++++------- templates/pages/review.html | 93 ++++++++++++++++++++++++++++------- 2 files changed, 134 insertions(+), 37 deletions(-) diff --git a/templates/pages/generate.html b/templates/pages/generate.html index 0932170..fface87 100644 --- a/templates/pages/generate.html +++ b/templates/pages/generate.html @@ -13,13 +13,13 @@
- +
- + @@ -94,40 +94,82 @@ if (!resp.ok) throw new Error('Failed to load refs'); const refs = await resp.json(); - const baseSelect = document.getElementById('base-ref'); - const headSelect = document.getElementById('head-ref'); - baseSelect.innerHTML = ''; - headSelect.innerHTML = ''; + // Fetch recent commits for the "Recent Commits" group + let commits = []; + try { + const graphResp = await fetch(`/api/repos/${repoId}/graph?max_commits=20`); + if (graphResp.ok) { + commits = await graphResp.json(); + } + } catch (e) { + console.warn('Failed to load recent commits:', e); + } + const selects = ['base-ref', 'head-ref']; const branches = refs.filter(r => !r.is_tag); + const tags = refs.filter(r => r.is_tag); - branches.forEach(ref => { - const opt1 = document.createElement('option'); - opt1.value = ref.name; - opt1.textContent = ref.name + (ref.is_head ? ' (HEAD)' : ''); - baseSelect.appendChild(opt1); + selects.forEach(selectId => { + const select = document.getElementById(selectId); + select.innerHTML = ''; - const opt2 = document.createElement('option'); - opt2.value = ref.name; - opt2.textContent = ref.name + (ref.is_head ? ' (HEAD)' : ''); - headSelect.appendChild(opt2); + if (branches.length > 0) { + const group = document.createElement('optgroup'); + group.label = '分支'; + branches.forEach(ref => { + const opt = document.createElement('option'); + opt.value = ref.name; + opt.textContent = ref.name + (ref.is_head ? ' (HEAD)' : ''); + group.appendChild(opt); + }); + select.appendChild(group); + } + + if (tags.length > 0) { + const group = document.createElement('optgroup'); + group.label = '标签'; + tags.forEach(ref => { + const opt = document.createElement('option'); + opt.value = ref.name; + opt.textContent = ref.name; + group.appendChild(opt); + }); + select.appendChild(group); + } + + if (commits.length > 0) { + const group = document.createElement('optgroup'); + group.label = '最近提交'; + commits.forEach(commit => { + const opt = document.createElement('option'); + opt.value = commit.hash; + opt.textContent = `${commit.short_hash} ${commit.message.substring(0, 40)}`; + group.appendChild(opt); + }); + select.appendChild(group); + } }); // Auto-select from URL params, or fall back to main/master and HEAD const params = new URLSearchParams(window.location.search); const urlBase = params.get('base'); const urlHead = params.get('head'); + const baseSelect = document.getElementById('base-ref'); + const headSelect = document.getElementById('head-ref'); const mainBranch = branches.find(b => b.name === 'main' || b.name === 'master'); - const headBranch = branches.find(r => r.is_head); + const headBranch = refs.find(r => r.is_head); - if (urlBase && branches.some(b => b.name === urlBase)) { + // Check if value exists in select options + const hasOption = (select, val) => Array.from(select.options).some(o => o.value === val); + + if (urlBase && hasOption(baseSelect, urlBase)) { baseSelect.value = urlBase; } else if (mainBranch) { baseSelect.value = mainBranch.name; } - if (urlHead && branches.some(b => b.name === urlHead)) { + if (urlHead && hasOption(headSelect, urlHead)) { headSelect.value = urlHead; } else if (headBranch) { headSelect.value = headBranch.name; diff --git a/templates/pages/review.html b/templates/pages/review.html index 0b4e7d1..c91889d 100644 --- a/templates/pages/review.html +++ b/templates/pages/review.html @@ -19,13 +19,13 @@
- +
- + @@ -115,30 +115,85 @@ if (!resp.ok) throw new Error('Failed to load refs'); const refs = await resp.json(); - const baseSelect = document.getElementById('base-ref'); - const headSelect = document.getElementById('head-ref'); - baseSelect.innerHTML = ''; - headSelect.innerHTML = ''; + // Fetch recent commits for the "Recent Commits" group + let commits = []; + try { + const graphResp = await fetch(`/api/repos/${repoId}/graph?max_commits=20`); + if (graphResp.ok) { + commits = await graphResp.json(); + } + } catch (e) { + console.warn('Failed to load recent commits:', e); + } + const selects = ['base-ref', 'head-ref']; const branches = refs.filter(r => !r.is_tag); + const tags = refs.filter(r => r.is_tag); - branches.forEach(ref => { - const opt1 = document.createElement('option'); - opt1.value = ref.name; - opt1.textContent = ref.name + (ref.is_head ? ' (HEAD)' : ''); - baseSelect.appendChild(opt1); + selects.forEach(selectId => { + const select = document.getElementById(selectId); + select.innerHTML = ''; - const opt2 = document.createElement('option'); - opt2.value = ref.name; - opt2.textContent = ref.name + (ref.is_head ? ' (HEAD)' : ''); - headSelect.appendChild(opt2); + if (branches.length > 0) { + const group = document.createElement('optgroup'); + group.label = '分支'; + branches.forEach(ref => { + const opt = document.createElement('option'); + opt.value = ref.name; + opt.textContent = ref.name + (ref.is_head ? ' (HEAD)' : ''); + group.appendChild(opt); + }); + select.appendChild(group); + } + + if (tags.length > 0) { + const group = document.createElement('optgroup'); + group.label = '标签'; + tags.forEach(ref => { + const opt = document.createElement('option'); + opt.value = ref.name; + opt.textContent = ref.name; + group.appendChild(opt); + }); + select.appendChild(group); + } + + if (commits.length > 0) { + const group = document.createElement('optgroup'); + group.label = '最近提交'; + commits.forEach(commit => { + const opt = document.createElement('option'); + opt.value = commit.hash; + opt.textContent = `${commit.short_hash} ${commit.message.substring(0, 40)}`; + group.appendChild(opt); + }); + select.appendChild(group); + } }); - const mainBranch = branches.find(b => b.name === 'main' || b.name === 'master'); - const headBranch = branches.find(r => r.is_head); + // Auto-select from URL params, or fall back to main/master and HEAD + const params = new URLSearchParams(window.location.search); + const urlBase = params.get('base'); + const urlHead = params.get('head'); + const baseSelect = document.getElementById('base-ref'); + const headSelect = document.getElementById('head-ref'); - if (mainBranch) baseSelect.value = mainBranch.name; - if (headBranch) headSelect.value = headBranch.name; + const mainBranch = branches.find(b => b.name === 'main' || b.name === 'master'); + const headBranch = refs.find(r => r.is_head); + + const hasOption = (select, val) => Array.from(select.options).some(o => o.value === val); + + if (urlBase && hasOption(baseSelect, urlBase)) { + baseSelect.value = urlBase; + } else if (mainBranch) { + baseSelect.value = mainBranch.name; + } + + if (urlHead && hasOption(headSelect, urlHead)) { + headSelect.value = urlHead; + } else if (headBranch) { + headSelect.value = headBranch.name; + } } catch (err) { console.error('Load refs error:', err); }