reposync/issue_sync_module/run_sync.py

123 lines
4.0 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Issue同步模块主入口脚本
用户可以通过此脚本选择不同的同步操作
"""
import sys
import os
# 添加必要的路径
current_dir = os.path.dirname(os.path.abspath(__file__))
clients_dir = os.path.join(current_dir, 'clients')
sys.path.append(clients_dir)
# 添加原项目路径
sys.path.append(os.path.join(os.path.dirname(current_dir), 'src'))
from clients.sync_service import IssueSyncService
def show_menu():
"""显示操作菜单"""
print("=== Issue 同步工具 ===")
print()
print("请选择同步方向:")
print("1. GitLink → GitHub")
print("2. GitHub → GitLink")
print("3. GitLink → Gitee")
print("4. Gitee → GitLink")
print("5. GitHub → Gitee")
print("6. Gitee → GitHub")
print("0. 退出")
print()
return input("请输入选项 (0-6): ").strip()
def get_repo_info():
"""获取仓库信息"""
print("\n请输入仓库信息:")
# 源仓库信息
print("源仓库:")
src_org = input(" 组织/用户名: ").strip()
src_repo = input(" 仓库名: ").strip()
# 目标仓库信息
print("目标仓库:")
dst_org = input(" 组织/用户名: ").strip()
dst_repo = input(" 仓库名: ").strip()
return src_org, src_repo, dst_org, dst_repo
def main():
"""主函数"""
sync_service = IssueSyncService()
while True:
choice = show_menu()
if choice == "0":
print("再见!")
break
elif choice in ["1", "2", "3", "4", "5", "6"]:
# 获取仓库信息
src_org, src_repo, dst_org, dst_repo = get_repo_info()
print(f"\n开始同步 {src_org}/{src_repo}{dst_org}/{dst_repo}")
try:
success = False
if choice == "1": # GitLink → GitHub
success = sync_service.sync_gitlink_to_github(
gitlink_org=src_org, gitlink_repo=src_repo,
github_org=dst_org, github_repo=dst_repo
)
elif choice == "2": # GitHub → GitLink
success = sync_service.sync_github_to_gitlink(
github_org=src_org, github_repo=src_repo,
gitlink_org=dst_org, gitlink_repo=dst_repo
)
elif choice == "3": # GitLink → Gitee
success = sync_service.sync_gitlink_to_gitee(
gitlink_org=src_org, gitlink_repo=src_repo,
gitee_org=dst_org, gitee_repo=dst_repo
)
elif choice == "4": # Gitee → GitLink
success = sync_service.sync_gitee_to_gitlink(
gitee_org=src_org, gitee_repo=src_repo,
gitlink_org=dst_org, gitlink_repo=dst_repo
)
elif choice == "5": # GitHub → Gitee
success = sync_service.sync_github_to_gitee(
github_org=src_org, github_repo=src_repo,
gitee_org=dst_org, gitee_repo=dst_repo
)
elif choice == "6": # Gitee → GitHub
success = sync_service.sync_gitee_to_github(
gitee_org=src_org, gitee_repo=src_repo,
github_org=dst_org, github_repo=dst_repo
)
if success:
print("✅ 同步成功完成!")
else:
print("❌ 同步失败!")
except Exception as e:
print(f"❌ 同步过程中发生错误: {str(e)}")
import traceback
traceback.print_exc()
else:
print("无效选项,请重新输入!")
input("\n按Enter键继续...")
print("\n" + "="*50 + "\n")
if __name__ == "__main__":
main()