fix: read snapshot of tracked file and close it afterwards

We were writing to the file as the file was opened in read mode. This
lead to PRs not being removed after first time notified.
This commit is contained in:
2026-06-12 15:19:50 +02:00
parent 276b61aeca
commit 9af4538e1e
+32 -7
View File
@@ -232,21 +232,46 @@ def main():
if pr: if pr:
print(" " + str(pr) + " " + getPRTitle(pr)) print(" " + str(pr) + " " + getPRTitle(pr))
elif sys.argv[1] == "listen": elif sys.argv[1] == "listen":
while True: while True:
try:
if trackedPRFile.exists(): if trackedPRFile.exists():
# Read a snapshot of the file first so we don't modify
# tracked.txt while iterating over it.
with trackedPRFile.open("r") as f: with trackedPRFile.open("r") as f:
tracked_prs = []
for line in f: for line in f:
PR = int(line.strip()) line = line.strip()
if fetchStatus(PR) == "accepted": if not line:
continue
tracked_prs.append(int(line))
for PR in tracked_prs:
try:
status = fetchStatus(PR)
if status == "accepted":
print(f"PR #{PR} accepted")
if shouldLocalNotify: if shouldLocalNotify:
localNotify(PR) localNotify(PR)
if shouldMatrixNotify: if shouldMatrixNotify:
matrixNotify(PR) matrixNotify(PR)
removeTracker(PR) removeTracker(PR)
sleep(configFetchTime) # avoids to send request to quickly to the website print(f"Removed PR #{PR} from tracking")
sleep(configTime)
except Exception as e:
print(
f"Failed to process PR #{PR}: {e}"
)
# Avoid hammering the tracker website
sleep(configFetchTime)
except Exception as e:
print(f"Listener loop error: {e}")
sleep(configTime)
else: else:
print("Unknown argument \"" + sys.argv[1] + "\"\nAccepted arguments are:\n add\n remove or rm\n list or ls\n listen") print("Unknown argument \"" + sys.argv[1] + "\"\nAccepted arguments are:\n add\n remove or rm\n list or ls\n listen")