342.md 6.6 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
# Notification settings API

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

*   [Valid notification levels](#valid-notification-levels)
*   [Global notification settings](#global-notification-settings)
*   [Update global notification settings](#update-global-notification-settings)
*   [Group / project level notification settings](#group--project-level-notification-settings)
*   [Update group/project level notification settings](#update-groupproject-level-notification-settings)

# Notification settings API[](#notification-settings-api "Permalink")

在 GitLab 8.12 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/5632) .

## Valid notification levels[](#valid-notification-levels "Permalink")

通知级别在`NotificationSetting.level`模型枚举中定义. 当前,这些级别被认可:

```
disabled
participating
watch
global
mention
custom 
```

如果使用`custom`级别,则可以控制特定的电子邮件事件. 可用事件由`NotificationSetting.email_events`返回. 当前,这些事件被认可:

*   `new_note`
*   `new_issue`
*   `reopen_issue`
*   `close_issue`
*   `reassign_issue`
*   `issue_due`
*   `new_merge_request`
*   `push_to_merge_request`
*   `reopen_merge_request`
*   `close_merge_request`
*   `reassign_merge_request`
*   `merge_merge_request`
*   `failed_pipeline`
*   `fixed_pipeline`
*   `success_pipeline`
*   `new_epic`

## Global notification settings[](#global-notification-settings "Permalink")

获取当前的通知设置和电子邮件地址.

```
GET /notification_settings 
```

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

响应示例:

```
{  "level":  "participating",  "notification_email":  "admin@example.com"  } 
```

## Update global notification settings[](#update-global-notification-settings "Permalink")

更新当前的通知设置和电子邮件地址.

```
PUT /notification_settings 
```

```
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/notification_settings?level=watch" 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `level` | string | no | 全局通知级别 |
| `notification_email` | string | no | 发送通知的电子邮件地址 |
| `new_note` | boolean | no | 启用/禁用此通知 |
| `new_issue` | boolean | no | 启用/禁用此通知 |
| `reopen_issue` | boolean | no | 启用/禁用此通知 |
| `close_issue` | boolean | no | 启用/禁用此通知 |
| `reassign_issue` | boolean | no | 启用/禁用此通知 |
| `issue_due` | boolean | no | 启用/禁用此通知 |
| `new_merge_request` | boolean | no | 启用/禁用此通知 |
| `push_to_merge_request` | boolean | no | 启用/禁用此通知 |
| `reopen_merge_request` | boolean | no | 启用/禁用此通知 |
| `close_merge_request` | boolean | no | 启用/禁用此通知 |
| `reassign_merge_request` | boolean | no | 启用/禁用此通知 |
| `merge_merge_request` | boolean | no | 启用/禁用此通知 |
| `failed_pipeline` | boolean | no | 启用/禁用此通知 |
| `fixed_pipeline` | boolean | no | 启用/禁用此通知 |
| `success_pipeline` | boolean | no | 启用/禁用此通知 |
| `new_epic` | boolean | no | 启用/禁用此通知(在 11.3 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/6626) ) |

响应示例:

```
{  "level":  "watch",  "notification_email":  "admin@example.com"  } 
```

## Group / project level notification settings[](#group--project-level-notification-settings "Permalink")

获取当前的组或项目通知设置.

```
GET /groups/:id/notification_settings
GET /projects/:id/notification_settings 
```

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/5/notification_settings"
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/8/notification_settings" 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 组/项目 ID 或路径 |

响应示例:

```
{  "level":  "global"  } 
```

## Update group/project level notification settings[](#update-groupproject-level-notification-settings "Permalink")

更新当前的组/项目通知设置.

```
PUT /groups/:id/notification_settings
PUT /projects/:id/notification_settings 
```

```
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/5/notification_settings?level=watch"
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/8/notification_settings?level=custom&new_note=true" 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 组/项目 ID 或路径 |
| `level` | string | no | 全局通知级别 |
| `new_note` | boolean | no | 启用/禁用此通知 |
| `new_issue` | boolean | no | 启用/禁用此通知 |
| `reopen_issue` | boolean | no | 启用/禁用此通知 |
| `close_issue` | boolean | no | 启用/禁用此通知 |
| `reassign_issue` | boolean | no | 启用/禁用此通知 |
| `issue_due` | boolean | no | 启用/禁用此通知 |
| `new_merge_request` | boolean | no | 启用/禁用此通知 |
| `push_to_merge_request` | boolean | no | 启用/禁用此通知 |
| `reopen_merge_request` | boolean | no | 启用/禁用此通知 |
| `close_merge_request` | boolean | no | 启用/禁用此通知 |
| `reassign_merge_request` | boolean | no | 启用/禁用此通知 |
| `merge_merge_request` | boolean | no | 启用/禁用此通知 |
| `failed_pipeline` | boolean | no | 启用/禁用此通知 |
| `fixed_pipeline` | boolean | no | 启用/禁用此通知 |
| `success_pipeline` | boolean | no | 启用/禁用此通知 |
| `new_epic` | boolean | no | 启用/禁用此通知(在 11.3 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/6626) ) |

响应示例:

```
{  "level":  "watch"  }  {  "level":  "custom",  "events":  {  "new_note":  true,  "new_issue":  false,  "reopen_issue":  false,  "close_issue":  false,  "reassign_issue":  false,  "issue_due":  false,  "new_merge_request":  false,  "push_to_merge_request":  false,  "reopen_merge_request":  false,  "close_merge_request":  false,  "reassign_merge_request":  false,  "merge_merge_request":  false,  "failed_pipeline":  false,  "fixed_pipeline":  false,  "success_pipeline":  false  }  } 
```

使用 GitLab [Ultimate 或 Gold 的](https://about.gitlab.com/pricing/)用户还将看到`new_epic`参数:

```
{  "level":  "custom",  "events":  {  "new_note":  true,  "new_issue":  false,  "new_epic":  false,  ...  }  } 
```