diff --git a/frontend/src/components/repos/ReposView.tsx b/frontend/src/components/repos/ReposView.tsx index 06a2597..2f25f10 100644 --- a/frontend/src/components/repos/ReposView.tsx +++ b/frontend/src/components/repos/ReposView.tsx @@ -16,12 +16,19 @@ export default function ReposView() { const [latestBranch, setLatestBranch] = useState('') const [showBranchPicker, setShowBranchPicker] = useState(false) const [scanningBranches, setScanningBranches] = useState(false) + const [branchDetected, setBranchDetected] = useState(false) const [apiKey, setApiKey] = useState('') const [expandedRepo, setExpandedRepo] = useState(null) const [currentTaskId, setCurrentTaskId] = useState(null) const [actionLabel, setActionLabel] = useState('') const [feUrl, setFeUrl] = useState('') const [feBranch, setFeBranch] = useState('main') + const [feBranchSuggestions, setFeBranchSuggestions] = useState<{name:string;commit:string}[]>([]) + const [feBranchCount, setFeBranchCount] = useState(0) + const [feLatestBranch, setFeLatestBranch] = useState('') + const [feShowBranchPicker, setFeShowBranchPicker] = useState(false) + const [feScanningBranches, setFeScanningBranches] = useState(false) + const [feBranchDetected, setFeBranchDetected] = useState(false) const [feApiKey, setFeApiKey] = useState('') const [feTaskId, setFeTaskId] = useState(null) const [feRunning, setFeRunning] = useState(false) @@ -60,12 +67,34 @@ export default function ReposView() { const selected = data.latest && data.latest !== data.default ? data.latest : data.default setBranch(selected || 'main') setLatestBranch(data.latest || '') + setBranchDetected(true) setShowBranchPicker(true) } } catch { setBranchSuggestions([{name:'main',commit:''}, {name:'master',commit:''}]) } setScanningBranches(false) } + const detectFeBranches = async (repoUrl: string) => { + if (!repoUrl || !repoUrl.includes('://')) return + setFeScanningBranches(true) + setFeBranchSuggestions([]) + setFeBranchCount(0) + try { + const res = await fetch('/api/repos/branches?url=' + encodeURIComponent(repoUrl)) + const data = await res.json() + if (data.branches && data.branches.length > 0) { + setFeBranchSuggestions(data.branches) + setFeBranchCount(data.total || 0) + const selected = data.latest && data.latest !== data.default ? data.latest : data.default + setFeBranch(selected || 'main') + setFeLatestBranch(data.latest || '') + setFeBranchDetected(true) + setFeShowBranchPicker(true) + } + } catch { setFeBranchSuggestions([{name:'main',commit:''}, {name:'master',commit:''}]) } + setFeScanningBranches(false) + } + const scanRepo = async () => { if (!url) return; setActionLabel('扫描仓库') const res = await fetch('/api/repos', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url, branch, api_key: apiKey }) }) @@ -129,6 +158,13 @@ export default function ReposView() { )} + {branchDetected && latestBranch && latestBranch !== branch && ( +
+ + 已自动选择最新提交分支: {latestBranch} + +
+ )} setApiKey(e.target.value)} className="w-48 px-3 py-2 rounded-lg text-sm outline-none" style={{ backgroundColor: 'rgb(var(--color-page))', borderColor: !apiKey ? 'rgb(var(--color-error))' : 'rgb(var(--color-border))', borderWidth: !apiKey ? '2px' : '1px', color: 'rgb(var(--color-text-primary))' }} /> @@ -159,38 +195,45 @@ export default function ReposView() {
- { setFeUrl(e.target.value); setShowBranchPicker(false) }} onBlur={() => { if (feUrl.includes('://')) detectBranches(feUrl) }} className="flex-1 px-3 py-2 rounded-lg text-sm bg-[rgb(var(--color-page))] border border-[rgb(var(--color-border))] text-[rgb(var(--color-text-primary))] outline-none" /> + { setFeUrl(e.target.value); setFeShowBranchPicker(false) }} onBlur={() => { if (feUrl.includes('://')) detectFeBranches(feUrl) }} className="flex-1 px-3 py-2 rounded-lg text-sm bg-[rgb(var(--color-page))] border border-[rgb(var(--color-border))] text-[rgb(var(--color-text-primary))] outline-none" />
-
{ if (feUrl.includes('://')) detectBranches(feUrl); setShowBranchPicker(!showBranchPicker) }}> +
{ if (feUrl.includes('://')) detectFeBranches(feUrl); setFeShowBranchPicker(!feShowBranchPicker) }}> - {scanningBranches ? ( + {feScanningBranches ? ( 扫描中... ) : ( {feBranch} )} - +
- {showBranchPicker && ( + {feShowBranchPicker && (
- {scanningBranches ? ( + {feScanningBranches ? (
正在扫描远程分支...
) : ( - branchSuggestions.map(b => ( + feBranchSuggestions.map(b => ( )) )}
)}
+ {feBranchDetected && feLatestBranch && feLatestBranch !== feBranch && ( +
+ + 最新提交分支: {feLatestBranch} + +
+ )} setFeApiKey(e.target.value)} className="w-48 px-3 py-2 rounded-lg text-sm outline-none" style={{ backgroundColor: 'rgb(var(--color-page))', borderColor: !feApiKey ? 'rgb(var(--color-error))' : 'rgb(var(--color-border))', borderWidth: !feApiKey ? '2px' : '1px', color: 'rgb(var(--color-text-primary))' }} />