@@ -208,16 +208,24 @@ async def ensure_issue_plugin_test_button_in_progress(handler: IssueHandler):
208208async def process_pull_request (
209209 handler : IssueHandler , result : ValidationDict , branch_name : str , title : str
210210):
211- """
212- 根据发布信息合法性创建拉取请求或将请求改为草稿
213- """
214- if result .valid :
215- commit_message = f"{ COMMIT_MESSAGE_PREFIX } { result .type .value .lower ()} { result .name } (#{ handler .issue_number } )"
211+ """根据发布信息合法性创建拉取请求或将请求改为草稿"""
212+ if not result .valid :
213+ # 如果之前已经创建了拉取请求,则将其转换为草稿
214+ await handler .draft_pull_request (branch_name )
215+ return
216+
217+ # 更新文件
218+ handler .switch_branch (branch_name )
219+ update_file (result )
216220
217- handler .switch_branch (branch_name )
218- # 更新文件
219- update_file (result )
220- handler .commit_and_push (commit_message , branch_name , handler .author )
221+ # 只有当远程分支不存在时才创建拉取请求
222+ # 需要在 commit_and_push 前判断,否则远程一定存在
223+ remote_branch_exists = handler .remote_branch_exists (branch_name )
224+
225+ commit_message = f"{ COMMIT_MESSAGE_PREFIX } { result .type .value .lower ()} { result .name } (#{ handler .issue_number } )"
226+ handler .commit_and_push (commit_message , branch_name , handler .author )
227+
228+ if not remote_branch_exists :
221229 # 创建拉取请求
222230 try :
223231 pull_number = await handler .create_pull_request (
@@ -226,13 +234,14 @@ async def process_pull_request(
226234 branch_name ,
227235 )
228236 await handler .add_labels (pull_number , [PUBLISH_LABEL , result .type .value ])
237+ return
229238 except RequestFailed :
230- # 如果之前已经创建了拉取请求,则将其转换为草稿
231239 logger .info ("该分支的拉取请求已创建,请前往查看" )
232- await handler .update_pull_request_status (title , branch_name )
233240 else :
234- # 如果之前已经创建了拉取请求,则将其转换为草稿
235- await handler .draft_pull_request (branch_name )
241+ logger .info ("远程分支已存在,跳过创建拉取请求" )
242+
243+ # 如果之前已经创建了拉取请求,则将其转换为可评审
244+ await handler .update_pull_request_status (title , branch_name )
236245
237246
238247async def trigger_registry_update (handler : IssueHandler , publish_type : PublishType ):
0 commit comments