2018-01-08 20:45:03 +01:00
|
|
|
|
---
|
2018-07-17 10:41:31 +02:00
|
|
|
|
id: 通知
|
|
|
|
|
title: "通知"
|
2018-01-08 20:45:03 +01:00
|
|
|
|
---
|
2018-07-17 10:41:31 +02:00
|
|
|
|
创建通知主要是与Slack的输入webhooks一起使用,但它也会传递简单的载荷到任何末端。目前只对 `npm publish`命令有效。
|
2018-01-08 20:45:03 +01:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
## 使用
|
2018-01-08 20:45:03 +01:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
**HipChat**, **Stride** 和 **Google Hangouts Chat** hook的一个范例:
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
> Verdaccio 支持任何 API, 请随意添加更多范例。
|
2018-01-08 20:45:03 +01:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
#### 单个通知
|
2018-01-08 20:45:03 +01:00
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
notify:
|
|
|
|
|
method: POST
|
|
|
|
|
headers: [{'Content-Type': 'application/json'}]
|
|
|
|
|
endpoint: https://usagge.hipchat.com/v2/room/3729485/notification?auth_token=mySecretToken
|
|
|
|
|
content: '{"color":"green","message":"New package published: * {{ name }}*","notify":true,"message_format":"text"}'
|
|
|
|
|
```
|
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
#### 多通知
|
2018-01-08 20:45:03 +01:00
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
notify:
|
2018-05-24 13:08:15 +02:00
|
|
|
|
'example-google-chat':
|
|
|
|
|
method: POST
|
|
|
|
|
headers: [{'Content-Type': 'application/json'}]
|
|
|
|
|
endpoint: https://chat.googleapis.com/v1/spaces/AAAAB_TcJYs/messages?key=myKey&token=myToken
|
|
|
|
|
content: '{"text":"New package published: `{{ name }}{{#each versions}} v{{version}}{{/each}}`"}'
|
|
|
|
|
'example-hipchat':
|
2018-01-08 20:45:03 +01:00
|
|
|
|
method: POST
|
|
|
|
|
headers: [{'Content-Type': 'application/json'}]
|
|
|
|
|
endpoint: https://usagge.hipchat.com/v2/room/3729485/notification?auth_token=mySecretToken
|
|
|
|
|
content: '{"color":"green","message":"New package published: * {{ name }}*","notify":true,"message_format":"text"}'
|
2018-06-14 09:02:21 +02:00
|
|
|
|
'example-stride':
|
|
|
|
|
method: POST
|
|
|
|
|
headers: [{'Content-Type': 'application/json'}, {'authorization': 'Bearer secretToken'}]
|
|
|
|
|
endpoint: https://api.atlassian.com/site/{cloudId}/conversation/{conversationId}/message
|
|
|
|
|
content: '{"body": {"version": 1,"type": "doc","content": [{"type": "paragraph","content": [{"type": "text","text": "New package published: * {{ name }}* Publisher name: * {{ publisher.name }}"}]}]}}'
|
2018-01-08 20:45:03 +01:00
|
|
|
|
```
|
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
## 模板
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
我们用[Handlebars](https://handlebarsjs.com/) 作为主要模板引擎。
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
### 格式范例
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
# 重复所有版本
|
2018-06-14 09:02:21 +02:00
|
|
|
|
{{ name }}{{#each versions}} v{{version}}{{/each}}`"}
|
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
# 已发布的发表人和 `dist-tag` 包
|
2018-06-14 09:02:21 +02:00
|
|
|
|
{{ publisher.name }} has published {{publishedPackage}}"}
|
|
|
|
|
|
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
### 属性
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
通过模板进入的属性列表
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
* 元数据
|
|
|
|
|
* 发表者(在发表的人)
|
|
|
|
|
* 已发布的包(包@1.0.0)
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
### 元数据
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
模板可以访问的包元数据
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"_id": "@test/pkg1",
|
|
|
|
|
"name": "@test/pkg1",
|
|
|
|
|
"description": "",
|
|
|
|
|
"dist-tags": {
|
|
|
|
|
"beta": "1.0.54"
|
|
|
|
|
},
|
|
|
|
|
"versions": {
|
|
|
|
|
"1.0.54": {
|
|
|
|
|
"name": "@test/pkg1",
|
|
|
|
|
"version": "1.0.54",
|
|
|
|
|
"description": "some description",
|
|
|
|
|
"main": "index.js",
|
|
|
|
|
"scripts": {
|
|
|
|
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
|
|
|
},
|
|
|
|
|
"keywords": [],
|
|
|
|
|
"author": {
|
|
|
|
|
"name": "Author Name",
|
|
|
|
|
"email": "author@domain.com"
|
|
|
|
|
},
|
|
|
|
|
"license": "MIT",
|
|
|
|
|
"dependencies": {
|
|
|
|
|
"webpack": "4.12.0"
|
|
|
|
|
},
|
|
|
|
|
"readmeFilename": "README.md",
|
|
|
|
|
"_id": "@ test/pkg1@1.0.54",
|
|
|
|
|
"_npmVersion": "6.1.0",
|
|
|
|
|
"_nodeVersion": "9.9.0",
|
|
|
|
|
"_npmUser": {},
|
|
|
|
|
"dist": {
|
|
|
|
|
"integrity": "sha512-JlXWpLtMUBAqvVZBvH7UVLhXkGE1ctmXbDjbH/l0zMuG7wVzQ7GshTYvD/b5C+G2vOL2oiIS1RtayA/kKkTwKw==",
|
|
|
|
|
"shasum": "29c55c52c1e76e966e706165e5b9f22e32aa9f22",
|
|
|
|
|
"tarball": "http://localhost:4873/@test/pkg1/-/@test/pkg1-1.0.54.tgz"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"readme": "# test",
|
|
|
|
|
"_attachments": {
|
|
|
|
|
"@test/pkg1-1.0.54.tgz": {
|
|
|
|
|
"content_type": "application/octet-stream",
|
|
|
|
|
"data": "H4sIAAAAAAAAE+y9Z5PjyJIgOJ ...",
|
|
|
|
|
"length": 33112
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"time": {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
### 发表人
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
您可以用`publisher` object(对象)在webhook的`content`里访问包发表人信息。
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
请参阅以下`publisher` object(对象)类别:
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
name: string,
|
|
|
|
|
groups: string[],
|
|
|
|
|
real_groups: string[]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
范例:
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
|
|
|
|
notify:
|
|
|
|
|
method: POST
|
|
|
|
|
headers: [{'Content-Type': 'application/json'}]
|
|
|
|
|
endpoint: https://usagge.hipchat.com/v2/room/3729485/notification?auth_token=mySecretToken
|
|
|
|
|
content: '{"color":"green","message":"New package published: * {{ name }}*. Publisher name: * {{ publisher.name }} *.","notify":true,"message_format":"text"}'
|
|
|
|
|
|
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
**请注意:** 如果 `package.json` 文件已经有`publisher`属性,是不可能再拿到发表人信息的。
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
### 已发布包
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
您可以如以下所示用热词`{{publishedPackage}}` 来访问已经发布的包.
|
2018-06-14 09:02:21 +02:00
|
|
|
|
|
|
|
|
|
{{ publisher.name }} has published {{publishedPackage}}"}
|
|
|
|
|
|
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
## 配置
|
2018-01-08 20:45:03 +01:00
|
|
|
|
|
2018-07-17 10:41:31 +02:00
|
|
|
|
| 属性 | 类型 | 必填 | 支持 | 默认 | 描述 |
|
|
|
|
|
| ------------------- | ----- | -- | ---- | -- | ------------------------------------------- |
|
|
|
|
|
| 方法 | 字符串 | 不 | 任意路径 | | HTTP verb |
|
|
|
|
|
| packagePattern | 字符串 | 不 | 任意路径 | | 仅当包名字和正规表达式匹配时才运行此通知 |
|
|
|
|
|
| packagePatternFlags | 字符串 | 不 | 任意路径 | | 任何与正规表达式一起使用的标记 |
|
|
|
|
|
| 标头 | 数组/对象 | 是 | 任意路径 | | 如果此端点需要特定的标头,请把它们设置为键数组:value objects(值对象)。 |
|
|
|
|
|
| 端点 | 字符串 | 是 | 任意路径 | | 设置此调用的URL 端点 |
|
|
|
|
|
| 内容 | 字符串 | 是 | 任意路径 | | 任何[Handlebar](https://handlebarsjs.com/)表达式 |
|