gitlab feature start

This commit is contained in:
Tim Bendt
2025-11-05 08:56:31 -05:00
parent c46d53b261
commit 73079f743a
11 changed files with 779 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ from .email import email
from .calendar import calendar
from .ticktick import ticktick
from .godspeed import godspeed
from .gitlab_monitor import gitlab_monitor
@click.group()
@@ -22,8 +23,11 @@ cli.add_command(email)
cli.add_command(calendar)
cli.add_command(ticktick)
cli.add_command(godspeed)
cli.add_command(gitlab_monitor)
# Add 'tt' as a short alias for ticktick
cli.add_command(ticktick, name="tt")
# Add 'gs' as a short alias for godspeed
cli.add_command(godspeed, name="gs")
# Add 'glm' as a short alias for gitlab_monitor
cli.add_command(gitlab_monitor, name="glm")

View File

@@ -1,9 +1,12 @@
import click
import subprocess
import os
@click.command()
def drive():
"""View OneDrive files."""
click.echo("Launching OneDrive viewer...")
subprocess.run(["python3", "src/drive_view_tui.py"])
# Get the directory containing this file, then go up to project root
current_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
subprocess.run(["python3", "drive_view_tui.py"], cwd=current_dir)

152
src/cli/gitlab_monitor.py Normal file
View File

@@ -0,0 +1,152 @@
import click
import asyncio
import os
import signal
import subprocess
import sys
from pathlib import Path
@click.group()
def gitlab_monitor():
"""GitLab pipeline monitoring daemon."""
pass
@gitlab_monitor.command()
@click.option("--config", help="Path to configuration file")
@click.option("--daemon", "-d", is_flag=True, help="Run in background as daemon")
def start(config, daemon):
"""Start the GitLab pipeline monitoring daemon."""
daemon_path = os.path.join(
os.path.dirname(__file__), "..", "services", "gitlab_monitor", "daemon.py"
)
if daemon:
# Run as background daemon
click.echo("Starting GitLab pipeline monitor daemon in background...")
cmd = [sys.executable, daemon_path]
if config:
cmd.extend(["--config", config])
# Create pid file
pid_file = os.path.expanduser("~/.config/gtd-tools/gitlab_monitor.pid")
Path(pid_file).parent.mkdir(parents=True, exist_ok=True)
# Start daemon process
process = subprocess.Popen(
cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
preexec_fn=os.setsid,
)
# Save PID
with open(pid_file, "w") as f:
f.write(str(process.pid))
click.echo(f"Daemon started with PID {process.pid}")
click.echo(f"PID file: {pid_file}")
else:
# Run in foreground
click.echo("Starting GitLab pipeline monitor (press Ctrl+C to stop)...")
# Import and run the daemon
from src.services.gitlab_monitor.daemon import main
asyncio.run(main())
@gitlab_monitor.command()
def stop():
"""Stop the GitLab pipeline monitoring daemon."""
pid_file = os.path.expanduser("~/.config/gtd-tools/gitlab_monitor.pid")
if not os.path.exists(pid_file):
click.echo("Daemon is not running (no PID file found)")
return
try:
with open(pid_file, "r") as f:
pid = int(f.read().strip())
# Send SIGTERM to process group
os.killpg(os.getpgid(pid), signal.SIGTERM)
# Remove PID file
os.unlink(pid_file)
click.echo(f"Daemon stopped (PID {pid})")
except (ValueError, ProcessLookupError, OSError) as e:
click.echo(f"Error stopping daemon: {e}")
# Clean up stale PID file
if os.path.exists(pid_file):
os.unlink(pid_file)
@gitlab_monitor.command()
def status():
"""Check the status of the GitLab pipeline monitoring daemon."""
pid_file = os.path.expanduser("~/.config/gtd-tools/gitlab_monitor.pid")
if not os.path.exists(pid_file):
click.echo("Daemon is not running")
return
try:
with open(pid_file, "r") as f:
pid = int(f.read().strip())
# Check if process exists
os.kill(pid, 0) # Send signal 0 to check if process exists
click.echo(f"Daemon is running (PID {pid})")
except (ValueError, ProcessLookupError, OSError):
click.echo("Daemon is not running (stale PID file)")
# Clean up stale PID file
os.unlink(pid_file)
@gitlab_monitor.command()
@click.option("--config", help="Path to configuration file")
def test(config):
"""Test the configuration and dependencies."""
from src.services.gitlab_monitor.daemon import GitLabPipelineMonitor
monitor = GitLabPipelineMonitor(config)
click.echo("Configuration test:")
click.echo(
f"GitLab token configured: {'' if monitor.config.get_gitlab_token() else ''}"
)
click.echo(
f"OpenAI key configured: {'' if monitor.config.get_openai_key() else ''}"
)
click.echo(f"Subject patterns: {monitor.config.get_subject_patterns()}")
click.echo(f"Sender patterns: {monitor.config.get_sender_patterns()}")
click.echo(f"Check interval: {monitor.config.get_check_interval()}s")
click.echo(f"Config file: {monitor.config.config_path}")
@gitlab_monitor.command()
def config():
"""Show the current configuration file path and create default if needed."""
from src.services.gitlab_monitor.config import GitLabMonitorConfig
config = GitLabMonitorConfig()
click.echo(f"Configuration file: {config.config_path}")
if os.path.exists(config.config_path):
click.echo("Configuration file exists")
else:
click.echo("Default configuration file created")
click.echo("\nTo configure the daemon:")
click.echo("1. Set environment variables:")
click.echo(" export GITLAB_API_TOKEN='your_gitlab_token'")
click.echo(" export OPENAI_API_KEY='your_openai_key'")
click.echo("2. Or edit the configuration file directly")
if __name__ == "__main__":
gitlab_monitor()