169 lines
5.2 KiB
Python
169 lines
5.2 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
|
||
"""
|
||
快速测试评论同步功能
|
||
专门测试Gitee → GitLink的Issue和评论同步
|
||
"""
|
||
|
||
import sys
|
||
import os
|
||
|
||
# 添加项目根目录到路径
|
||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '.'))
|
||
|
||
from clients.sync_service import IssueSyncService
|
||
from clients.gitee_client import GiteeIssueClient
|
||
|
||
import logging
|
||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||
logger = logging.getLogger(__name__)
|
||
|
||
|
||
def test_gitee_comments_for_specific_issue():
|
||
"""测试指定Issue的Gitee评论获取"""
|
||
print("\n" + "="*60)
|
||
print("🔍 检查Gitee Issue评论")
|
||
print("="*60)
|
||
|
||
try:
|
||
gitee_client = GiteeIssueClient("ttk00", "testdemo")
|
||
|
||
# 查找gitee_gitlink_testissue
|
||
target_issue_title = "gitee_gitlink_testissue"
|
||
target_issue = gitee_client.find_issue_by_title(target_issue_title)
|
||
|
||
if not target_issue:
|
||
print(f"❌ 未找到Issue: {target_issue_title}")
|
||
return False
|
||
|
||
issue_number = target_issue['number']
|
||
print(f"✅ 找到Issue: #{issue_number} - {target_issue_title}")
|
||
|
||
# 获取评论
|
||
comments = gitee_client.get_issue_comments(issue_number)
|
||
print(f"📋 Issue #{issue_number} 有 {len(comments)} 条评论")
|
||
|
||
for i, comment in enumerate(comments[:3], 1): # 只显示前3条
|
||
comment_body = comment.get('body', '')[:100]
|
||
author = comment.get('user', {}).get('login', 'Unknown')
|
||
created_at = comment.get('created_at', '')
|
||
print(f" {i}. @{author} 于 {created_at[:19]}: {comment_body}...")
|
||
|
||
return len(comments) > 0
|
||
|
||
except Exception as e:
|
||
print(f"❌ 检查Gitee评论失败: {str(e)}")
|
||
return False
|
||
|
||
|
||
def test_sync_with_comments():
|
||
"""测试带评论同步的Issue同步"""
|
||
print("\n" + "="*60)
|
||
print("🔄 测试Gitee → GitLink Issue和评论同步")
|
||
print("="*60)
|
||
|
||
try:
|
||
sync_service = IssueSyncService()
|
||
|
||
print("开始同步(包含评论)...")
|
||
result = sync_service.sync_gitee_to_gitlink(
|
||
gitee_org="ttk00",
|
||
gitee_repo="testdemo",
|
||
gitlink_org="qinxinqi",
|
||
gitlink_repo="testdemo",
|
||
sync_comments=True # 启用评论同步
|
||
)
|
||
|
||
if result:
|
||
print("✅ 带评论的Issue同步成功!")
|
||
return True
|
||
else:
|
||
print("❌ 带评论的Issue同步失败")
|
||
return False
|
||
|
||
except Exception as e:
|
||
print(f"❌ 同步测试失败: {str(e)}")
|
||
return False
|
||
|
||
|
||
def test_sync_without_comments():
|
||
"""测试不带评论同步的Issue同步(对比)"""
|
||
print("\n" + "="*60)
|
||
print("🔄 测试Gitee → GitLink Issue同步(不包含评论)")
|
||
print("="*60)
|
||
|
||
try:
|
||
sync_service = IssueSyncService()
|
||
|
||
print("开始同步(不包含评论)...")
|
||
result = sync_service.sync_gitee_to_gitlink(
|
||
gitee_org="ttk00",
|
||
gitee_repo="testdemo",
|
||
gitlink_org="qinxinqi",
|
||
gitlink_repo="testdemo",
|
||
sync_comments=False # 禁用评论同步
|
||
)
|
||
|
||
if result:
|
||
print("✅ 仅Issue同步成功(评论未同步)")
|
||
return True
|
||
else:
|
||
print("❌ Issue同步失败")
|
||
return False
|
||
|
||
except Exception as e:
|
||
print(f"❌ 同步测试失败: {str(e)}")
|
||
return False
|
||
|
||
|
||
def main():
|
||
"""主测试函数"""
|
||
print("\n" + "🎯" + "="*60)
|
||
print("🎯 快速评论同步功能测试")
|
||
print("🎯" + "="*60)
|
||
|
||
print("\n📋 测试计划:")
|
||
print("1. 检查Gitee中 gitee_gitlink_testissue 的评论")
|
||
print("2. 测试带评论同步的Issue同步")
|
||
print("3. 对比测试不带评论同步的普通同步")
|
||
|
||
tests = [
|
||
("检查Gitee评论", test_gitee_comments_for_specific_issue),
|
||
("带评论同步", test_sync_with_comments),
|
||
("普通同步对比", test_sync_without_comments),
|
||
]
|
||
|
||
results = []
|
||
for test_name, test_func in tests:
|
||
try:
|
||
result = test_func()
|
||
results.append((test_name, result))
|
||
except Exception as e:
|
||
print(f"❌ {test_name} 测试异常: {str(e)}")
|
||
results.append((test_name, False))
|
||
|
||
# 输出测试结果
|
||
print("\n" + "📊" + "="*60)
|
||
print("📊 测试结果汇总")
|
||
print("📊" + "="*60)
|
||
|
||
success_count = 0
|
||
for test_name, result in results:
|
||
status = "✅ 通过" if result else "❌ 失败"
|
||
print(f"{status} {test_name}")
|
||
if result:
|
||
success_count += 1
|
||
|
||
print(f"\n🎯 总体结果: {success_count}/{len(results)} 个测试通过")
|
||
|
||
if success_count >= 2: # 至少评论检查和同步成功
|
||
print("🎉 评论同步功能可以正常使用!")
|
||
print("\n💡 使用方法:")
|
||
print("sync_service.sync_gitee_to_gitlink(..., sync_comments=True)")
|
||
else:
|
||
print("⚠️ 评论同步功能需要进一步调试")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main() |