@@ -32,8 +32,9 @@ export default function StartDevelopTaskDialog({
3232 const [ submitting , setSubmitting ] = useState < boolean > ( false )
3333 const [ limitDialogOpen , setLimitDialogOpen ] = useState ( false )
3434 const [ branches , setBranches ] = useState < string [ ] > ( [ ] )
35- const [ selectedBranch , setSelectedBranch ] = useState < string > ( '' )
35+ const [ selectedBranch , setSelectedBranch ] = useState < string > ( 'main ' )
3636 const [ loadingBranches , setLoadingBranches ] = useState < boolean > ( false )
37+ const [ branchFetchFailed , setBranchFetchFailed ] = useState < boolean > ( false )
3738 const [ userMessage , setUserMessage ] = useState < string > ( '' )
3839 const [ selectedModelId , setSelectedModelId ] = useState < string > ( '' )
3940 const { images, models, hosts, subscription } = useCommonData ( )
@@ -47,17 +48,21 @@ export default function StartDevelopTaskDialog({
4748 if ( project . platform === ConstsGitPlatform . GitPlatformInternal ) {
4849 setSelectedBranch ( '' )
4950 setBranches ( [ ] )
51+ setBranchFetchFailed ( false )
5052 return
5153 }
5254
5355 setLoadingBranches ( true )
56+ setBranchFetchFailed ( false )
57+ setBranches ( [ ] )
58+ setSelectedBranch ( 'main' )
5459
5560 try {
5661 // 直接使用 full_name 字段
5762 const escapedRepoFullName = project ?. full_name || ''
5863
5964 if ( ! escapedRepoFullName ) {
60- toast . error ( '无法获取仓库信息' )
65+ setBranchFetchFailed ( true )
6166 setLoadingBranches ( false )
6267 return
6368 }
@@ -69,6 +74,12 @@ export default function StartDevelopTaskDialog({
6974 if ( resp . code === 0 && resp . data ) {
7075 const branchList = resp . data . map ( ( b : DomainBranch ) => b . name || '' ) . filter ( Boolean )
7176 setBranches ( branchList )
77+
78+ if ( branchList . length === 0 ) {
79+ setBranchFetchFailed ( true )
80+ setSelectedBranch ( 'main' )
81+ return
82+ }
7283
7384 // 优先选择 main 或 master,否则选择第一个
7485 if ( branchList . includes ( 'main' ) ) {
@@ -79,11 +90,15 @@ export default function StartDevelopTaskDialog({
7990 setSelectedBranch ( branchList [ 0 ] )
8091 }
8192 } else {
93+ setBranchFetchFailed ( true )
94+ setSelectedBranch ( 'main' )
8295 toast . error ( '获取分支列表失败: ' + resp . message )
8396 }
8497 } )
8598 } catch ( error ) {
8699 console . error ( 'Fetch branches error:' , error )
100+ setBranchFetchFailed ( true )
101+ setSelectedBranch ( 'main' )
87102 toast . error ( '获取分支列表失败' )
88103 } finally {
89104 setLoadingBranches ( false )
@@ -98,6 +113,7 @@ export default function StartDevelopTaskDialog({
98113 if ( justOpened ) {
99114 setUserMessage ( '' )
100115 setSelectedModelId ( selectPreferredTaskModel ( models , subscription ) )
116+ setSelectedBranch ( 'main' )
101117 }
102118 fetchBranches ( )
103119 } else {
@@ -124,8 +140,13 @@ export default function StartDevelopTaskDialog({
124140 return
125141 }
126142
127- if ( project ?. platform !== ConstsGitPlatform . GitPlatformInternal && ! selectedBranch ) {
128- toast . error ( '请选择分支' )
143+ if ( project ?. platform !== ConstsGitPlatform . GitPlatformInternal && loadingBranches ) {
144+ toast . error ( '分支列表加载中,请稍后' )
145+ return
146+ }
147+
148+ if ( project ?. platform !== ConstsGitPlatform . GitPlatformInternal && ! selectedBranch . trim ( ) ) {
149+ toast . error ( '请输入分支名称' )
129150 return
130151 }
131152
@@ -144,7 +165,7 @@ export default function StartDevelopTaskDialog({
144165 image_id : selectImage ( images , false ) ,
145166 host_id : selectHost ( hosts , false ) ,
146167 repo : {
147- branch : project ?. platform === ConstsGitPlatform . GitPlatformInternal ? '' : selectedBranch ,
168+ branch : project ?. platform === ConstsGitPlatform . GitPlatformInternal ? '' : selectedBranch . trim ( ) ,
148169 } ,
149170 resource : {
150171 core : 2 ,
@@ -190,27 +211,34 @@ export default function StartDevelopTaskDialog({
190211 { ( project ?. platform !== ConstsGitPlatform . GitPlatformInternal ) && (
191212 < div className = "space-y-2" >
192213 < Label > 代码仓库分支</ Label >
193- < Select value = { selectedBranch } onValueChange = { setSelectedBranch } disabled = { loadingBranches || branches . length === 0 } >
194- < SelectTrigger className = "w-full" >
195- { loadingBranches ? (
196- < div className = "flex items-center gap-2" >
197- < Spinner className = "size-4" />
198- < span > 加载中...</ span >
199- </ div >
200- ) : (
214+ { loadingBranches ? (
215+ < div className = "flex h-10 items-center gap-2 rounded-md border px-3 text-sm text-muted-foreground" >
216+ < Spinner className = "size-4" />
217+ < span > 加载中...</ span >
218+ </ div >
219+ ) : branchFetchFailed || branches . length === 0 ? (
220+ < Input
221+ value = { selectedBranch }
222+ onChange = { ( e ) => setSelectedBranch ( e . target . value ) }
223+ placeholder = "请输入分支名称"
224+ required
225+ />
226+ ) : (
227+ < Select value = { selectedBranch } onValueChange = { setSelectedBranch } >
228+ < SelectTrigger className = "w-full" >
201229 < SelectValue placeholder = "请选择分支" />
202- ) }
203- </ SelectTrigger >
204- < SelectContent className = "break-all" >
205- { branches . map ( ( branch ) => (
206- < SelectItem key = { branch } value = { branch } >
207- { branch }
208- </ SelectItem >
209- ) ) }
210- </ SelectContent >
211- </ Select >
212- </ div >
213- ) }
230+ </ SelectTrigger >
231+ < SelectContent className = "break-all" >
232+ { branches . map ( ( branch ) => (
233+ < SelectItem key = { branch } value = { branch } >
234+ { branch }
235+ </ SelectItem >
236+ ) ) }
237+ </ SelectContent >
238+ </ Select >
239+ ) }
240+ </ div >
241+ ) }
214242 < div className = "space-y-2" >
215243 < Label > 大模型</ Label >
216244 < Select value = { selectedModelId } onValueChange = { setSelectedModelId } >
0 commit comments