From 3206363a8858182aefe887832a8247bc0a18dc7e Mon Sep 17 00:00:00 2001 From: bartool Date: Fri, 6 Mar 2026 21:03:34 +0100 Subject: [PATCH] feat: use interactive notifications in file watcher with deferral support --- git_monitor/file_watcher.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/git_monitor/file_watcher.py b/git_monitor/file_watcher.py index f3c3281..836d6b9 100644 --- a/git_monitor/file_watcher.py +++ b/git_monitor/file_watcher.py @@ -1,9 +1,11 @@ import time import os +import threading from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler from git_monitor.logger import logger from git_monitor.git_manager import git_manager +from git_monitor.notifier import notifier class RepositoryWatcher: def __init__(self, path): @@ -43,27 +45,35 @@ class GitEventHandler(FileSystemEventHandler): self.handle_event(event, action, custom_file_name=file_name) def handle_event(self, event, action, custom_file_name=None): - # Ignore .git directory and the log file file_path = event.src_path if action != "rename" else event.dest_path file_name = os.path.basename(file_path) - # Check if any part of the path is .git or if it's the log file if ".git" in file_path.split(os.sep) or file_name == "git_monitor.log": return - # NEW: Respect .gitignore if git_manager.is_ignored(file_path): logger.info(f"Ignored: {file_path} (matches .gitignore)") return display_name = custom_file_name if custom_file_name else file_name - logger.info(f"File event: {action} on {display_name}") - + logger.info(f"Change detected: {action} on {display_name}") + repo_root = git_manager.repo_path if repo_root: - if custom_file_name: - # For renames, we use the custom format provided - git_manager.commit_change(action, custom_file_name) - else: - rel_path = os.path.relpath(file_path, repo_root) + rel_path = os.path.relpath(file_path, repo_root) if not custom_file_name else custom_file_name + + # Interactive notification instead of immediate commit + def save_now(): git_manager.commit_change(action, rel_path) + + def ask_later(): + logger.info(f"User deferred change: {rel_path} for 5 minutes.") + # Reschedule the same event after 5 minutes (300 seconds) + threading.Timer(300, self.handle_event, [event, action, custom_file_name]).start() + + notifier.notify_interactive( + "Zmiana wykryta!", + f"Wykryto zmianę: {action}: {display_name}. Co chcesz zrobić?", + on_save=save_now, + on_later=ask_later + )