374.md 3.1 KB
Newer Older
Lab机器人's avatar
readme  
Lab机器人 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
# System hooks API

> 原文:[https://docs.gitlab.com/ee/api/system_hooks.html](https://docs.gitlab.com/ee/api/system_hooks.html)

*   [List system hooks](#list-system-hooks)
*   [Add new system hook](#add-new-system-hook)
*   [Test system hook](#test-system-hook)
*   [Delete system hook](#delete-system-hook)

# System hooks API[](#system-hooks-api "Permalink")

所有方法都需要管理员授权.

也可以使用**Admin Area> System Hooks**`/admin/hooks` )中的 UI 来配置系统挂钩的 URL 端点.

阅读有关[系统挂钩的](../system_hooks/system_hooks.html)更多信息.

## List system hooks[](#list-system-hooks "Permalink")

获取所有系统挂钩的列表.

```
GET /hooks 
```

请求示例:

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/hooks" 
```

响应示例:

```
[  {  "id":1,  "url":"https://gitlab.example.com/hook",  "created_at":"2016-10-31T12:32:15.192Z",  "push_events":true,  "tag_push_events":false,  "merge_requests_events":  true,  "repository_update_events":  true,  "enable_ssl_verification":true  }  ] 
```

## Add new system hook[](#add-new-system-hook "Permalink")

添加一个新的系统挂钩.

```
POST /hooks 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `url` | string | yes | 挂钩网址 |
| `token` | string | no | 用于验证收到的有效载荷的秘密令牌; 这将不会在响应中返回 |
| `push_events` | boolean | no | 设置为 true 时,挂钩将在推送事件时触发 |
| `tag_push_events` | boolean | no | 设置为 true 时,挂钩将在被推送的新标签上触发 |
| `merge_requests_events` | boolean | no | 触发合并请求事件的钩子 |
| `repository_update_events` | boolean | no | 触发挂钩存储库更新事件 |
| `enable_ssl_verification` | boolean | no | 触发挂钩时执行 SSL 验证 |

请求示例:

```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/hooks?url=https://gitlab.example.com/hook" 
```

响应示例:

```
[  {  "id":1,  "url":"https://gitlab.example.com/hook",  "created_at":"2016-10-31T12:32:15.192Z",  "push_events":true,  "tag_push_events":false,  "merge_requests_events":  true,  "repository_update_events":  true,  "enable_ssl_verification":true  }  ] 
```

## Test system hook[](#test-system-hook "Permalink")

```
GET /hooks/:id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer | yes | 钩子的 ID |

请求示例:

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/hooks/2" 
```

响应示例:

```
{  "project_id"  :  1,  "owner_email"  :  "example@gitlabhq.com",  "owner_name"  :  "Someone",  "name"  :  "Ruby",  "path"  :  "ruby",  "event_name"  :  "project_create"  } 
```

## Delete system hook[](#delete-system-hook "Permalink")

删除系统挂钩.

```
DELETE /hooks/:id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer | yes | 钩子的 ID |

请求示例:

```
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/hooks/2" 
```