跳到主要内容
版本号:Next

通知

创建通知主要是与Slack的输入webhooks一起使用,但它也会传递简单的载荷到任何末端。 目前只对 npm publish命令有效。

使用

HipChat, StrideGoogle Hangouts Chat hook的一个范例:

Verdaccio 支持任何 API,欢迎添加更多示例。

单个通知

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"}'

多通知

notify:
'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':
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"}'
'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 }}"}]}]}}'

模板

我们用Handlebars 作为主要模板引擎。

格式范例

# 遍历所有版本
{{ name }}{{#each versions}} v{{version}}{{{/each}}
# 发布者和发布的软件包 `dist-tag`
{{ publisher.name }} has published {{ publishedPackage }}

属性

通过模板进入的属性列表

  • 元数据
  • 发表者(在发表的人)
  • 已发布的包(包@1.0.0)

元数据

模板可以访问的包元数据

{
"_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": {}
}

发表人

您可以用publisher object(对象)在webhook的content里访问包发表人信息。

请参阅以下publisher object(对象)类别:

{
name: string,
groups: string[],
real_groups: string[]
}

范例:

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"}' Publisher name: * {{ publisher.name }} *.","notify":true,"message_format":"text"}'

请注意: 如果 package.json 文件已经有publisher属性,是不可能再拿到发表人信息的。

已发布包

您可以使用关键字 {{publishedPackage}} 访问已经发布的包,如下所示。

{{ publisher.name }} 发布了 {{ publishedPackage }}

配置

属性类型必须的支持版本默认值描述
methodstring全部HTTP 方法
packagePatternstring全部仅当包名字和正规表达式匹配时才运行此通知
packagePatternFlagsstring全部任何与正规表达式一起使用的标记
headersarray/object全部如果此端点需要特定的标头,请把它们设置为键数组:value objects(值对象)。
endpointstring全部设置此调用的URL 端点
contentstring全部任何Handlebar表达式