#!/usr/bin/env python3
"""
Demo script showing GitHub β Radicle synchronization functionality.
"""
import asyncio
import os
import sys
from datetime import datetime
async def demo_sync():
"""Demonstrate sync functionality."""
print("π― GitHub β Radicle Synchronization Demo")
print("=" * 50)
# Check environment
github_token = os.getenv("GITHUB_PERSONAL_ACCESS_TOKEN")
if not github_token:
print("β Missing GITHUB_PERSONAL_ACCESS_TOKEN environment variable")
print("π To set it up:")
print(" 1. Go to GitHub Settings > Developer settings > Personal access tokens")
print(" 2. Generate a new token with 'repo' and 'issues' permissions")
print(" 3. Export it: export GITHUB_PERSONAL_ACCESS_TOKEN=your_token_here")
print("\nβ οΈ Running in demo mode without actual sync...")
# Show dry-run information
print("\nπ What would be synced (dry-run):")
print(" β GitHub issues β Radicle issues")
print(" β Radicle issues β GitHub issues")
print(" β GitHub PRs β Radicle patches (limited)")
print(" β Radicle patches β GitHub PRs (limited)")
print("\nπ‘ Key features:")
print(" β’ Idempotent operations (safe to run multiple times)")
print(" β’ Mapping database tracks GitHub/Radicle ID relationships")
print(" β’ Preserves original metadata and links")
print(" β’ Respects existing mappings to avoid duplication")
return
# Test with actual sync
try:
from github_radicle_sync import GitHubRadicleSyncer
github_repo = "fovi-llc/radicle-mcp"
print(f"π Testing sync with repository: {github_repo}")
print(f"π Token: {'*' * 8}...{github_token[-4:]}")
syncer = GitHubRadicleSyncer(github_token, github_repo)
print("\nπ Testing connectivity...")
# Test GitHub connectivity
github_issues = syncer.github.get_issues()
print(f"β
GitHub: Found {len(github_issues)} issues")
github_prs = syncer.github.get_pull_requests()
print(f"β
GitHub: Found {len(github_prs)} pull requests")
# Test Radicle connectivity
radicle_issues = await syncer.radicle.get_issues()
print(f"β
Radicle: Found {len(radicle_issues)} issues")
radicle_patches = await syncer.radicle.get_patches()
print(f"β
Radicle: Found {len(radicle_patches)} patches")
# Show current mappings
issue_mappings = len(syncer.db.data.get('issues', {}))
patch_mappings = len(syncer.db.data.get('patches', {}))
last_sync = syncer.db.data.get('last_sync', 'Never')
print(f"\nπ Current sync state:")
print(f" Issue mappings: {issue_mappings}")
print(f" Patch mappings: {patch_mappings}")
print(f" Last sync: {last_sync}")
# Ask user if they want to perform actual sync
print("\nπ€ Would you like to perform an actual sync? (y/N): ", end="")
response = input().strip().lower()
if response in ['y', 'yes']:
print("\nπ Performing sync...")
results = await syncer.sync_all()
print("\nπ Sync Results:")
print(f" Issues GitHub β Radicle: {results['issues_gh_to_rad']}")
print(f" Issues Radicle β GitHub: {results['issues_rad_to_gh']}")
print(f" Patches GitHub β Radicle: {results['patches_gh_to_rad']}")
print(f" Patches Radicle β GitHub: {results['patches_rad_to_gh']}")
print(f"\nπ Sync completed at {datetime.now().isoformat()}")
else:
print("\nβ
Demo completed (no sync performed)")
except ImportError:
print("β github_radicle_sync module not available")
print("Make sure all dependencies are installed")
except Exception as e:
print(f"β Error during demo: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
asyncio.run(demo_sync())