From 7a7e35bcf5ec03f1d66d913a4545f2ce64f94810 Mon Sep 17 00:00:00 2001 From: Matt Van Horn Date: Tue, 3 Feb 2026 11:02:28 -0800 Subject: [PATCH] feat(main): add Bird setup function Add bird_x import and setup_bird_if_needed function to main script. The function checks Bird status and offers installation if needed, returning 'bird' if ready, 'declined' if user declined, or None if unavailable. Co-Authored-By: Claude Opus 4.5 --- scripts/last30days.py | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/scripts/last30days.py b/scripts/last30days.py index 64c41a2..2786949 100644 --- a/scripts/last30days.py +++ b/scripts/last30days.py @@ -26,7 +26,10 @@ from pathlib import Path SCRIPT_DIR = Path(__file__).parent.resolve() sys.path.insert(0, str(SCRIPT_DIR)) +from typing import Optional + from lib import ( + bird_x, dates, dedupe, env, @@ -44,6 +47,47 @@ from lib import ( ) +def setup_bird_if_needed(progress: ui.ProgressDisplay) -> Optional[str]: + """Check Bird status and offer installation if needed. + + Returns: + 'bird' if Bird is ready to use, + 'declined' if user declined install, + None if Bird not available and couldn't be installed. + """ + status = bird_x.get_bird_status() + + # Already working + if status["authenticated"]: + return 'bird' + + # Installed but not authenticated + if status["installed"]: + progress.show_bird_auth_help() + return None + + # Not installed - offer to install if npm available + if status["can_install"]: + if progress.prompt_bird_install(): + success, message = bird_x.install_bird() + if success: + # Check if auth works now + username = bird_x.is_bird_authenticated() + if username: + progress.show_bird_install_success(username) + return 'bird' + else: + progress.show_bird_auth_help() + return None + else: + progress.show_bird_install_failed(message) + return None + else: + return 'declined' + + return None + + def load_fixture(name: str) -> dict: """Load a fixture file.""" fixture_path = SCRIPT_DIR.parent / "fixtures" / name