You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否通过Gerrit REST API获取特定变更的dependsOn与neededBy属性?

Can Gerrit REST API retrieve dependsOn and neededBy properties?

Absolutely! You don’t need to rely on the Gerrit SSH command to fetch dependency information—the REST API fully supports getting both dependsOn and neededBy relationships for a specific change. Here’s how to implement it:

1. Use the Change Detail Endpoint

The most direct approach is to call the /changes/{change-id}/detail endpoint, which returns comprehensive details about a change, including its dependencies. Since these fields aren’t included in the default response, you’ll need to explicitly request them via query parameters.

Example Request

Send a GET request with these parameters:

GET /changes/{change-id}/detail?o=CURRENT_REVISION&o=DEPENDENCIES

Replace {change-id} with your target change’s identifier—this can be the full hash (like I123456789abcdef123456789abcdef123456789a) or the project-branch-number format (e.g., my-project~main~123).

Response Breakdown

In the JSON output, navigate to the current_revision object (this maps to the --current-patch-set flag in your SSH command). The associated patch set will include two key arrays:

  • depends_on: Lists changes that the current change relies on (matches the SSH command’s dependsOn property)
  • needed_by: Lists changes that depend on the current change (matches the SSH command’s neededBy property)

Each entry in these arrays includes details like the dependency’s change ID, branch, subject, and basic status.

2. Alternative: Mirror the SSH Query Structure

If you want to replicate your original SSH query logic (change:$changeid AND branch:$branch), use the /changes/ query endpoint with matching filters plus the dependency flags:

GET /changes/?q=change:{change-id}+branch:{branch}&o=CURRENT_REVISION&o=DEPENDENCIES

This returns a list (with one entry for your target change) containing the same dependency fields as the detail endpoint.

Key Notes

  • Permissions: Make sure you have read access to both the target change and any linked dependencies—Gerrit will omit data you don’t have permission to view.
  • Parameter Alignment: The o=CURRENT_REVISION flag corresponds to --current-patch-set in SSH, and o=DEPENDENCIES matches the --dependencies flag.

内容的提问来源于stack exchange,提问作者Some programmer dude

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 10:37:32