Pull Request¶
Pull Request(合并请求)用于把源分支的改动合入目标分支。通过 API 可以创建、更新、合并 PR,管理评论与标签,指派审查人、测试人和合并人,读取变更文件、Commit 与操作日志。
仓库级的标签、里程碑有独立分组,本页只覆盖 PR 自身的接口。
对象¶
| 对象 | 说明 | 相关接口 |
|---|---|---|
| Pull Request | 标题、状态、源/目标分支、描述、里程碑、标签、是否草稿 | 获取单个Pull Request |
| 合并 | merge / squash / rebase 三种方式 | 合并Pull Request |
| 评论 | PR 普通评论与代码行级/文件级评论 | 提交pull request 评论 |
| 讨论(discussion) | 评论所在的讨论串,回复按讨论 ID 定位 | 回复Pull Request评论 |
| 标签 | PR 上的标签,支持新增、替换与批量删除 | 替换 Pull Request所有标签 |
| 审查人 | 指派、取消审查人,重置审查状态 | 指派用户审查 Pull Request |
| 测试人 | 指派、取消测试人,重置测试状态,候选列表 | 指派用户测试 Pull Request |
| 合并人 | 指定一个或多个合并人 | 设置Pull Request合并人 |
| 关联 Issue | PR 与 Issue 的双向关联 | Pull Request关联issue |
| 变更内容 | PR 的 Commit 列表、变更文件、文件变更统计 | Pull Request Commit文件列表 |
| 表态 | 用户对 PR 及其评论的 emoji 表态 | 获取Pull Request的表态列表 |
| 历史与日志 | PR 与评论的修改历史、操作日志 | 获取某个Pull Request的操作日志 |
标识方式¶
- 仓库级接口用
owner+repo标识仓库,用number标识 PR 编号。 - 评论用
id标识(路径/pulls/comments/{id}),检视意见与回复用discussion_id、comment_id标识。 - 组织级接口用
org,路径为/api/v5/org/{org}/pull_requests(单数org)。 - 企业级接口用
enterprise,列表接口的路径里用*占位。
常见任务¶
注意事项¶
- 组织级 PR 列表的路径是
GET /api/v5/org/{org}/pull_requests,用单数org,与其他/orgs/{org}/…接口不同;企业级列表用GET /api/v5/enterprises/*/pull_requests,路径里是*占位。 - 评论有两类路径:按 PR 操作的
/pulls/{number}/comments(支持行级与文件级评论),以及按评论 ID 操作的/pulls/comments/{id}。 - 回复评论要带讨论 ID:
POST /pulls/{number}/discussions/{discussion_id}/comments;而修改检视意见的解决状态用的是PUT /pulls/{number}/comments/{discussion_id},路径里传的是discussion_id而不是评论 ID。 - 审查相关的接口有两组并存:
/pulls/{number}/assignees与/pulls/{number}/reviewers,前者带重置审查状态的语义、后者是评审人名单,调用前先看具体接口页的参数表。 - 候选列表的路径不一致:测试人候选是
GET /pulls/option_testers(不带 PR 编号),评审人候选是GET /pulls/{number}/option_reviewers。 - 文件变更有两套返回:
/pulls/{number}/files给变更文件列表,/pulls/{number}/files.json给变更统计与 diff 引用。
接口列表¶
本模块共 45 个接口。
| # | 接口 | 方法与路径 | 说明 |
|---|---|---|---|
| 1 | 获取项目Pull Request列表 | GET /api/v5/repos/{owner}/{repo}/pulls |
该接口用于获取指定仓库下的 Pull Request 列表,支持按状态、目标分支、时间范围、排序、分页等条件进行筛选… |
| 2 | 创建Pull Request | POST /api/v5/repos/{owner}/{repo}/pulls |
该接口用于在指定仓库下创建 Pull Request(合并请求),可设置标题、源分支与目标分支、描述内容,并支持指定… |
| 3 | 合并Pull Request | PUT /api/v5/repos/{owner}/{repo}/pulls/{number}/merge |
该接口用于合并指定仓库中指定序号的 Pull Request。支持通过 merge、squash 或 rebase … |
| 4 | 判断Pull Request是否合并 | GET /api/v5/repos/{owner}/{repo}/pulls/{number}/merge |
该接口用于判断指定仓库中某个 Pull Request 是否已经合并,根据仓库空间地址、仓库路径及 PR 序号定位目… |
| 5 | 获取pr关联的issue | GET /api/v5/repos/{owner}/{repo}/pulls/{number}/issues |
该接口用于获取指定仓库中某个 PR(Pull Request)所关联的 issue 列表,并返回每个 issue 的… |
| 6 | 提交pull request 评论 | POST /api/v5/repos/{owner}/{repo}/pulls/{number}/comments |
该接口用于向指定的 pull request 提交评论,可指定文件路径与代码所在行数进行行级评论,也可选择文件级评论… |
| 7 | 获取某个Pull Request的所有评论 | GET /api/v5/repos/{owner}/{repo}/pulls/{number}/comments |
该接口用于获取指定仓库中某个 Pull Request 的全部评论,支持按代码行评论与 PR 普通评论类型筛选,并可… |
| 8 | Pull Request Commit文件列表 | GET /api/v5/repos/{owner}/{repo}/pulls/{number}/files |
该接口用于查询指定仓库中某个 Pull Request(合并请求)变更所涉及的文件列表,返回每个变更文件的路径、状态… |
| 9 | 更新Pull Request信息 | PATCH /api/v5/repos/{owner}/{repo}/pulls/{number} |
该接口用于更新指定仓库中某个 Pull Request 的信息,支持修改标题、内容、状态、里程碑、标签、是否草稿等,… |
| 10 | 获取单个Pull Request | GET /api/v5/repos/{owner}/{repo}/pulls/{number} |
该接口用于获取指定仓库中单个 Pull Request 的详细信息,包括标题、状态、审核人与测试人信息、标签、合并门… |
| 11 | 获取某Pull Request的所有Commit信息 | GET /api/v5/repos/{owner}/{repo}/pulls/{number}/commits |
该接口用于获取指定仓库中某个 Pull Request 的全部 Commit 信息,返回内容包括提交的 SHA、提交… |
| 12 | 创建 Pull Request标签 | POST /api/v5/repos/{owner}/{repo}/pulls/{number}/labels |
该接口用于为指定仓库中的指定 Pull Request 创建标签,通过请求体提交标签名称数组,成功后可获取所创建标签… |
| 13 | 获取某个 Pull Request的所有标签 | GET /api/v5/repos/{owner}/{repo}/pulls/{number}/labels |
该接口用于获取指定仓库中某个 Pull Request 的所有标签,通过仓库空间地址、仓库路径和 PR 序号定位目标… |
| 14 | 替换 Pull Request所有标签 | PUT /api/v5/repos/{owner}/{repo}/pulls/{number}/labels |
该接口用于替换指定 Pull Request 的所有标签。请求体为标签名称数组,提交后将覆盖该 Pull Reque… |
| 15 | 删除 Pull Request标签 | DELETE /api/v5/repos/{owner}/{repo}/pulls/{number}/labels/{name} |
该接口用于删除指定仓库中指定 Pull Request 的一个或多个标签,支持通过英文逗号分隔标签名称进行批量删除,… |
| 16 | 处理 Pull Request测试 | POST /api/v5/repos/{owner}/{repo}/pulls/{number}/test |
该接口用于处理指定仓库中某个 Pull Request 的测试操作,支持通过 force 参数强制测试通过(该能力仅… |
| 17 | 处理 Pull Request审查 | POST /api/v5/repos/{owner}/{repo}/pulls/{number}/review |
该接口用于对指定仓库中指定序号的 Pull Request 执行审查处理,通过提交审查请求推进该 PR 的审查流程,… |
| 18 | 获取某个Pull Request的操作日志 | GET /api/v5/repos/{owner}/{repo}/pulls/{number}/operate_logs |
该接口用于查询指定仓库中某个 Pull Request 的操作日志,支持按时间倒序排序和分页浏览,返回每一条操作的详… |
| 19 | 重置 Pull Request测试 的状态 | PATCH /api/v5/repos/{owner}/{repo}/pulls/{number}/testers |
该接口用于重置指定 Pull Request 的测试状态。通过请求体中的 reset_all 参数,可重置单个测试人… |
| 20 | 指派用户测试 Pull Request | POST /api/v5/repos/{owner}/{repo}/pulls/{number}/testers |
该接口用于为指定仓库中的某个 Pull Request 指派测试人,通过请求体中的测试人列表进行设置,并支持覆盖更新… |
| 21 | 取消用户测试Pull Request | DELETE /api/v5/repos/{owner}/{repo}/pulls/{number}/testers |
该接口用于取消指定仓库中某个 Pull Request 的测试用户。通过传入需移除的用户个人空间地址,可将相应测试者… |
| 22 | 获取可作为Pull Request测试人列表 | GET /api/v5/repos/{owner}/{repo}/pulls/option_testers |
该接口用于获取指定仓库中可作为 Pull Request 测试人的用户列表,返回候选用户的账号、昵称、头像及对象标识… |
| 23 | 重置 Pull Request审查 的状态 | PATCH /api/v5/repos/{owner}/{repo}/pulls/{number}/assignees |
该接口用于重置指定仓库中特定 Pull Request 的审查状态,可通过请求体可选参数设定是否重置所有审查人的审查… |
| 24 | 指派用户审查 Pull Request | POST /api/v5/repos/{owner}/{repo}/pulls/{number}/assignees |
该接口用于为指定仓库中的指定 Pull Request 指派审查用户:提交以逗号分隔的用户个人空间地址列表,可将一名… |
| 25 | 取消用户审查 Pull Request | DELETE /api/v5/repos/{owner}/{repo}/pulls/{number}/assignees |
该接口用于取消指定 Pull Request 上已指派的用户审查,撤回用户的审查资格,解除其审查任务,使该用户不再参… |
| 26 | pr提交的文件变更信息 | GET /api/v5/repos/{owner}/{repo}/pulls/{number}/files.json |
该接口用于查询指定 PR 提交的文件变更信息,返回文件变更数量、新增与删除行数、对比引用的 commit 信息,以及… |
| 27 | 企业 Pull Request列表 | GET /api/v5/enterprises/*/pull_requests |
该接口用于查询指定企业(空间)下的 Pull Request 列表,支持按状态、作者、目标分支、标签、时间范围等条件… |
| 28 | 获取Pull Request某条评论 | GET /api/v5/repos/{owner}/{repo}/pulls/comments/{id} |
该接口用于根据评论 ID 获取指定仓库中 Pull Request 的某条评论详情,包括评论内容、作者信息、创建及更… |
| 29 | 编辑评论 | PATCH /api/v5/repos/{owner}/{repo}/pulls/comments/{id} |
该接口用于编辑仓库中指定 Pull Request 下某条评论的内容,通过评论 ID 定位目标评论并提交新的评论内容… |
| 30 | 删除评论 | DELETE /api/v5/repos/{owner}/{repo}/pulls/comments/{id} |
该接口用于删除指定仓库中指定 Pull Request 的评论,通过仓库地址、仓库路径及评论 ID 定位目标评论,删… |
| 31 | 组织 Pull Request列表 | GET /api/v5/org/{org}/pull_requests |
该接口用于查询指定组织下的 Pull Request 列表,支持按仓库、状态、目标分支、作者、标签、创建与更新时间范… |
| 32 | 获取企业 issue 关联的 Pull Requests | GET /api/v5/enterprises/{enterprise}/issues/{number}/pull_requests |
该接口用于获取指定企业下与某个 issue 关联的所有 Pull Requests,通过企业路径与 issue 全局… |
| 33 | Pull Request关联issue | POST /api/v5/repos/{owner}/{repo}/pulls/{number}/issues |
该接口用于将指定仓库中的 Issue 关联到目标 Pull Request,请求时需提交待关联的 Issue 序号列… |
| 34 | Pull Request删除关联的issue | DELETE /api/v5/repos/{owner}/{repo}/pulls/{number}/issues |
该接口用于解除指定 Pull Request 与多个 issue 的关联关系,请求体中传入待解除关联的 issue … |
| 35 | 回复Pull Request评论 | POST /api/v5/repos/{owner}/{repo}/pulls/{number}/discussions/{discussion_id}/comments |
该接口用于对指定 Pull Request 讨论中的评论进行回复,提交回复正文后,该回复会作为一条新评论写入对应讨论… |
| 36 | 修改检视意见解决状态 | PUT /api/v5/repos/{owner}/{repo}/pulls/{number}/comments/{discussion_id} |
该接口用于修改指定 Pull Request 中检视意见(评论/讨论)的解决状态,通过请求体中的 resolved … |
| 37 | 设置Pull Request合并人 | PUT /api/v5/repos/{owner}/{repo}/pulls/{number}/mergers |
该接口用于为指定仓库中的 Pull Request 设置合并人,通过提交以逗号分隔的用户个人空间地址,可指定一个或多… |
| 38 | 指派用户评审Pull Request | POST /api/v5/repos/{owner}/{repo}/pulls/{number}/reviewers |
该接口用于为指定仓库中的某个 Pull Request 指派用户作为评审人,支持新增或覆盖更新评审人名单,并可返回指… |
| 39 | 取消用户评审Pull Request | DELETE /api/v5/repos/{owner}/{repo}/pulls/{number}/reviewers |
该接口用于取消指定仓库中某个 Pull Request 的用户评审,通过传入需取消评审的用户个人空间地址列表,可将对… |
| 40 | 获取可作为Pull Request评审人列表 | GET /api/v5/repos/{owner}/{repo}/pulls/{number}/option_reviewers |
该接口用于获取指定仓库中指定 Pull Request 的可选评审人列表,返回评审人的用户 ID、账号、昵称、头像等… |
| 41 | 获取Pull Request的表态列表 | GET /api/v5/repos/{owner}/{repo}/pulls/{number}/user_reactions |
该接口用于获取指定仓库中指定 Pull Request 的表态列表,返回每条表态对应的 emoji 表情及表态用户信… |
| 42 | 获取Pull Request评论的表态列表 | GET /api/v5/repos/{owner}/{repo}/pulls/comment/{comment_id}/user_reactions |
该接口用于获取指定 Pull Request 评论的表态列表,返回各表态记录的编号、表情及表态用户信息,并支持按 e… |
| 43 | 获取Pull Request的修改历史 | GET /api/v5/repos/{owner}/{repo}/pulls/{number}/modify_history |
该接口用于获取指定仓库中指定 Pull Request 的修改历史,返回包含修改时间、修改内容及操作者、更新者用户信… |
| 44 | 获取Pull Request评论的修改历史 | GET /api/v5/repos/{owner}/{repo}/pulls/comment/{comment_id}/modify_history |
该接口用于获取指定仓库中Pull Request评论的修改历史。通过这个接口,用户可以查看评论在创建及历次修改过程中… |
| 45 | 刷新Pull Request评论位置/过期状态 | POST /api/v5/repos/{owner}/{repo}/pulls/{number}/refresh_position |
该接口用于刷新指定 Pull Request 评论的位置与过期状态,支持按文件路径或评论 ID 定向刷新,当两者均未… |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc