manage-pull-requests

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Manage Pull Requests

管理拉取请求(PR)

Manage Harness Code pull requests, reviewers, comments, checks, and activity via MCP.
通过MCP管理Harness Code的拉取请求、评审人员、评论、检查项及活动。

MCP Tools Used

使用的MCP工具

ToolResource TypePurpose
harness_list
pull_request
List PRs in a repo, filter by state
harness_get
pull_request
Get PR details by number
harness_create
pull_request
Open a new PR
harness_update
pull_request
Update PR title / description / state
harness_execute
(action:
merge
)
pull_request
Merge a PR (merge/squash/rebase/fast-forward)
harness_list
pr_reviewer
List reviewers on a PR
harness_create
pr_reviewer
Add a reviewer to a PR
harness_execute
(action:
submit_review
)
pr_reviewer
Submit an
approved
or
changereq
review
harness_create
pr_comment
Post a top-level or inline code comment
harness_update
pr_comment
Edit a comment
harness_delete
pr_comment
Delete a comment
harness_list
pr_activity
Read the discussion timeline — the only way to READ comments
harness_list
pr_check
List CI status checks on a PR
harness_schema
any of the aboveExact JSON Schema for
create
/
update
body fields
All pull-request resources are repo-scoped. Every call needs
repo_id
and
pr_number
(except
harness_list
for
pull_request
, which only needs
repo_id
).
org_id
/
project_id
are optional (the server infers them from the repo).
URL shortcut: the MCP server auto-extracts
repo_id
and
pr_number
if you pass a Harness PR URL via the
url
parameter — e.g.
harness_get(resource_type="pull_request", url="https://app.harness.io/ng/account/.../pulls/42")
.
工具资源类型用途
harness_list
pull_request
列出仓库中的PR,按状态筛选
harness_get
pull_request
根据编号获取PR详情
harness_create
pull_request
新建PR
harness_update
pull_request
更新PR标题/描述/状态
harness_execute
(动作:
merge
pull_request
合并PR(支持merge/squash/rebase/fast-forward模式)
harness_list
pr_reviewer
列出PR的评审人员
harness_create
pr_reviewer
为PR添加评审人员
harness_execute
(动作:
submit_review
pr_reviewer
提交
approved
(批准)或
changereq
(要求修改)的评审结论
harness_create
pr_comment
发布顶层评论或行内代码评论
harness_update
pr_comment
编辑评论
harness_delete
pr_comment
删除评论
harness_list
pr_activity
查看讨论时间线 —— 这是唯一可查看评论的方式
harness_list
pr_check
列出PR的CI状态检查项
harness_schema
上述任意类型
create
/
update
请求体字段的精确JSON Schema
所有拉取请求资源均为仓库级作用域。每次调用都需要
repo_id
pr_number
(除了
harness_list
操作
pull_request
时仅需
repo_id
)。
org_id
/
project_id
为可选参数(服务器会从仓库信息中自动推断)。
URL快捷方式:如果通过
url
参数传入Harness PR链接,MCP服务器会自动提取
repo_id
pr_number
—— 例如:
harness_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 search
Or 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."
title
,
source_branch
,
target_branch
are required.
description
supports markdown.
调用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."
title
source_branch
target_branch
为必填项。
description
支持markdown格式。

Step 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 | closed
All 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>"           # 可选 —— 你评审的提交记录SHA

Step 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
line_old
for comments on removed lines.
顶层评论
调用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_old
参数。

Step 7: Read comments — use
pr_activity
, not
pr_comment

步骤7:查看评论 —— 使用
pr_activity
而非
pr_comment

The Harness Code API does not expose
GET
on
/comments
. To read the discussion, list PR activity filtered by kind:
Call 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 only
Other useful
type
filters:
review-submit
,
reviewer-add
,
state-change
,
merge
,
title-change
.
Harness Code API 不支持通过
GET
请求
/comments
接口。如需查看讨论内容,需按类型筛选PR活动列表:
调用MCP工具:harness_list
参数:
  resource_type: "pr_activity"
  repo_id: "<repo>"
  pr_number: <number>
  kind: "comment"        # 仅查看评论(普通评论+代码评论)
  # 或使用type: "code-comment"仅查看行内代码评审评论
其他实用的
type
筛选值:
review-submit
reviewer-add
state-change
merge
title-change

Step 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 lock
Set
dry_run: true
first to preview the merge without executing — useful before destructive merges.
调用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>"   # 可选:乐观锁校验
建议先设置
dry_run: true
预览合并操作,不实际执行 —— 这在执行破坏性的squash/rebase合并前尤为实用。

Examples

示例

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_id
    +
    pr_number
    together
    except for
    harness_list(pull_request)
    which only needs
    repo_id
    . Missing
    pr_number
    on per-PR calls returns a helpful 400 from the server.
  • Read comments via
    pr_activity
    , never
    pr_comment
    .
    The comments endpoint is POST-only. Use
    kind=comment
    for all discussion,
    type=code-comment
    for inline only.
  • Use
    dry_run: true
    on merge
    before destructive squash/rebase merges — especially on main branches with required checks.
  • Prefer the URL shortcut when the user pastes a PR link.
    url="<PR URL>"
    auto-extracts
    org_id
    ,
    project_id
    ,
    repo_id
    , and
    pr_number
    — fewer args to get wrong.
  • pr_reviewer.submit_review
    records a review independently of the reviewer list. You don't need to call
    harness_create(pr_reviewer)
    first to submit a review — any user with access can review.
  • Cross-scope search:
    harness_search(query="<text>", resource_types=["pull_request"])
    finds PRs across repos when you don't know which repo contains it.
  • harness_list(pull_request)
    仅需
    repo_id
    外,其他针对单个PR的操作请务必同时传入
    repo_id
    pr_number
    。如果缺少
    pr_number
    ,服务器会返回明确的400错误提示。
  • 请通过
    pr_activity
    查看评论,切勿使用
    pr_comment
    。评论接口仅支持POST请求。使用
    kind=comment
    查看所有讨论内容,使用
    type=code-comment
    仅查看行内评论。
  • 执行合并操作前请使用
    dry_run: true
    —— 尤其是在带有必填检查项的主分支上执行squash/rebase等破坏性合并时。
  • 当用户粘贴PR链接时,优先使用URL快捷方式。传入
    url="<PR URL>"
    会自动提取
    org_id
    project_id
    repo_id
    pr_number
    —— 减少参数错误的概率。
  • pr_reviewer.submit_review
    会独立于评审人员列表记录评审结果。提交评审前无需先调用
    harness_create(pr_reviewer)
    —— 任何拥有访问权限的用户均可提交评审。
  • 跨仓库搜索:当你不知道PR所在仓库时,可使用
    harness_search(query="<text>", resource_types=["pull_request"])
    跨仓库查找PR。

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
harness_list(resource_type="repository")
if you're unsure.
所有PR操作均为仓库级作用域。请传入仓库标识符(而非仓库名称)—— 若不确定仓库标识符,可先调用
harness_list(resource_type="repository")
列出所有仓库。

Comments don't show up when I list them

列表中无法显示评论

pr_comment
has no
list
/
get
operations. Use
harness_list(resource_type="pr_activity", kind="comment")
to read the discussion timeline.
pr_comment
不支持
list
/
get
操作。请使用
harness_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
/comments
. Read via
pr_activity
.
原因同上 —— Harness Code API的
/comments
接口仅支持POST请求。请通过
pr_activity
查看评论。

Review decision rejected

评审结论提交失败

Check the
decision
value — it must be exactly
"approved"
or
"changereq"
. The API does not accept
"approve"
(no
d
) or
"request_changes"
.
检查
decision
参数值 —— 必须严格为
"approved"
"changereq"
。API不接受
"approve"
(缺少末尾的d)或
"request_changes"

Merge fails with "source SHA mismatch"

合并失败并提示"source SHA mismatch"

You passed
source_sha
and it no longer matches the branch head (someone pushed after you computed it). Drop
source_sha
or re-fetch the PR to get the current
source_sha
.
你传入的
source_sha
已与分支头部不一致(在你计算SHA后有人推送了新代码)。可移除
source_sha
参数,或重新获取PR以获取最新的
source_sha

Inline comment has no diff context

行内评论无差异上下文

Inline code comments need both
source_commit_sha
and
target_commit_sha
in the body — without them the comment appears as a top-level comment. Get the SHAs from
harness_get(pull_request)
source_sha
/
target_sha
.
行内代码评论的请求体中必须同时包含
source_commit_sha
target_commit_sha
—— 缺少这些参数时,评论会显示为顶层评论。可通过
harness_get(pull_request)
获取
source_sha
/
target_sha

Required checks aren't passing but merge succeeded anyway

必填检查项未通过但合并仍成功

harness_execute(action=merge)
bypasses branch protection if the caller has admin rights. Use
harness_list(resource_type="pr_check")
first and fail fast in automation if any check is not
success
.
若调用者拥有管理员权限,
harness_execute(action=merge)
会绕过分支保护规则。建议先调用
harness_list(resource_type="pr_check")
,若存在未通过的检查项则在自动化流程中终止合并操作。