fix: 仓库页面 ref 选择器填充最近提交
This commit is contained in:
@@ -168,7 +168,15 @@
|
|||||||
const refsResp = await fetch(`/api/repos/${repoId}/refs`);
|
const refsResp = await fetch(`/api/repos/${repoId}/refs`);
|
||||||
if (refsResp.ok) {
|
if (refsResp.ok) {
|
||||||
currentRefs = await refsResp.json();
|
currentRefs = await refsResp.json();
|
||||||
populateRefSelects(currentRefs);
|
|
||||||
|
// Fetch recent commits independently
|
||||||
|
let commits = [];
|
||||||
|
try {
|
||||||
|
const graphResp = await fetch(`/api/repos/${repoId}/graph?max_commits=20`);
|
||||||
|
if (graphResp.ok) commits = await graphResp.json();
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
|
||||||
|
populateRefSelects(currentRefs, commits);
|
||||||
updateButtonLinks();
|
updateButtonLinks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +203,7 @@
|
|||||||
document.getElementById('error-message').textContent = message;
|
document.getElementById('error-message').textContent = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
function populateRefSelects(refs) {
|
function populateRefSelects(refs, commits) {
|
||||||
const selects = ['select-base', 'select-head'];
|
const selects = ['select-base', 'select-head'];
|
||||||
const branches = refs.filter(r => !r.is_tag);
|
const branches = refs.filter(r => !r.is_tag);
|
||||||
const tags = refs.filter(r => r.is_tag);
|
const tags = refs.filter(r => r.is_tag);
|
||||||
@@ -231,10 +239,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add "Recent Commits" group
|
// Add "Recent Commits" group
|
||||||
if (GitGraph.commits && GitGraph.commits.length > 0) {
|
if (commits && commits.length > 0) {
|
||||||
const group = document.createElement('optgroup');
|
const group = document.createElement('optgroup');
|
||||||
group.label = '最近提交';
|
group.label = '最近提交';
|
||||||
GitGraph.commits.slice(0, 20).forEach(commit => {
|
commits.forEach(commit => {
|
||||||
const opt = document.createElement('option');
|
const opt = document.createElement('option');
|
||||||
opt.value = commit.hash;
|
opt.value = commit.hash;
|
||||||
opt.dataset.hash = commit.hash;
|
opt.dataset.hash = commit.hash;
|
||||||
|
|||||||
Reference in New Issue
Block a user