5个不稳定版本
0.3.0 | 2023年12月2日 |
---|---|
0.2.1 | 2023年11月12日 |
0.2.0 | 2023年11月11日 |
0.1.1 | 2023年11月10日 |
0.1.0 | 2023年11月9日 |
#742 in 文本处理
每月 39 次下载
29KB
799 代码行
Unfurl
Unfurl 扩展文本中的链接,并用有用的内容替换它们。
$ unfurl <<EOF
This issue was resolved: https://github.com/bww/unfurl/issues/1
EOF
This issue was resolved: This is just an example issue (#1)
$
支持的服务和路由
Unfurl默认支持扩展以下URL类型
-
GitHub
- PRs
https://api.github.com/repos/{org}/{repo}/pulls/{num}'
- 问题
https://api.github.com/repos/{org}/{repo}/issues/{num}
- PRs
-
Jira Cloud
- 问题
https://{domain}/rest/api/3/issue/{key}
- 问题
您可以通过配置路由定义并在命令行上指定它(使用 --routes <definition.yml>
)来添加对更多服务的支持。内置的路由定义文件可以作为参考。自定义路由附加到内置路由,并具有优先权。
总体来说,Unfurl匹配一个表示/浏览器URL,将其转换为API对应项(或者可能只是向相同的URL提供合适的头信息),以结构化的形式表示相同的信息。然后默认格式确定如何将结构化数据渲染为文本。以下是一个示例
github.com:
routes:
- name: pr
route: "/{org}/{repo}/pull/{num}"
url: "https://api.github.com/repos/{org}/{repo}/pulls/{num}"
format: "{title} (PR #{number})"
路由.yml
向服务进行身份验证
默认情况下,Unfurl将支持受支持的公共URL按预期工作。然而,通常这些服务上托管的URL不是公开的,因此您可能需要提供一些凭据。这可以通过配置文件完成,默认情况下位于 $HOME/.unfurl.yml
。
自定义输出格式
您还可以通过定义每个URL的格式化模板来指定URL的扩展方式。此格式的输入是从底层服务收到的JSON,因此您可以使用服务API提供的任何信息。
示例配置文件
services:
# We provide authentication and custom formatting for GitHub routes. You
# cannot define routes in a configuration file, use a route definition
# file for that.
github.com:
auth: # optionally provide authentication to expand non-public URLs
header: Bearer $YOUR_PERSONAL_ACCESS_TOKEN
format: # optionally define formats for these URL patterns
pr: "[{number}] {title} ({url})"
issue: "[{number}] {title} ({url})"
# Jira configurations are per-cloud-tenant: specify your domain. (Unfurl
# will fail over to the base domain, `atlassian.net` in this case, if no
# exact match is found.)
treno.atlassian.net:
auth:
header: Basic $YOUR_PERSONAL_ACCESS_CREDENTIALS
format:
issue: "[{key}] {fields.summary}"
# And so on for whatever other domains you have added...
twitter.com:
auth:
header: # ...
$HOME/.unfurl.yml
依赖关系
~11–26MB
~428K SLoC