发布打开的请求列表
pr-publisher的Python项目详细描述
概述
这是一个cli工具,可以列出打开的pull请求并将它们发布到某个地方, 主要是松懈。这有助于帮助团队保持对拉取请求的控制 评论。
它是可配置的,支持多个发布服务器,并且易于编写 你自己的出版商。
pip install pr-publisher
注意:这不是一个bot,不是一个slack插件,也不支持 从命令行以任何方式更新拉取请求。
请报告任何问题或功能请求on Github
用法
这将安装名为pr-publisher
,
pr-publisher --help
参数与cli选项或环境变量一起提供。见
--help
输出或下面的可用选项。
基本用法
该工具需要具有repo
和read:org
权限的github个人访问令牌。
[x] repo
[ ] admin:org
[ ] write:org
[x] read:org
(注意:它将尝试读取分支保护设置以确定所需的 检查存储库。我忘了是否需要额外的许可 为此)
通过cli选项或环境变量提供令牌。
Flag | Env Var | Example |
---|---|---|
^{ | ^{ | ^{ |
^{ | ^{ | |
^{ | ^{ | ^{ |
^{ | ||
^{ | ^{ | |
^{ | ^{ | |
^{ |
目前,github组织是必需的。打开拉取请求将是 从组织中的所有存储库中发现。或者,该列表可以是 过滤到由特定github用户名拥有的用户。
支持Github Enterprise。只需为您的github企业url提供
--github-url
(但是,我没有测试2fa)。
### Using flags
pr-publisher --github-org my-org --github-token <token> table slack
### Using environment variablesexportGITHUB_TOKEN=<token> exportGITHUB_ORG=my-org pr-publisher --users pglass,hotpie table slack
默认情况下,标题包含“WIP”(不区分大小写)的prs将被忽略。
如果希望包含这些标记,请使用--include-wip
标记。
出版商
脚本接受发布者名称列表。目前有两个出版商
table
:将表中的拉取请求列表打印到stdoutslack
:将拉取请求列表发布到slack
指定的每个发布服务器都将运行并发布打开的请求列表 请求。
### Run the "table" publisher pr-publisher <options> table ### Run both the "table" and "slack" publishers pr-publisher <options> table slack
松弛发布器
slack发布服务器需要slack url和令牌。目前,松懈 jenkins-ci集成url是唯一一个经过测试且已知有效的webhook url。
下面是一个完整的选项列表,
Flag | Env Var | Example |
---|---|---|
^{ | ^{ | |
^{ | ^{ | ^{ |
^{ | ^{ | ^{ |
^{ | ^{ | ^{ |
^{ | ^{ | ^{ |
^{ | ^{ | ^{ |
^{ | ^{ | ^{ |
^{ | ^{ | ^{ |
- 松弛通道是可选的。如果未提供,则将松弛消息发送到 与令牌关联的通道。
- 所有emojis默认为空字符串,如果您愿意,可以是纯文本字符串
- “已批准”和“请求更改”emojis用于显示拉取请求
批准。如果您的团队需要对拉取请求进行最少数量的批准,
您应该提供
--approvals-needed
标志来显示还有多少个批准 是必要的。
自定义发布服务器
编写自己的自定义发布服务器有两个基本步骤,
- 创建发布者类时的子类
BasePublisher
- 向
Main
注册您的出版商
Here's a basic example。你创造了 publisher类,添加任何您喜欢的cli参数,然后实现发布 方法。
"""Example of a custom publisher"""frompr_publisher.publishers.baseimportBasePublisherfrompr_publisher.mainimportMainclassCustomPublisher(BasePublisher):@classmethoddefadd_cli_arguments(cls,parser):# All publisher cli args should be optional. (A user may only care to# run a single publisher, and doesn't want to supply values for the# rest of the publishers)parser.add_argument("--some-chat-url",default=None)def__init__(self,args):super(CustomPublisher,self).__init__(args)ifnotargs.some_chat_url:raiseException("--some-chat-url is required")defpublish(self,publish_entries):forentryinpublish_entries:# Just printing, for the sake of this example.# see pr_publisher.entry.PublishEntry for all available fields.print("{}\n{}".format(entry.pr.title,entry.pr.html_url))defmain():# Register the publisher before we run the programMain.register_publisher("some-chat",CustomPublisher)# Run the programMain().run()if__name__=="__main__":main()
你现在已经把你的出版商联系上了。您应该看到新的cli参数
为some-chat
发布服务器显示,并为所有其他发布服务器显示cli参数
已注册的发布服务器(但在示例中会截断此发布服务器)。
$ python custom_publisher.py -h ... positional arguments: {table,slack,some-chat} List of publishers to run optional arguments: -h, --help show this help message and exit ... --some-chat-url SOME_CHAT_URL
要运行发布服务器,请在命令中指定发布服务器名称(some-chat
)
行。
$ python custom_publisher.py ... --some-chat-url 'http://chat.example.com' --users pglass some-chat
Logging in...
Collecting info...
Publishing with CustomPublisher
Fixing some bug
https://github.com/pglass/pr-publisher/pull/2
Fixing another bug
https://github.com/pglass/pr-publisher/pull/5
Adding some feature
https://github.com/pglass/pr-publisher/pull/6