事件 API

  • Tier: 基础版,专业版,旗舰版
  • Offering: JihuLab.com,私有化部署

使用此 API 来查看事件活动。事件可以包括广泛的操作,如加入项目、在议题上评论、推送更改到 MR 或关闭史诗。

有关活动保留限制的信息,请参见:

列出所有事件#

列出当前已认证用户的所有事件。不会返回与史诗相关的事件。

先决条件:

  • 您的访问令牌必须具有 read_userapi 范围。
plaintext
GET /events

参数:

参数类型必需描述
actionstring如果定义,则返回指定 操作类型 的事件。
target_typestring如果定义,则返回指定 目标类型 的事件。
beforedate (ISO 8601)如果定义,则返回在指定日期之前创建的令牌。
afterdate (ISO 8601)如果定义,则返回在指定日期之后创建的令牌。
scopestring包括用户项目中的所有事件。
sortstring按创建日期排序结果的方向。可能的值:ascdesc。默认值:desc

请求示例:

shell
curl --request GET \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/events?target_type=issue&action=created&after=2017-01-31&before=2017-03-01&scope=all"

响应示例:

json
1[ 2 { 3 "id": 1, 4 "title":null, 5 "project_id":1, 6 "action_name":"opened", 7 "target_id":160, 8 "target_iid":53, 9 "target_type":"Issue", 10 "author_id":25, 11 "target_title":"Qui natus eos odio tempore et quaerat consequuntur ducimus cupiditate quis.", 12 "created_at":"2017-02-09T10:43:19.667Z", 13 "author":{ 14 "name":"User 3", 15 "username":"user3", 16 "id":25, 17 "state":"active", 18 "avatar_url":"http://www.gravatar.com/avatar/97d6d9441ff85fdc730e02a6068d267b?s=80\u0026d=identicon", 19 "web_url":"https://gitlab.example.com/user3" 20 }, 21 "author_username":"user3", 22 "imported":false, 23 "imported_from": "none" 24 }, 25 { 26 "id": 2, 27 "title":null, 28 "project_id":1, 29 "action_name":"opened", 30 "target_id":159, 31 "target_iid":14, 32 "target_type":"Issue", 33 "author_id":21, 34 "target_title":"Nostrum enim non et sed optio illo deleniti non.", 35 "created_at":"2017-02-09T10:43:19.426Z", 36 "author":{ 37 "name":"Test User", 38 "username":"ted", 39 "id":21, 40 "state":"active", 41 "avatar_url":"http://www.gravatar.com/avatar/80fb888c9a48b9a3f87477214acaa63f?s=80\u0026d=identicon", 42 "web_url":"https://gitlab.example.com/ted" 43 }, 44 "author_username":"ted", 45 "imported":false, 46 "imported_from": "none" 47 } 48]

获取用户的贡献事件#

获取指定用户的贡献事件。不会返回与史诗相关的事件。

先决条件:

  • 您的访问令牌必须具有 read_userapi 范围。
plaintext
GET /users/:id/events

参数:

参数类型必需描述
idinteger用户的 ID 或用户名。
actionstring如果定义,则返回指定 操作类型 的事件。
target_typestring如果定义,则返回指定 目标类型 的事件。
beforedate (ISO 8601)如果定义,则返回在指定日期之前创建的令牌。
afterdate (ISO 8601)如果定义,则返回在指定日期之后创建的令牌。
sortstring按创建日期排序结果的方向。可能的值:ascdesc。默认值:desc
pageinteger返回指定结果页。默认值:1
per_pageinteger每页结果数。默认值:20

请求示例:

shell
curl --request GET \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/users/:id/events"

响应示例:

