建议变更 API
- Tier: 基础版,专业版,旗舰版
- Offering: JihuLab.com, 私有化部署
当你审查代码时,建议提供了一种可以直接应用的具体更改的方式。有关更多信息,请参阅建议更改。
你可以通过此 API 在合并请求讨论中以编程方式创建和应用代码建议。对建议的每次 API 调用都必须进行认证。
创建建议
要通过 API 创建建议,请使用讨论 API 在合并请求差异中创建一个新线程。建议的格式为:
markdown```suggestion:-3+0 example text ```
应用建议
在合并请求中应用建议的补丁。用户必须至少具有开发者角色才能执行此操作。
plaintextPUT /suggestions/:id/apply
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer | 是 | 建议的 ID |
| commit_message | string | 否 | 使用自定义提交消息替代默认生成的消息或项目的默认消息 |
shellcurl --request PUT \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/suggestions/5/apply"
示例响应:
json1{ 2 "id": 5, 3 "from_line": 10, 4 "to_line": 10, 5 "applicable": true, 6 "applied": false, 7 "from_content": "This is an example\n", 8 "to_content": "This is an example\n" 9}
应用多个建议
plaintextPUT /suggestions/batch_apply
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| ids | integer | 是 | 建议的 ID |
| commit_message | string | 否 | 使用自定义提交消息替代默认生成的消息或项目的默认消息 |
shellcurl --request PUT \ --header "PRIVATE-TOKEN: <your_access_token>" \ --header 'Content-Type: application/json' \ --data '{"ids": [5, 6]}' \ --url "https://gitlab.example.com/api/v4/suggestions/batch_apply"
示例响应:
json1[ 2 { 3 "id": 5, 4 "from_line": 10, 5 "to_line": 10, 6 "applicable": true, 7 "applied": false, 8 "from_content": "This is an example\n", 9 "to_content": "This is an example\n" 10 } 11 { 12 "id": 6, 13 "from_line": 19, 14 "to_line": 19, 15 "applicable": true, 16 "applied": false, 17 "from_content": "This is another example\n", 18 "to_content": "This is another example\n" 19 } 20 ]