manage-pull-requests
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseManage Pull Requests
管理拉取请求(PR)
Manage Harness Code pull requests, reviewers, comments, checks, and activity via MCP.
通过MCP管理Harness Code的拉取请求、评审人员、评论、检查项及活动。
MCP Tools Used
使用的MCP工具
| Tool | Resource Type | Purpose |
|---|---|---|
| | List PRs in a repo, filter by state |
| | Get PR details by number |
| | Open a new PR |
| | Update PR title / description / state |
| | Merge a PR (merge/squash/rebase/fast-forward) |
| | List reviewers on a PR |
| | Add a reviewer to a PR |
| | Submit an |
| | Post a top-level or inline code comment |
| | Edit a comment |
| | Delete a comment |
| | Read the discussion timeline — the only way to READ comments |
| | List CI status checks on a PR |
| any of the above | Exact JSON Schema for |
All pull-request resources are repo-scoped. Every call needs and (except for , which only needs ). / are optional (the server infers them from the repo).
repo_idpr_numberharness_listpull_requestrepo_idorg_idproject_idURL shortcut: the MCP server auto-extracts and if you pass a Harness PR URL via the parameter — e.g. .
repo_idpr_numberurlharness_get(resource_type="pull_request", url="https://app.harness.io/ng/account/.../pulls/42")| 工具 | 资源类型 | 用途 |
|---|---|---|
| | 列出仓库中的PR,按状态筛选 |
| | 根据编号获取PR详情 |
| | 新建PR |
| | 更新PR标题/描述/状态 |
| | 合并PR(支持merge/squash/rebase/fast-forward模式) |
| | 列出PR的评审人员 |
| | 为PR添加评审人员 |
| | 提交 |
| | 发布顶层评论或行内代码评论 |
| | 编辑评论 |
| | 删除评论 |
| | 查看讨论时间线 —— 这是唯一可查看评论的方式 |
| | 列出PR的CI状态检查项 |
| 上述任意类型 | |
所有拉取请求资源均为仓库级作用域。每次调用都需要和(除了操作时仅需)。/为可选参数(服务器会从仓库信息中自动推断)。
repo_idpr_numberharness_listpull_requestrepo_idorg_idproject_idURL快捷方式:如果通过参数传入Harness PR链接,MCP服务器会自动提取和 —— 例如:。
urlrepo_idpr_numberharness_get(resource_type="pull_request", url="https://app.harness.io/ng/account/.../pulls/42")Instructions
操作步骤
Step 1: List or find the PR
步骤1:列出或查找PR
Call MCP tool: harness_list
Parameters:
resource_type: "pull_request"
repo_id: "<repository_identifier>"
state: "open" # optional: open | closed | merged
query: "<keyword>" # optional: full-text searchOr fetch a specific PR:
Call MCP tool: harness_get
Parameters:
resource_type: "pull_request"
repo_id: "<repository_identifier>"
pr_number: <number>调用MCP工具:harness_list
参数:
resource_type: "pull_request"
repo_id: "<repository_identifier>"
state: "open" # 可选值:open | closed | merged
query: "<keyword>" # 可选:全文搜索或者获取指定PR:
调用MCP工具:harness_get
参数:
resource_type: "pull_request"
repo_id: "<repository_identifier>"
pr_number: <number>Step 2: Open a PR
步骤2:新建PR
Call MCP tool: harness_create
Parameters:
resource_type: "pull_request"
repo_id: "<repository_identifier>"
body:
title: "Fix race condition in scheduler"
source_branch: "fix/scheduler-race"
target_branch: "main"
description: "Resolves HAR-1234. Adds mutex around queue access."titlesource_branchtarget_branchdescription调用MCP工具:harness_create
参数:
resource_type: "pull_request"
repo_id: "<repository_identifier>"
body:
title: "Fix race condition in scheduler"
source_branch: "fix/scheduler-race"
target_branch: "main"
description: "Resolves HAR-1234. Adds mutex around queue access."titlesource_branchtarget_branchdescriptionStep 3: Update PR metadata
步骤3:更新PR元数据
Call MCP tool: harness_update
Parameters:
resource_type: "pull_request"
repo_id: "<repo>"
pr_number: <number>
body:
title: "Updated title"
description: "Updated description"
state: "closed" # optional: open | closedAll body fields are optional — only include what you want to change.
调用MCP工具:harness_update
参数:
resource_type: "pull_request"
repo_id: "<repo>"
pr_number: <number>
body:
title: "Updated title"
description: "Updated description"
state: "closed" # 可选值:open | closed请求体中所有字段均为可选 —— 仅需包含需要修改的内容。
Step 4: Add reviewers
步骤4:添加评审人员
Call MCP tool: harness_create
Parameters:
resource_type: "pr_reviewer"
repo_id: "<repo>"
pr_number: <number>
body:
reviewer_id: <numeric_user_id>List current reviewers with .
harness_list(resource_type="pr_reviewer", repo_id, pr_number)调用MCP工具:harness_create
参数:
resource_type: "pr_reviewer"
repo_id: "<repo>"
pr_number: <number>
body:
reviewer_id: <numeric_user_id>可通过查看当前评审人员列表。
harness_list(resource_type="pr_reviewer", repo_id, pr_number)Step 5: Submit a review decision
步骤5:提交评审结论
Call MCP tool: harness_execute
Parameters:
resource_type: "pr_reviewer"
action: "submit_review"
repo_id: "<repo>"
pr_number: <number>
body:
decision: "approved" # approved | changereq
commit_sha: "<sha>" # optional — the commit you reviewed调用MCP工具:harness_execute
参数:
resource_type: "pr_reviewer"
action: "submit_review"
repo_id: "<repo>"
pr_number: <number>
body:
decision: "approved" # approved | changereq
commit_sha: "<sha>" # 可选 —— 你评审的提交记录SHAStep 6: Post a comment
步骤6:发布评论
Top-level comment:
Call MCP tool: harness_create
Parameters:
resource_type: "pr_comment"
repo_id: "<repo>"
pr_number: <number>
body:
text: "LGTM with one nit — see inline."Inline code comment:
Call MCP tool: harness_create
Parameters:
resource_type: "pr_comment"
repo_id: "<repo>"
pr_number: <number>
body:
text: "This loop can leak if the context is cancelled."
path: "scheduler/queue.go"
line_new: 142
source_commit_sha: "<source_sha>"
target_commit_sha: "<target_sha>"Use for comments on removed lines.
line_old顶层评论:
调用MCP工具:harness_create
参数:
resource_type: "pr_comment"
repo_id: "<repo>"
pr_number: <number>
body:
text: "LGTM with one nit — see inline."行内代码评论:
调用MCP工具:harness_create
参数:
resource_type: "pr_comment"
repo_id: "<repo>"
pr_number: <number>
body:
text: "This loop can leak if the context is cancelled."
path: "scheduler/queue.go"
line_new: 142
source_commit_sha: "<source_sha>"
target_commit_sha: "<target_sha>"针对已删除代码行的评论使用参数。
line_oldStep 7: Read comments — use pr_activity
, not pr_comment
pr_activitypr_comment步骤7:查看评论 —— 使用pr_activity
而非pr_comment
pr_activitypr_commentThe Harness Code API does not expose on . To read the discussion, list PR activity filtered by kind:
GET/commentsCall MCP tool: harness_list
Parameters:
resource_type: "pr_activity"
repo_id: "<repo>"
pr_number: <number>
kind: "comment" # just comments (general + code)
# or type: "code-comment" for inline code review comments onlyOther useful filters: , , , , .
typereview-submitreviewer-addstate-changemergetitle-changeHarness Code API 不支持通过请求接口。如需查看讨论内容,需按类型筛选PR活动列表:
GET/comments调用MCP工具:harness_list
参数:
resource_type: "pr_activity"
repo_id: "<repo>"
pr_number: <number>
kind: "comment" # 仅查看评论(普通评论+代码评论)
# 或使用type: "code-comment"仅查看行内代码评审评论其他实用的筛选值:、、、、。
typereview-submitreviewer-addstate-changemergetitle-changeStep 8: Edit or delete a comment
步骤8:编辑或删除评论
Call MCP tool: harness_update
Parameters:
resource_type: "pr_comment"
repo_id: "<repo>"
pr_number: <number>
comment_id: <numeric_comment_id>
body:
text: "Updated comment body"Call MCP tool: harness_delete
Parameters:
resource_type: "pr_comment"
repo_id: "<repo>"
pr_number: <number>
comment_id: <numeric_comment_id>调用MCP工具:harness_update
参数:
resource_type: "pr_comment"
repo_id: "<repo>"
pr_number: <number>
comment_id: <numeric_comment_id>
body:
text: "Updated comment body"调用MCP工具:harness_delete
参数:
resource_type: "pr_comment"
repo_id: "<repo>"
pr_number: <number>
comment_id: <numeric_comment_id>Step 9: Inspect CI checks
步骤9:检查CI状态
Call MCP tool: harness_list
Parameters:
resource_type: "pr_check"
repo_id: "<repo>"
pr_number: <number>Returns the status of each status check (pipeline, test run, external check) associated with the PR head commit. Use this before merging to confirm required checks are green.
调用MCP工具:harness_list
参数:
resource_type: "pr_check"
repo_id: "<repo>"
pr_number: <number>返回与PR头部提交记录关联的所有状态检查项(流水线、测试运行、外部检查)的状态。建议在合并前调用此接口确认所有必填检查项均已通过。
Step 10: Merge
步骤10:合并PR
Call MCP tool: harness_execute
Parameters:
resource_type: "pull_request"
action: "merge"
repo_id: "<repo>"
pr_number: <number>
body:
method: "squash" # merge | squash | rebase | fast-forward
delete_source_branch: true
dry_run: false
source_sha: "<expected_sha>" # optional optimistic lockSet first to preview the merge without executing — useful before destructive merges.
dry_run: true调用MCP工具:harness_execute
参数:
resource_type: "pull_request"
action: "merge"
repo_id: "<repo>"
pr_number: <number>
body:
method: "squash" # merge | squash | rebase | fast-forward
delete_source_branch: true
dry_run: false
source_sha: "<expected_sha>" # 可选:乐观锁校验建议先设置预览合并操作,不实际执行 —— 这在执行破坏性的squash/rebase合并前尤为实用。
dry_run: trueExamples
示例
Open a PR and request a review
新建PR并请求评审
/manage-pull-requests
Open a PR from feat/new-auth into main titled "Add OAuth device flow" on repo platformUI,
and add user 12345 as a reviewer./manage-pull-requests
在platformUI仓库中,从feat/new-auth分支向main分支新建标题为"Add OAuth device flow"的PR,并添加用户12345作为评审人员。Read all unresolved comments on a PR
查看PR中所有未解决的评论
/manage-pull-requests
Show me every inline code comment on PR 182 in repo harness-core so I can address them./manage-pull-requests
展示harness-core仓库中PR 182的所有行内代码评论,以便我处理这些评论。Approve and merge
批准并合并PR
/manage-pull-requests
Approve PR 47 in repo mcp-server with a "LGTM" comment, then squash-merge it and delete the branch./manage-pull-requests
批准mcp-server仓库中的PR 47,留下"LGTM"评论,然后以squash模式合并并删除源分支。Check CI before merging
合并前检查CI状态
/manage-pull-requests
List the checks on PR 99 in repo harness-cli. If they're all green, merge it with a squash./manage-pull-requests
列出harness-cli仓库中PR 99的检查项。如果全部通过,则以squash模式合并。Close a stale PR
关闭陈旧PR
/manage-pull-requests
Close PR 22 in repo harness-skills with a comment explaining we're going in a different direction./manage-pull-requests
关闭harness-skills仓库中的PR 22,并留下评论说明我们将采用其他方案。Performance Notes
性能注意事项
- Always pass +
repo_idtogether except forpr_numberwhich only needsharness_list(pull_request). Missingrepo_idon per-PR calls returns a helpful 400 from the server.pr_number - Read comments via , never
pr_activity. The comments endpoint is POST-only. Usepr_commentfor all discussion,kind=commentfor inline only.type=code-comment - Use on merge before destructive squash/rebase merges — especially on main branches with required checks.
dry_run: true - Prefer the URL shortcut when the user pastes a PR link. auto-extracts
url="<PR URL>",org_id,project_id, andrepo_id— fewer args to get wrong.pr_number - records a review independently of the reviewer list. You don't need to call
pr_reviewer.submit_reviewfirst to submit a review — any user with access can review.harness_create(pr_reviewer) - Cross-scope search: finds PRs across repos when you don't know which repo contains it.
harness_search(query="<text>", resource_types=["pull_request"])
- 除仅需
harness_list(pull_request)外,其他针对单个PR的操作请务必同时传入repo_id和repo_id。如果缺少pr_number,服务器会返回明确的400错误提示。pr_number - 请通过查看评论,切勿使用
pr_activity。评论接口仅支持POST请求。使用pr_comment查看所有讨论内容,使用kind=comment仅查看行内评论。type=code-comment - 执行合并操作前请使用—— 尤其是在带有必填检查项的主分支上执行squash/rebase等破坏性合并时。
dry_run: true - 当用户粘贴PR链接时,优先使用URL快捷方式。传入会自动提取
url="<PR URL>"、org_id、project_id和repo_id—— 减少参数错误的概率。pr_number - 会独立于评审人员列表记录评审结果。提交评审前无需先调用
pr_reviewer.submit_review—— 任何拥有访问权限的用户均可提交评审。harness_create(pr_reviewer) - 跨仓库搜索:当你不知道PR所在仓库时,可使用跨仓库查找PR。
harness_search(query="<text>", resource_types=["pull_request"])
Troubleshooting
故障排查
"repo_id is required"
"repo_id is required"
All PR operations are repo-scoped. Pass the repo identifier (not the repo name) — list repos first with if you're unsure.
harness_list(resource_type="repository")所有PR操作均为仓库级作用域。请传入仓库标识符(而非仓库名称)—— 若不确定仓库标识符,可先调用列出所有仓库。
harness_list(resource_type="repository")Comments don't show up when I list them
列表中无法显示评论
pr_commentlistgetharness_list(resource_type="pr_activity", kind="comment")pr_commentlistgetharness_list(resource_type="pr_activity", kind="comment")"GET /comments not found" / 404 on reading a comment
"GET /comments not found" / 查看评论时返回404
Same cause as above — the Harness Code API is POST-only for . Read via .
/commentspr_activity原因同上 —— Harness Code API的接口仅支持POST请求。请通过查看评论。
/commentspr_activityReview decision rejected
评审结论提交失败
Check the value — it must be exactly or . The API does not accept (no ) or .
decision"approved""changereq""approve"d"request_changes"检查参数值 —— 必须严格为或。API不接受(缺少末尾的d)或。
decision"approved""changereq""approve""request_changes"Merge fails with "source SHA mismatch"
合并失败并提示"source SHA mismatch"
You passed and it no longer matches the branch head (someone pushed after you computed it). Drop or re-fetch the PR to get the current .
source_shasource_shasource_sha你传入的已与分支头部不一致(在你计算SHA后有人推送了新代码)。可移除参数,或重新获取PR以获取最新的。
source_shasource_shasource_shaInline comment has no diff context
行内评论无差异上下文
Inline code comments need both and in the body — without them the comment appears as a top-level comment. Get the SHAs from → / .
source_commit_shatarget_commit_shaharness_get(pull_request)source_shatarget_sha行内代码评论的请求体中必须同时包含和 —— 缺少这些参数时,评论会显示为顶层评论。可通过获取/。
source_commit_shatarget_commit_shaharness_get(pull_request)source_shatarget_shaRequired checks aren't passing but merge succeeded anyway
必填检查项未通过但合并仍成功
harness_execute(action=merge)harness_list(resource_type="pr_check")success若调用者拥有管理员权限,会绕过分支保护规则。建议先调用,若存在未通过的检查项则在自动化流程中终止合并操作。
harness_execute(action=merge)harness_list(resource_type="pr_check")