@@ -197,13 +197,31 @@ def ensure_repo_clone():
197
197
run_command (["git" , "reset" , "--hard" , "origin/main" ], cwd = str (REPO_CLONE_DIR ))
198
198
199
199
200
+ def check_existing_pr (repo , branch_name ):
201
+ logger .info (f"Checking for existing PR for branch: { branch_name } " )
202
+ existing_prs = repo .get_pulls (state = 'open' , head = f"{ FORK_OWNER } :{ branch_name } " )
203
+ return next (existing_prs , None )
204
+
205
+
200
206
def create_revert_pr (commit_sha , builder , failing_build ):
201
207
logger .info (f"Creating revert PR for commit: { commit_sha } " )
202
208
g = Github (GITHUB_TOKEN )
203
209
204
210
try :
205
211
main_repo = g .get_repo (f"{ REPO_OWNER } /{ REPO_NAME } " )
206
212
213
+ branch_name = f"revert-{ commit_sha [:7 ]} "
214
+
215
+ # Check for existing PR
216
+ existing_pr = check_existing_pr (main_repo , branch_name )
217
+ if existing_pr :
218
+ logger .info (f"Existing PR found: { existing_pr .html_url } " )
219
+ return None , None
220
+
221
+ with FileLock (LOCK_FILE ):
222
+ ensure_repo_clone ()
223
+
224
+
207
225
with FileLock (LOCK_FILE ):
208
226
ensure_repo_clone ()
209
227
@@ -215,7 +233,6 @@ def create_revert_pr(commit_sha, builder, failing_build):
215
233
cwd = str (REPO_CLONE_DIR ),
216
234
)
217
235
218
- branch_name = f"revert-{ commit_sha [:7 ]} "
219
236
run_command (["git" , "checkout" , "-b" , branch_name ], cwd = str (REPO_CLONE_DIR ))
220
237
logger .info (f"Created and checked out new branch: { branch_name } " )
221
238
@@ -322,7 +339,7 @@ async def process_builder(session, builder, first_failing_build):
322
339
pr_url , discord_message = create_revert_pr (
323
340
commit_sha , builder , first_failing_build
324
341
)
325
- if pr_url :
342
+ if pr_url and discord_message :
326
343
logger .info (f"Created revert PR for commit { commit_sha } : { pr_url } " )
327
344
await send_discord_notification (session , discord_message )
328
345
else :
0 commit comments