json
1[ 2 { 3 "id": 3, 4 "title": null, 5 "project_id": 15, 6 "action_name": "closed", 7 "target_id": 830, 8 "target_iid": 82, 9 "target_type": "Issue", 10 "author_id": 1, 11 "target_title": "Public project search field", 12 "author": { 13 "name": "Dmitriy Zaporozhets", 14 "username": "root", 15 "id": 1, 16 "state": "active", 17 "avatar_url": "http://localhost:3000/uploads/user/avatar/1/fox_avatar.png", 18 "web_url": "http://localhost:3000/root" 19 }, 20 "author_username": "root", 21 "imported": false, 22 "imported_from": "none" 23 }, 24 { 25 "id": 4, 26 "title": null, 27 "project_id": 15, 28 "action_name": "pushed", 29 "target_id": null, 30 "target_iid": null, 31 "target_type": null, 32 "author_id": 1, 33 "author": { 34 "name": "Dmitriy Zaporozhets", 35 "username": "root", 36 "id": 1, 37 "state": "active", 38 "avatar_url": "http://localhost:3000/uploads/user/avatar/1/fox_avatar.png", 39 "web_url": "http://localhost:3000/root" 40 }, 41 "author_username": "john", 42 "imported": false, 43 "imported_from": "none", 44 "push_data": { 45 "commit_count": 1, 46 "action": "pushed", 47 "ref_type": "branch", 48 "commit_from": "50d4420237a9de7be1304607147aec22e4a14af7", 49 "commit_to": "c5feabde2d8cd023215af4d2ceeb7a64839fc428", 50 "ref": "main", 51 "commit_title": "Add simple search to projects in public area" 52 }, 53 "target_title": null 54 }, 55 { 56 "id": 5, 57 "title": null, 58 "project_id": 15, 59 "action_name": "closed", 60 "target_id": 840, 61 "target_iid": 11, 62 "target_type": "Issue", 63 "author_id": 1, 64 "target_title": "Finish & merge Code search PR", 65 "author": { 66 "name": "Dmitriy Zaporozhets", 67 "username": "root", 68 "id": 1, 69 "state": "active", 70 "avatar_url": "http://localhost:3000/uploads/user/avatar/1/fox_avatar.png", 71 "web_url": "http://localhost:3000/root" 72 }, 73 "author_username": "root", 74 "imported": false, 75 "imported_from": "none" 76 }, 77 { 78 "id": 7, 79 "title": null, 80 "project_id": 15, 81 "action_name": "commented on", 82 "target_id": 1312, 83 "target_iid": 61, 84 "target_type": "Note", 85 "author_id": 1, 86 "target_title": null, 87 "created_at": "2015-12-04T10:33:58.089Z", 88 "note": { 89 "id": 1312, 90 "body": "What an awesome day!", 91 "attachment": null, 92 "author": { 93 "name": "Dmitriy Zaporozhets", 94 "username": "root", 95 "id": 1, 96 "state": "active", 97 "avatar_url": "http://localhost:3000/uploads/user/avatar/1/fox_avatar.png", 98 "web_url": "http://localhost:3000/root" 99 }, 100 "created_at": "2015-12-04T10:33:56.698Z", 101 "system": false, 102 "noteable_id": 377, 103 "noteable_type": "Issue" 104 }, 105 "author": { 106 "name": "Dmitriy Zaporozhets", 107 "username": "root", 108 "id": 1, 109 "state": "active", 110 "avatar_url": "http://localhost:3000/uploads/user/avatar/1/fox_avatar.png", 111 "web_url": "http://localhost:3000/root" 112 }, 113 "author_username": "root", 114 "imported": false, 115 "imported_from": "none" 116 } 117]

列出项目的可见事件#

列出指定项目的所有可见事件。

plaintext
GET /projects/:project_id/events

参数:

参数类型必需描述
project_idinteger/string项目的 ID 或 URL 编码路径
actionstring如果定义,则返回指定 操作类型 的事件。
target_typestring如果定义,则返回指定 目标类型 的事件。
beforedate (ISO 8601)如果定义,则返回在指定日期之前创建的令牌。
afterdate (ISO 8601)如果定义,则返回在指定日期之后创建的令牌。
sortstring按创建日期排序结果的方向。可能的值:ascdesc。默认值:desc

