Skip to content

[r2cn] Mega 侧支持 Bot 集成-事件通知机制 #1950

@benjamin-747

Description

@benjamin-747

[任务] Mega 侧支持 Bot 集成-事件通知机制

[任务分值] 30 分

[背景描述]

当前 r2cn Bot 已接入 GitHub,已经具备:

  • 接收 GitHub Webhook(PR、评论、Push 等)
  • 解析 GitHub 事件模型
  • 调用 GitHub API 获取 PR / Commit / Diff
  • 基于 PR 进行评论,状态回写

现在希望 Bot 接入 Mega,需要考虑:

  • Mega 是否具备 GitHub 等价的事件模型?
  • Mega 的 CL 模型是否等价于 GitHub PR?
  • Mega 的 API 是否支持 Bot 所需能力?

本质上,这是一次 平台适配层(Platform Adapter)的扩展。

[需求描述]

一、事件通知机制(Webhook 体系)

Bot 要能“被动感知”CL 生命周期,Mega 必须提供可靠的事件推送能力。

  1. 需要支持的核心事件

至少包括:

CL 相关

  • cl.created
  • cl.updated
  • cl.reopened
  • cl.merged
  • cl.closed

评论相关

  • cl.comment.created
  1. Webhook 注册机制

POST /api/webhooks
GET /api/webhooks
DELETE /api/webhooks/{id}

Webhook 配置字段:

  • target_url
  • event_types[]
  • secret
  • path(可选,支持按路径配置)
  • active
  1. 事件 Payload 结构设计
    必须做到:
  • 平台稳定版本号
  • 事件类型明确
  • 数据可追溯
{
  "event": "cl.created",
  "timestamp": 1710000000,
  "cl": {
    "id": 123,
    "title": "fix bug",
    "author": {
      "id": 10,
      "name": "alice"
    },
    "base_branch": "main",
    "head_commit": "abc123"
  },
  "repository": {
    "id": 5,
    "name": "mono"
  }
}
  1. 投递机制设计

必须考虑:

  • 异步发送(队列)
  • 重试机制(指数退避)
  • 超时控制
  • 签名验证(HMAC)

[代码标准]

  1. 所有 PR 提交必须签署 Signed-off-by 和 使用 GPG 签名,即提交代码时(使用 git commit 命令时)至少使用 -s -S 两个参数,参考 Contributing Guide
  2. 所有 PR 提交必须通过 GitHub Actions 自动化测试,提交 PR 后请关注 GitHub Actions 结果;
  3. 代码注释均需要使用英文;

[PR 提交地址] 提交到 mega 仓库的 main 分支 `` 目录;

[开发指导]

  1. 认领任务参考 r2cn 开源实习计划 - 任务认领与确认;

[导师及邮箱] 请申请此题目的同学使用邮件联系导师,或加入到 R2CN Discord 后在 #p-meta 频道和导师交流。

  1. Quanyi Ma genedna@gmail.com
  2. Tianxing Ye yetianxing2014@gmail.com

[备注]

  1. 认领实习任务的同学,必须完成测试任务和注册流程,请参考: r2cn 开源实习计划 - 测试任务r2cn 开源实习计划 - 学生注册与审核

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions