Help us learn about your current experience with the documentation. Take the survey.

合并请求上下文提交 API

  • 层级:免费、专业、旗舰
  • 产品:GitLab.com、GitLab 自管理版、GitLab 专用版

如果您的合并请求是基于之前的合并请求构建的,您可能需要在您的合并请求中包含先前已合并的提交以提供上下文。使用此 API 可以向合并请求添加提交,以提供更多上下文。

列出合并请求上下文提交

获取合并请求上下文提交列表。

GET /projects/:id/merge_requests/:merge_request_iid/context_commits

参数:

属性 类型 必需 描述
id 整数 项目的 ID 或 URL 编码路径
merge_request_iid 整数 合并请求的内部 ID。
[
    {
        "id": "4a24d82dbca5c11c61556f3b35ca472b7463187e",
        "short_id": "4a24d82d",
        "created_at": "2017-04-11T10:08:59.000Z",
        "parent_ids": null,
        "title": "Update README.md to include `Usage in testing and development`",
        "message": "Update README.md to include `Usage in testing and development`",
        "author_name": "Example \"Sample\" User",
        "author_email": "user@example.com",
        "authored_date": "2017-04-11T10:08:59.000Z",
        "committer_name": "Example \"Sample\" User",
        "committer_email": "user@example.com",
        "committed_date": "2017-04-11T10:08:59.000Z"
    }
]

创建合并请求上下文提交

创建一个合并请求上下文提交列表。

POST /projects/:id/merge_requests/:merge_request_iid/context_commits

参数:

属性 类型 必需 描述
id 整数 项目的 ID 或 URL 编码路径
merge_request_iid 整数 合并请求的内部 ID。
commits 字符串数组 上下文提交的 SHA 值。

请求示例:

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
  --header 'Content-Type: application/json' \
  --data '{"commits": ["51856a574ac3302a95f82483d6c7396b1e0783cb"]}' \
  --url "https://gitlab.example.com/api/v4/projects/15/merge_requests/12/context_commits"

响应示例:

[
    {
        "id": "51856a574ac3302a95f82483d6c7396b1e0783cb",
        "short_id": "51856a57",
        "created_at": "2014-02-27T10:05:10.000+02:00",
        "parent_ids": [
            "57a82e2180507c9e12880c0747f0ea65ad489515"
        ],
        "title": "Commit title",
        "message": "Commit message",
        "author_name": "Example User",
        "author_email": "user@example.com",
        "authored_date": "2014-02-27T10:05:10.000+02:00",
        "committer_name": "Example User",
        "committer_email": "user@example.com",
        "committed_date": "2014-02-27T10:05:10.000+02:00",
        "trailers": {},
        "web_url": "https://gitlab.example.com/project/path/-/commit/b782f6c553653ab4e16469ff34bf3a81638ac304"
    }
]

删除合并请求上下文提交

删除一个合并请求上下文提交列表。

DELETE /projects/:id/merge_requests/:merge_request_iid/context_commits

参数:

属性 类型 必需 描述
commits 字符串数组 上下文提交的 SHA 值。
id 整数 项目的 ID 或 URL 编码路径
merge_request_iid 整数 合并请求的内部 ID。