Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot only reports moving to trash_bin when relevant #292

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions eessi_bot_event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,33 +636,37 @@ def handle_pull_request_closed_event(self, event_info, pr):
self.log(f"PR {pr.number}: determining directories to be moved to trash bin")
job_dirs = determine_job_dirs(pr.number)

# 2) Get trash_bin_dir from configs
trash_bin_root_dir = self.cfg[config.SECTION_CLEAN_UP][config.CLEAN_UP_SETTING_TRASH_BIN_ROOT_DIR]

repo_name = request_body['repository']['full_name']
dt_start = datetime.now(timezone.utc)
trash_bin_dir = "/".join([trash_bin_root_dir, repo_name, dt_start.strftime('%Y.%m.%d')])

# Subdirectory with date of move. Also with repository name. Handle symbolic links (later?)
# cron job deletes symlinks?

# 3) move the directories to the trash_bin
self.log(f"PR {pr.number}: moving directories to trash bin {trash_bin_dir}")
move_to_trash_bin(trash_bin_dir, job_dirs)
dt_end = datetime.now(timezone.utc)
dt_delta = dt_end - dt_start
seconds_elapsed = dt_delta.days * 24 * 3600 + dt_delta.seconds
self.log(f"PR {pr.number}: moved directories to trash bin {trash_bin_dir} (took {seconds_elapsed} seconds)")
if job_dirs == []:
self.log(f"PR {pr.number}: No job directories found; nothing to move.")
else:
# 2) Get trash_bin_dir from configs
trash_bin_root_dir = self.cfg[config.SECTION_CLEAN_UP][config.CLEAN_UP_SETTING_TRASH_BIN_ROOT_DIR]

# 4) report move to pull request
repo_name = pr.base.repo.full_name
gh = github.get_instance()
repo = gh.get_repo(repo_name)
pull_request = repo.get_pull(pr.number)
clean_up_comment = self.cfg[config.SECTION_CLEAN_UP][config.CLEAN_UP_SETTING_MOVED_JOB_DIRS_COMMENT]
moved_comment = clean_up_comment.format(job_dirs=job_dirs, trash_bin_dir=trash_bin_dir)
issue_comment = pull_request.create_issue_comment(moved_comment)
return issue_comment
repo_name = request_body['repository']['full_name']
dt_start = datetime.now(timezone.utc)
trash_bin_dir = "/".join([trash_bin_root_dir, repo_name, dt_start.strftime('%Y.%m.%d')])

# Subdirectory with date of move. Also with repository name. Handle symbolic links (later?)
# cron job deletes symlinks?

# 3) move the directories to the trash_bin
self.log(f"PR {pr.number}: moving directories to trash bin {trash_bin_dir}")
move_to_trash_bin(trash_bin_dir, job_dirs)
dt_end = datetime.now(timezone.utc)
dt_delta = dt_end - dt_start
seconds_elapsed = dt_delta.days * 24 * 3600 + dt_delta.seconds
self.log(f"PR {pr.number}: moved directories to trash bin {trash_bin_dir} (took {seconds_elapsed} seconds)")

# 4) report move to pull request

repo_name = pr.base.repo.full_name
gh = github.get_instance()
repo = gh.get_repo(repo_name)
pull_request = repo.get_pull(pr.number)
clean_up_comment = self.cfg[config.SECTION_CLEAN_UP][config.CLEAN_UP_SETTING_MOVED_JOB_DIRS_COMMENT]
moved_comment = clean_up_comment.format(job_dirs=job_dirs, trash_bin_dir=trash_bin_dir)
issue_comment = pull_request.create_issue_comment(moved_comment)
return issue_comment


def main():
Expand Down