-
+
@@ -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);
}