Skip to main content

通知

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

使用

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

Verdaccio supports any API, feel free to add more examples.

单个通知

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 作为主要模板引擎。

格式范例

# iterate all versions
{{ name }}{{#each versions}} v{{version}}{{/each}}

# publisher and `dist-tag` package published
{{ 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属性,是不可能再拿到发表人信息的。

已发布包

You can access to the package is being published with the keyword {{publishedPackage}} as follows.

{{ publisher.name }} has published {{ publishedPackage }}

Configuration

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