请求示例:

shell
curl --request GET \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/:project_id/events?target_type=issue&action=created&after=2017-01-31&before=2017-03-01"

响应示例:

json
1[ 2 { 3 "id": 8, 4 "title":null, 5 "project_id":1, 6 "action_name":"opened", 7 "target_id":160, 8 "target_iid":160, 9 "target_type":"Issue", 10 "author_id":25, 11 "target_title":"Qui natus eos odio tempore et quaerat consequuntur ducimus cupiditate quis.", 12 "created_at":"2017-02-09T10:43:19.667Z", 13 "author":{ 14 "name":"User 3", 15 "username":"user3", 16 "id":25, 17 "state":"active", 18 "avatar_url":"http://www.gravatar.com/avatar/97d6d9441ff85fdc730e02a6068d267b?s=80\u0026d=identicon", 19 "web_url":"https://gitlab.example.com/user3" 20 }, 21 "author_username":"user3", 22 "imported":false, 23 "imported_from": "none" 24 }, 25 { 26 "id": 9, 27 "title":null, 28 "project_id":1, 29 "action_name":"opened", 30 "target_id":159, 31 "target_iid":159, 32 "target_type":"Issue", 33 "author_id":21, 34 "target_title":"Nostrum enim non et sed optio illo deleniti non.", 35 "created_at":"2017-02-09T10:43:19.426Z", 36 "author":{ 37 "name":"Test User", 38 "username":"ted", 39 "id":21, 40 "state":"active", 41 "avatar_url":"http://www.gravatar.com/avatar/80fb888c9a48b9a3f87477214acaa63f?s=80\u0026d=identicon", 42 "web_url":"https://gitlab.example.com/ted" 43 }, 44 "author_username":"ted", 45 "imported":false, 46 "imported_from": "none" 47 }, 48 { 49 "id": 10, 50 "title": null, 51 "project_id": 1, 52 "action_name": "commented on", 53 "target_id": 1312, 54 "target_iid": 1312, 55 "target_type": "Note", 56 "author_id": 1, 57 "data": null, 58 "target_title": null, 59 "created_at": "2015-12-04T10:33:58.089Z", 60 "note": { 61 "id": 1312, 62 "body": "What an awesome day!", 63 "attachment": null, 64 "author": { 65 "name": "Dmitriy Zaporozhets", 66 "username": "root", 67 "id": 1, 68 "state": "active", 69 "avatar_url": "https://gitlab.example.com/uploads/user/avatar/1/fox_avatar.png", 70 "web_url": "https://gitlab.example.com/root" 71 }, 72 "created_at": "2015-12-04T10:33:56.698Z", 73 "system": false, 74 "noteable_id": 377, 75 "noteable_type": "Issue", 76 "noteable_iid": 377 77 }, 78 "author": { 79 "name": "Dmitriy Zaporozhets", 80 "username": "root", 81 "id": 1, 82 "state": "active", 83 "avatar_url": "https://gitlab.example.com/uploads/user/avatar/1/fox_avatar.png", 84 "web_url": "https://gitlab.example.com/root" 85 }, 86 "author_username": "root", 87 "imported": false, 88 "imported_from": "none" 89 } 90]

目标类型#

History
    • 在极狐GitLab 17.3 中增加了 epic

您可以过滤结果以返回来自特定目标类型的事件。可能的值是:

  • epic1
  • issue
  • merge_request
  • milestone
  • note2
  • project
  • snippet
  • user

脚注:

  1. 您必须启用 新的史诗外观。一些史诗功能,如子项目、链接项目、开始日期、截止日期和健康状态不会通过 API 返回。
  2. 一些合并请求备注可能会使用 DiscussionNote 类型。此目标类型 不受 API 支持