如何通过REST API获取GitLab事故类型Issue的时间线事件?
获取GitLab事故类型Issue的时间线事件
你需要使用GitLab专门的Incident Timeline Events API来提取事故的实际时间线事件,这是你之前未尝试的专属接口。
核心接口说明
该API仅适用于GitLab EE版本,端点为:
GET /projects/:id/incidents/:incident_iid/timeline_events
示例请求
curl --location 'https://your-gitlab-instance/api/v4/projects/131/incidents/1/timeline_events' \ --header 'PRIVATE-TOKEN: your-access-token'
示例返回结果
返回的JSON数据会包含你需要的事件类型、描述等关键信息:
[ { "id": 123, "incident_id": 94, "project_id": 131, "action": "added", "author": { "id": 456, "name": "John Doe", "username": "johndoe" }, "created_at": "2024-01-25T14:06:00Z", "updated_at": "2024-01-25T14:06:00Z", "note": null, "system": false, "timeline_event_type": "impact_detected", "description": "Service X became unresponsive for EU users", "occurred_at": "2024-01-25T14:00:00Z" }, { "id": 124, "incident_id": 94, "project_id": 131, "action": "added", "author": { "id": 456, "name": "John Doe", "username": "johndoe" }, "created_at": "2024-01-25T15:30:00Z", "updated_at": "2024-01-25T15:30:00Z", "note": null, "system": false, "timeline_event_type": "end_time", "description": "Service X fully restored", "occurred_at": "2024-01-25T15:25:00Z" } ]
关键字段解释
timeline_event_type:对应你要找的"Impact detected"/"End time"等事件标签description:事件的详细说明内容occurred_at:事件实际发生的时间(区别于事件被添加到时间线的created_at)author:创建该时间线事件的用户信息
为什么之前的API无法获取?
- Notes API返回的是系统生成的操作记录(比如"added an incident timeline event"),并非时间线事件本身的结构化数据
- Events API、
resource_*_events接口聚焦于项目级活动或Issue的状态/标签变更,不包含事故专属的时间线事件数据
权限要求
调用该API需要项目的开发者及以上权限,或拥有事故管理相关的权限。
内容的提问来源于stack exchange,提问作者RubenLaguna
相关产品推荐
相关产品推荐

