From 283f602d4aefe64a562ee74dbdad150874ae2c37 Mon Sep 17 00:00:00 2001
From: Neves-P
Date: Mon, 1 Jul 2024 15:45:29 +0200
Subject: [PATCH] Also move pr event dirs
---
eessi_bot_event_handler.py | 3 ++-
tasks/clean_up.py | 10 ++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/eessi_bot_event_handler.py b/eessi_bot_event_handler.py
index 51134e3..8523089 100644
--- a/eessi_bot_event_handler.py
+++ b/eessi_bot_event_handler.py
@@ -17,6 +17,7 @@
#
# Standard library imports
+import os
import sys
from datetime import datetime, timezone
@@ -639,7 +640,7 @@ def handle_pull_request_closed_event(self, event_info, pr):
repo_name = request_body['repository']['full_name']
dt = datetime.now(timezone.utc)
- trash_bin_dir = "/".join([trash_bin_root_dir, repo_name, dt.strftime('%Y%m.%d')])
+ trash_bin_dir = "/".join([trash_bin_root_dir, repo_name, dt.strftime('%Y.%m.%d')])
# Subdirectory with date of move. Also with repository name. Handle symbolic links (later?)
# cron job deletes symlinks?
diff --git a/tasks/clean_up.py b/tasks/clean_up.py
index 96b3b0c..8a28a97 100644
--- a/tasks/clean_up.py
+++ b/tasks/clean_up.py
@@ -35,7 +35,17 @@ def move_to_trash_bin(trash_bin_dir, job_dirs):
log(f"{funcname}(): trash_bin_dir = {trash_bin_dir}")
os.makedirs(trash_bin_dir, exist_ok=True)
+ pr_dirs = []
for job_dir in job_dirs:
destination_dir = shutil.move(job_dir, trash_bin_dir)
log(f"{funcname}(): moved {job_dir} to {destination_dir}")
+ # Save upper directory above to remove later (pr_xx)
+ pr_dirs = os.path.dirname(job_dir)
+
+ # Remove event_xxx-yyy/run_nnn/ directories
+ pr_dirs = list(set(pr_dirs))
+ for pr_dir in pr_dirs:
+ destination_dir = shutil.move(pr_dir, trash_bin_dir)
+ log(f"{funcname}(): moved {pr_dir} to {destination_dir}")
+
return True