-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_db.py
More file actions
45 lines (36 loc) · 1.66 KB
/
patch_db.py
File metadata and controls
45 lines (36 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import re
filepath = "/home/citec/.openclaw/workspace/skills/patch-review/os/linux-v2/patch_preprocessing.py"
with open(filepath, "r", encoding="utf-8") as f:
code = f.read()
# Replace the entire Step 4 block
step_4_regex = r"# --- Step 4: Save to SQLite Database .*?print\(f\"\[DB SUCCESS\].*?}\"\)"
# Actually, I can use a simpler replacement
old_code_start = """ # Fetch the set of already-stored issueIds to avoid duplicates
cursor.execute('DELETE FROM PreprocessedPatch')
existing_ids = {row[0] for row in cursor.fetchall()}
for p in final_candidates:
issue_id = p.get('id', 'Unknown')
if issue_id in existing_ids:
skipped += 1
continue"""
new_code = """ cursor.execute('DELETE FROM PreprocessedPatch')
existing_ids = set()
for p in final_candidates:
issue_id = p.get('id', 'Unknown')"""
if old_code_start in code:
code = code.replace(old_code_start, new_code)
else:
# Try the original
orig_code_start = """ # Fetch the set of already-stored issueIds to avoid duplicates
cursor.execute('SELECT issueId FROM PreprocessedPatch')
existing_ids = {row[0] for row in cursor.fetchall()}
for p in final_candidates:
issue_id = p.get('id', 'Unknown')
if issue_id in existing_ids:
skipped += 1
continue"""
if orig_code_start in code:
code = code.replace(orig_code_start, new_code)
with open(filepath, "w", encoding="utf-8") as f:
f.write(code)
print("Patched DB logic!")