-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.py
More file actions
54 lines (43 loc) · 1.6 KB
/
memory.py
File metadata and controls
54 lines (43 loc) · 1.6 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
46
47
48
49
50
51
52
53
54
import json
import os
MEMORY_FILE = "memory.json" #varianle storing filename
def load_memory() -> dict:
if not os.path.exists(MEMORY_FILE):
return {}
with open(MEMORY_FILE, "r") as f:
# open the JSON file and returns a dictionary
return json.load(f)
def save_memory(data: dict):
try:
# save the data in memory
with open("memory.json", "w") as f:
json.dump(data, f)
except Exception as e:
raise RuntimeError(f"Failed to save memory: {e}")
def mark_triaged(issue_number: int) -> None:
try:
key = str(issue_number)
memory_dict=load_memory()
if key not in memory_dict:
memory_dict[key] = {"triaged": True, "actions": []}
else:
memory_dict[key]["triaged"] = True
save_memory(memory_dict)
except Exception as e:
raise RuntimeError(f"failed to add issue: {e}")
def is_triaged(issue_number: int) -> bool:
key = str(issue_number)
memory_dict=load_memory()
return key in memory_dict and memory_dict[key].get("triaged", False)
def log_action(issue_number: int, action: str):
key = str(issue_number)
try:
memory_dict=load_memory()
if key not in memory_dict:
memory_dict[key] = {"triaged": False, "actions": []}
actions: list = memory_dict[key]["actions"]# get the list of actions for that issue, if not return an empty list
actions.append(action)
memory_dict[key]["actions"] = actions
save_memory(memory_dict)
except Exception as e:
raise RuntimeError(f"failed to log action: {e}")