Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
bit-pm
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
燕伟桐
bit-pm
Commits
867ea28f
Unverified
提交
867ea28f
authored
7月 31, 2025
作者:
Will Chen
提交者:
GitHub
7月 31, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto-sync GitHub after connecting to project (#756)
上级
03c200b9
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
63 行增加
和
26 行删除
+63
-26
GitHubConnector.tsx
src/components/GitHubConnector.tsx
+63
-26
没有找到文件。
src/components/GitHubConnector.tsx
浏览文件 @
867ea28f
...
@@ -49,6 +49,8 @@ interface ConnectedGitHubConnectorProps {
...
@@ -49,6 +49,8 @@ interface ConnectedGitHubConnectorProps {
appId
:
number
;
appId
:
number
;
app
:
any
;
app
:
any
;
refreshApp
:
()
=>
void
;
refreshApp
:
()
=>
void
;
triggerAutoSync
?:
boolean
;
onAutoSyncComplete
?:
()
=>
void
;
}
}
interface
UnconnectedGitHubConnectorProps
{
interface
UnconnectedGitHubConnectorProps
{
...
@@ -56,7 +58,7 @@ interface UnconnectedGitHubConnectorProps {
...
@@ -56,7 +58,7 @@ interface UnconnectedGitHubConnectorProps {
folderName
:
string
;
folderName
:
string
;
settings
:
any
;
settings
:
any
;
refreshSettings
:
()
=>
void
;
refreshSettings
:
()
=>
void
;
refreshApp
:
()
=>
void
;
handleRepoSetupComplete
:
()
=>
void
;
expanded
?:
boolean
;
expanded
?:
boolean
;
}
}
...
@@ -64,6 +66,8 @@ function ConnectedGitHubConnector({
...
@@ -64,6 +66,8 @@ function ConnectedGitHubConnector({
appId
,
appId
,
app
,
app
,
refreshApp
,
refreshApp
,
triggerAutoSync
,
onAutoSyncComplete
,
}:
ConnectedGitHubConnectorProps
)
{
}:
ConnectedGitHubConnectorProps
)
{
const
[
isSyncing
,
setIsSyncing
]
=
useState
(
false
);
const
[
isSyncing
,
setIsSyncing
]
=
useState
(
false
);
const
[
syncError
,
setSyncError
]
=
useState
<
string
|
null
>
(
null
);
const
[
syncError
,
setSyncError
]
=
useState
<
string
|
null
>
(
null
);
...
@@ -71,6 +75,7 @@ function ConnectedGitHubConnector({
...
@@ -71,6 +75,7 @@ function ConnectedGitHubConnector({
const
[
showForceDialog
,
setShowForceDialog
]
=
useState
(
false
);
const
[
showForceDialog
,
setShowForceDialog
]
=
useState
(
false
);
const
[
isDisconnecting
,
setIsDisconnecting
]
=
useState
(
false
);
const
[
isDisconnecting
,
setIsDisconnecting
]
=
useState
(
false
);
const
[
disconnectError
,
setDisconnectError
]
=
useState
<
string
|
null
>
(
null
);
const
[
disconnectError
,
setDisconnectError
]
=
useState
<
string
|
null
>
(
null
);
const
autoSyncTriggeredRef
=
useRef
(
false
);
const
handleDisconnectRepo
=
async
()
=>
{
const
handleDisconnectRepo
=
async
()
=>
{
setIsDisconnecting
(
true
);
setIsDisconnecting
(
true
);
...
@@ -85,32 +90,51 @@ function ConnectedGitHubConnector({
...
@@ -85,32 +90,51 @@ function ConnectedGitHubConnector({
}
}
};
};
const
handleSyncToGithub
=
async
(
force
:
boolean
=
false
)
=>
{
const
handleSyncToGithub
=
useCallback
(
setIsSyncing
(
true
);
async
(
force
:
boolean
=
false
)
=>
{
setSyncError
(
null
);
setIsSyncing
(
true
);
setSyncSuccess
(
false
);
setSyncError
(
null
);
setShowForceDialog
(
false
);
setSyncSuccess
(
false
);
setShowForceDialog
(
false
);
try
{
try
{
const
result
=
await
IpcClient
.
getInstance
().
syncGithubRepo
(
appId
,
force
);
const
result
=
await
IpcClient
.
getInstance
().
syncGithubRepo
(
if
(
result
.
success
)
{
appId
,
setSyncSuccess
(
true
);
force
,
}
else
{
);
setSyncError
(
result
.
error
||
"Failed to sync to GitHub."
);
if
(
result
.
success
)
{
// If it's a push rejection error, show the force dialog
setSyncSuccess
(
true
);
if
(
}
else
{
result
.
error
?.
includes
(
"rejected"
)
||
setSyncError
(
result
.
error
||
"Failed to sync to GitHub."
);
result
.
error
?.
includes
(
"non-fast-forward"
)
// If it's a push rejection error, show the force dialog
)
{
if
(
// Don't show force dialog immediately, let user see the error first
result
.
error
?.
includes
(
"rejected"
)
||
result
.
error
?.
includes
(
"non-fast-forward"
)
)
{
// Don't show force dialog immediately, let user see the error first
}
}
}
}
catch
(
err
:
any
)
{
setSyncError
(
err
.
message
||
"Failed to sync to GitHub."
);
}
finally
{
setIsSyncing
(
false
);
}
}
}
catch
(
err
:
any
)
{
},
setSyncError
(
err
.
message
||
"Failed to sync to GitHub."
);
[
appId
],
}
finally
{
);
setIsSyncing
(
false
);
// Auto-sync when triggerAutoSync prop is true
useEffect
(()
=>
{
if
(
triggerAutoSync
&&
!
autoSyncTriggeredRef
.
current
)
{
autoSyncTriggeredRef
.
current
=
true
;
handleSyncToGithub
(
false
).
finally
(()
=>
{
onAutoSyncComplete
?.();
});
}
else
if
(
!
triggerAutoSync
)
{
// Reset the ref when triggerAutoSync becomes false
autoSyncTriggeredRef
.
current
=
false
;
}
}
}
;
}
,
[
triggerAutoSync
]);
// Only depend on triggerAutoSync to avoid unnecessary re-runs
return
(
return
(
<
div
className=
"w-full"
data
-
testid=
"github-connected-repo"
>
<
div
className=
"w-full"
data
-
testid=
"github-connected-repo"
>
...
@@ -268,7 +292,7 @@ function UnconnectedGitHubConnector({
...
@@ -268,7 +292,7 @@ function UnconnectedGitHubConnector({
folderName
,
folderName
,
settings
,
settings
,
refreshSettings
,
refreshSettings
,
refreshApp
,
handleRepoSetupComplete
,
expanded
,
expanded
,
}:
UnconnectedGitHubConnectorProps
)
{
}:
UnconnectedGitHubConnectorProps
)
{
// --- Collapsible State ---
// --- Collapsible State ---
...
@@ -516,9 +540,10 @@ function UnconnectedGitHubConnector({
...
@@ -516,9 +540,10 @@ function UnconnectedGitHubConnector({
appId
,
appId
,
);
);
}
}
setCreateRepoSuccess
(
true
);
setCreateRepoSuccess
(
true
);
setRepoCheckError
(
null
);
setRepoCheckError
(
null
);
refreshApp
();
handleRepoSetupComplete
();
}
catch
(
err
:
any
)
{
}
catch
(
err
:
any
)
{
setCreateRepoError
(
setCreateRepoError
(
err
.
message
||
err
.
message
||
...
@@ -882,6 +907,16 @@ export function GitHubConnector({
...
@@ -882,6 +907,16 @@ export function GitHubConnector({
}:
GitHubConnectorProps
)
{
}:
GitHubConnectorProps
)
{
const
{
app
,
refreshApp
}
=
useLoadApp
(
appId
);
const
{
app
,
refreshApp
}
=
useLoadApp
(
appId
);
const
{
settings
,
refreshSettings
}
=
useSettings
();
const
{
settings
,
refreshSettings
}
=
useSettings
();
const
[
pendingAutoSync
,
setPendingAutoSync
]
=
useState
(
false
);
const
handleRepoSetupComplete
=
useCallback
(()
=>
{
setPendingAutoSync
(
true
);
refreshApp
();
},
[
refreshApp
]);
const
handleAutoSyncComplete
=
useCallback
(()
=>
{
setPendingAutoSync
(
false
);
},
[]);
if
(
app
?.
githubOrg
&&
app
?.
githubRepo
&&
appId
)
{
if
(
app
?.
githubOrg
&&
app
?.
githubRepo
&&
appId
)
{
return
(
return
(
...
@@ -889,6 +924,8 @@ export function GitHubConnector({
...
@@ -889,6 +924,8 @@ export function GitHubConnector({
appId=
{
appId
}
appId=
{
appId
}
app=
{
app
}
app=
{
app
}
refreshApp=
{
refreshApp
}
refreshApp=
{
refreshApp
}
triggerAutoSync=
{
pendingAutoSync
}
onAutoSyncComplete=
{
handleAutoSyncComplete
}
/>
/>
);
);
}
else
{
}
else
{
...
@@ -898,7 +935,7 @@ export function GitHubConnector({
...
@@ -898,7 +935,7 @@ export function GitHubConnector({
folderName=
{
folderName
}
folderName=
{
folderName
}
settings=
{
settings
}
settings=
{
settings
}
refreshSettings=
{
refreshSettings
}
refreshSettings=
{
refreshSettings
}
refreshApp=
{
refreshApp
}
handleRepoSetupComplete=
{
handleRepoSetupComplete
}
expanded=
{
expanded
}
expanded=
{
expanded
}
/>
/>
);
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论