reposync/pr_sync_module
张洋 369cd379a7 prtest 2025-07-07 10:15:37 +08:00
..
clients prtest 2025-07-07 10:15:37 +08:00
examples Initial commit 2025-07-05 08:24:22 +08:00
README.md Initial commit 2025-07-05 08:24:22 +08:00
gitee_pr_client.py Your commit message 2025-07-06 22:44:10 +08:00
gitlink_pr_client.py Your commit message 2025-07-06 22:44:10 +08:00
pr_sync_base.py Initial commit 2025-07-05 08:24:22 +08:00
pr_sync_manager.py Your commit message 2025-07-06 22:44:10 +08:00

README.md

PR 同步模块

这个模块提供了在不同代码托管平台之间同步 Pull Request (PR) 的功能。目前支持从 GitLink 同步到 Gitee。

功能特性

  • 支持同步 PR 的基本信息(标题、描述、源分支、目标分支等)
  • 支持同步 PR 的评论
  • 支持同步 PR 的标签
  • 支持同步单个 PR 或批量同步
  • 支持按状态(开放、关闭、全部)筛选要同步的 PR

使用方法

1. 安装依赖

pip install requests

2. 配置令牌

需要配置两个平台的访问令牌:

  • GitLink 令牌:用于访问源仓库
  • Gitee 令牌:用于访问目标仓库

可以通过环境变量或命令行参数提供令牌:

# 通过环境变量
export GITLINK_TOKEN="your_gitlink_token"
export GITEE_TOKEN="your_gitee_token"

# 或者通过命令行参数提供
python examples/sync_gitlink_to_gitee.py --gitlink-token "your_gitlink_token" --gitee-token "your_gitee_token" ...

3. 运行同步

同步所有开放的 PR

python examples/sync_gitlink_to_gitee.py \
    --source "https://gitlink.org.cn/your_org/your_repo" \
    --target "https://gitee.com/your_org/your_repo"

同步特定状态的 PR

python examples/sync_gitlink_to_gitee.py \
    --source "https://gitlink.org.cn/your_org/your_repo" \
    --target "https://gitee.com/your_org/your_repo" \
    --state "all"  # 可选值open, closed, all

同步单个 PR

python examples/sync_gitlink_to_gitee.py \
    --source "https://gitlink.org.cn/your_org/your_repo" \
    --target "https://gitee.com/your_org/your_repo" \
    --pr-number 123

代码结构

  • pr_sync_base.py: 定义了 PR 同步的基础类和数据结构
  • gitlink_pr_client.py: GitLink PR 客户端实现
  • gitee_pr_client.py: Gitee PR 客户端实现
  • pr_sync_manager.py: PR 同步管理器
  • examples/: 示例代码目录
    • sync_gitlink_to_gitee.py: 从 GitLink 同步到 Gitee 的示例脚本

注意事项

  1. 确保提供的仓库地址格式正确:

    • GitLink: https://gitlink.org.cn/org/repogit@code.gitlink.org.cn:org/repo.git
    • Gitee: https://gitee.com/org/repogit@gitee.com:org/repo.git
  2. 确保令牌具有足够的权限:

    • 读取源仓库的 PR、评论和标签
    • 在目标仓库创建和更新 PR、评论和标签
  3. 同步过程中的限制:

    • PR 的标题用于判断是否为同一个 PR
    • 评论会标注原作者信息
    • 部分元数据(如时间戳)可能会更新为同步时的时间

开发计划

  • 支持双向同步
  • 支持更多代码托管平台(如 GitHub
  • 支持同步 PR 的审查意见
  • 支持同步 PR 的状态(已合并、已关闭等)
  • 添加更多的错误处理和重试机制
  • 提供 Web 界面进行配置和管理