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

资源状态事件 API

  • Tier: Free, Premium, Ultimate
  • Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated

资源状态事件用于跟踪 GitLab issues(问题)、merge requests(合并请求)和 epics starting with GitLab 15.4(从 GitLab 15.4 开始的史诗)所发生的情况。

使用它们来跟踪设置了什么状态、谁操作的以及何时发生的。

资源状态事件 API 不跟踪资源的初始状态(“create” 或 “open”)。 对于未被关闭或重新打开的资源,将返回空列表。

Issues

列出项目问题状态事件

获取单个问题的所有状态事件列表。

GET /projects/:id/issues/:issue_iid/resource_state_events
属性 类型 必需 描述
id integer/string 项目的 ID 或 URL 编码路径
issue_iid integer 问题的 IID

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/issues/11/resource_state_events"

示例响应:

[
  {
    "id": 142,
    "user": {
      "id": 1,
      "name": "管理员",
      "username": "root",
      "state": "active",
      "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
      "web_url": "http://gitlab.example.com/root"
    },
    "created_at": "2018-08-20T13:38:20.077Z",
    "resource_type": "Issue",
    "resource_id": 11,
    "state": "opened"
  },
  {
    "id": 143,
    "user": {
      "id": 1,
      "name": "管理员",
      "username": "root",
      "state": "active",
      "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
      "web_url": "http://gitlab.example.com/root"
    },
    "created_at": "2018-08-21T14:38:20.077Z",
    "resource_type": "Issue",
    "resource_id": 11,
    "state": "closed"
  }
]

获取单个问题状态事件

返回特定项目问题的单个状态事件。

GET /projects/:id/issues/:issue_iid/resource_state_events/:resource_state_event_id

参数:

属性 类型 必需 描述
id integer/string 项目的 ID 或 URL 编码路径
issue_iid integer 问题的 IID
resource_state_event_id integer 状态事件的 ID

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/issues/11/resource_state_events/143"

示例响应:

{
  "id": 143,
  "user": {
    "id": 1,
    "name": "管理员",
    "username": "root",
    "state": "active",
    "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
    "web_url": "http://gitlab.example.com/root"
  },
  "created_at": "2018-08-21T14:38:20.077Z",
  "resource_type": "Issue",
  "resource_id": 11,
  "state": "closed"
}

Merge requests

列出项目合并请求状态事件

获取单个合并请求的所有状态事件列表。

GET /projects/:id/merge_requests/:merge_request_iid/resource_state_events
属性 类型 必需 描述
id integer/string 项目的 ID 或 URL 编码路径
merge_request_iid integer 合并请求的 IID

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/11/resource_state_events"

示例响应:

[
  {
    "id": 142,
    "user": {
      "id": 1,
      "name": "管理员",
      "username": "root",
      "state": "active",
      "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
      "web_url": "http://gitlab.example.com/root"
    },
    "created_at": "2018-08-20T13:38:20.077Z",
    "resource_type": "MergeRequest",
    "resource_id": 11,
    "state": "opened"
  },
  {
    "id": 143,
    "user": {
      "id": 1,
      "name": "管理员",
      "username": "root",
      "state": "active",
      "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
      "web_url": "http://gitlab.example.com/root"
    },
    "created_at": "2018-08-21T14:38:20.077Z",
    "resource_type": "MergeRequest",
    "resource_id": 11,
    "state": "closed"
  }
]

获取单个合并请求状态事件

返回特定项目合并请求的单个状态事件。

GET /projects/:id/merge_requests/:merge_request_iid/resource_state_events/:resource_state_event_id

参数:

属性 类型 必需 描述
id integer/string 项目的 ID 或 URL 编码路径
merge_request_iid integer 合并请求的 IID
resource_state_event_id integer 状态事件的 ID

示例请求:

curl --request GET --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/11/resource_state_events/120"

示例响应:

{
  "id": 120,
  "user": {
    "id": 1,
    "name": "管理员",
    "username": "root",
    "state": "active",
    "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
    "web_url": "http://gitlab.example.com/root"
  },
  "created_at": "2018-08-21T14:38:20.077Z",
  "resource_type": "MergeRequest",
  "resource_id": 11,
  "state": "closed"
}

Epics

Epics REST API 在 GitLab 17.0 中被 deprecated 并计划在 API v5 中移除。 从 GitLab 17.4 到 18.0,如果启用了 epics 的新外观,在 GitLab 18.1 及更高版本中,请使用 Work Items API。更多信息,请参见 将史诗 API 迁移到工作项。 此更改是一个破坏性更改。

列出组史诗状态事件

返回单个史诗的所有状态事件列表。

GET /groups/:id/epics/:epic_id/resource_state_events
属性 类型 必需 描述
id integer/string 组的 ID 或 URL 编码路径
epic_id integer 史诗的 ID

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/5/epics/11/resource_state_events"

示例响应:

[
  {
    "id": 142,
    "user": {
      "id": 1,
      "name": "管理员",
      "username": "root",
      "state": "active",
      "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
      "web_url": "http://gitlab.example.com/root"
    },
    "created_at": "2018-08-20T13:38:20.077Z",
    "resource_type": "Epic",
    "resource_id": 11,
    "state": "opened"
  },
  {
    "id": 143,
    "user": {
      "id": 1,
      "name": "管理员",
      "username": "root",
      "state": "active",
      "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
      "web_url": "http://gitlab.example.com/root"
    },
    "created_at": "2018-08-21T14:38:20.077Z",
    "resource_type": "Epic",
    "resource_id": 11,
    "state": "closed"
  }
]

获取单个史诗状态事件

返回特定组史诗的单个状态事件。

GET /groups/:id/epics/:epic_id/resource_state_events/:resource_state_event_id

参数:

属性 类型 必需 描述
id integer/string 组的 ID 或 URL 编码路径
epic_id integer 史诗的 ID
resource_state_event_id integer 状态事件的 ID

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/5/epics/11/resource_state_events/143"

示例响应:

{
  "id": 143,
  "user": {
    "id": 1,
    "name": "管理员",
    "username": "root",
    "state": "active",
    "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
    "web_url": "http://gitlab.example.com/root"
  },
  "created_at": "2018-08-21T14:38:20.077Z",
  "resource_type": "Epic",
  "resource_id": 11,
  "state": "closed"
}