demo_sync.pyā¢4.23 kB
#!/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())