pypyr slack插件:从pypyr管道发送slack消息
pypyrslack的Python项目详细描述
- pypyr
- 你喜欢怎么发音,但我通常说piper如“piping down the 野生山谷“
从pypyr向slack发送消息。这对 发送有关管道中的成功或失败情况的通知。或者 因为你可以发送信息。
pypyr是 运行yaml中定义的管道。
1 Installation
1.2 Python version
针对python进行测试>;=3.6
2 steps
pypyyrslack.steps.send发送
向Slack发送消息。
2.2 Text substitutions
对于slackchannel和slacktext,可以使用替换标记,也就是string
插值。这将用上下文替换大括号之间的任何内容
那个键的值。例如,如果您的上下文是这样的:
arbitraryValue:pypyrchannelarbitraryText:down themoreArbText:wildslackChannel:"#{arbitraryValue}"slackText:"piping{arbitraryText}valleys{moreArbText}"
这将导致向pypyryrchannel发送带有文本的消息:
将值压缩为wild
带双精度的转义文字大括号:{{表示{,}}表示}
请参阅一个有效的示例for substitutions here。
2.3 Sample pipeline
下面是一些使用pypyr slack插件的管道示例yaml
可能看起来像:
steps:-name:pypyrslack.steps.echoin:echoMe:"justanarbstepthatmayormaynotfail."-name:pypyrslack.steps.sendin:slackToken:supersecurevaluegoeshereslackChannel:"#channelnamehere"slackText:"pypyrisbusydoingthings:construction:"# The slackToken and slackChannel have already been set in steps# on_success and on_failure are just changing the text for the message.on_success:-name:pypyrslack.steps.sendin:slackText:"thatwentwell!:hotdog:"on_failure:-name:pypyrslack.steps.sendin:slackText:"whoops!:rage1:"
如果将此yaml保存为./pipelines/hoping-for-a-hotdog.yaml,则可以运行
来自/以下:
pypyr hoping-for-a-hotdog
请参阅pypyr slack here的工作示例。
2.2 Text substitutions
对于slackchannel和slacktext,可以使用替换标记,也就是string 插值。这将用上下文替换大括号之间的任何内容 那个键的值。例如,如果您的上下文是这样的:
arbitraryValue:pypyrchannelarbitraryText:down themoreArbText:wildslackChannel:"#{arbitraryValue}"slackText:"piping{arbitraryText}valleys{moreArbText}"
这将导致向pypyryrchannel发送带有文本的消息:
将值压缩为wild
带双精度的转义文字大括号:{{表示{,}}表示}
请参阅一个有效的示例for substitutions here。
2.3 Sample pipeline
下面是一些使用pypyr slack插件的管道示例yaml 可能看起来像:
steps:-name:pypyrslack.steps.echoin:echoMe:"justanarbstepthatmayormaynotfail."-name:pypyrslack.steps.sendin:slackToken:supersecurevaluegoeshereslackChannel:"#channelnamehere"slackText:"pypyrisbusydoingthings:construction:"# The slackToken and slackChannel have already been set in steps# on_success and on_failure are just changing the text for the message.on_success:-name:pypyrslack.steps.sendin:slackText:"thatwentwell!:hotdog:"on_failure:-name:pypyrslack.steps.sendin:slackText:"whoops!:rage1:"
如果将此yaml保存为./pipelines/hoping-for-a-hotdog.yaml,则可以运行 来自/以下:
pypyr hoping-for-a-hotdog
请参阅pypyr slack here的工作示例。
3 slack authentication
3.1 Get slack api token
要根据松弛时间进行身份验证,需要创建一个api密钥。有 使用遗留令牌、测试令牌或bot实现此目的的各种方法。
我通常是create a bot。鉴于 你可能只是用它来向slack发送通知,而不是 使用slack中的事件,这是一个非常简单的设置,只是为了获取api密钥。
记住邀请并将创建的机器人添加到松弛通道 你想发帖。像邀请普通用户一样邀请机器人加入。
3.2 Ensure secrets stay secret
安全!不要硬编码api令牌,不要将其签入公共repo。 下面是一些处理来自slack的api令牌的技巧。
请记住不要将api密钥作为shell参数到处乱扔-它可以 很容易通过ps泄漏到日志或公开。我通常用一个 pypyr内置的上下文解析器中,比如pypypyr.parser.jsonfile或 pypypyr.parser.yamlfile,请参阅 here for details。
4 Testing
4.1 Testing without worrying about dependencies
从tox运行以测试虚拟环境中的打包周期,并运行all 测试:
# just run tests $ tox -e dev -- tests # run tests, validate README.rst, run flake8 linter $ tox -e stage -- tests
4.3 Day-to-day testing
测试在/tests下运行(令人惊讶,嗯?).mirror的目录结构 正在测试的代码。
在测试定义前面加上test{eem>-因此一个单元t看起来像
deftest_this_should_totally_work():
要执行测试,请从根目录:
pytest tests
有关运行测试的更多信息:
pytest --verbose [path]
执行特定测试模块:
pytest tests/unit/arb_test_file.py
6 Contribute
6.1 Developers
有关如何帮助pypyr、运行测试和覆盖率的信息,请执行 查看contribution guide。
6.2 Bugs
好吧,你知道的。没有人是完美的。请随意create an issue。