• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

swinton/httpie.action: Human-friendly interactions with third-party web services ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

swinton/httpie.action

开源软件地址:

https://github.com/swinton/httpie.action

开源编程语言:

HCL 39.4%

开源软件介绍:

httpie.action

Human-friendly interactions with third-party web services through GitHub Actions

A general purpose HTTP client for GitHub Actions, wrapping the HTTPie CLI to enable human-friendly interactions with third-party web services that expose an API over HTTP in your development workflow.

Why not just use webhooks?

Great question! Webhooks will likely just work in the vast majority of cases

In certain situations though, this may be a better solution, as it provides more fine-grained control over the HTTP request that gets sent, for example you can:

  1. Form an entirely custom payload
  2. Use a variety of different authentication methods
  3. Use a variety of different request methods (GET, POST, PATCH, etc.)
  4. Send a variety of different MIME types
  5. Follow any redirects
  6. Act on the HTTP response
  7. Basically, leverage all of the features of HTTPie

Super simple example

To POST some JSON data, {"hello": "world"}, to https://httpbin.org/anything on every push to the repo:

workflow "Call external API" {
  on = "push"
  resolves = ["Call httpbin"]
}

action "Call httpbin" {
  uses = "swinton/httpie.action@master"
  args = ["POST", "httpbin.org/anything", "hello=world"]
}

More examples

Using output in a downstream action

In this more advanced, but somewhat contrived, example we'll open an issue in the current repository, and then comment and close that issue in subsequent actions.

Note, this is made possible since the response body is preserved in a file, $HOME/$GITHUB_ACTION.response.body (along with response headers, in $HOME/$GITHUB_ACTION.response.headers, and the entire response, in $HOME/$GITHUB_ACTION.response). The response can then be parsed in downstream actions using jq, a command-line JSON processor, which is pre-baked into the container.

action "Issue" {
  uses = "swinton/httpie.action@master"
  args = ["--auth-type=jwt", "--auth=$GITHUB_TOKEN", "POST", "api.github.com/repos/$GITHUB_REPOSITORY/issues", "title=Hello\\ world"]
  secrets = ["GITHUB_TOKEN"]
}

action "Comment on issue" {
  needs = ["Issue"]
  uses = "swinton/httpie.action@master"
  args = ["--auth-type=jwt", "--auth=$GITHUB_TOKEN", "POST", "`jq .comments_url /github/home/Issue.response.body --raw-output`", "body=Thanks\\ for\\ playing\\ :v:"]
  secrets = ["GITHUB_TOKEN"]
}

action "Close issue" {
  needs = ["Issue"]
  uses = "swinton/httpie.action@master"
  args = ["--auth-type=jwt", "--auth=$GITHUB_TOKEN", "PATCH", "`jq .url /github/home/Issue.response.body --raw-output`", "state=closed"]
  secrets = ["GITHUB_TOKEN"]
}

Trigger another workflow

In this example, we'll trigger a separate workflow, via the repository's dispatches endpoint.

Note, $PAT refers to a personal access token, created separately, and stored as a secret.

action "Trigger workflow" {
  uses = "swinton/httpie.action@master"
  args = ["--auth-type=jwt", "--auth=$PAT", "POST", "api.github.com/repos/$GITHUB_REPOSITORY/dispatches", "Accept:application/vnd.github.everest-preview+json", "event_type=demo"]
  secrets = ["PAT"]
}

Presets

Some HTTPie presets are applied by default by the included config.json, that make sense in the context of GitHub Actions, namely:

  1. --check-status: Causes a workflow to exit if the HTTP status is one of 3xx, 4xx, or 5xx
  2. --ignore-stdin: Disables HTTPie's default behaviour of automatically reading STDIN, typically not desirable during non-interactive invocations
  3. --default-scheme=https: Assumes https:// is the default prefix for URLs, so you can just say (for example) api.github.com/zen as opposed to https://api.github.com/zen
  4. --print=hb: Prints both response headers and response body in the output

Plugins

A few authentication plugins are included:

  1. httpie-api-auth: Provides support for the ApiAuth authentication scheme
  2. httpie-aws-auth: Provides support AWS authentication
  3. httpie-hmac-auth: Provides support for HMAC authentication
  4. httpie-jwt-auth: Provides support for JSON Web Tokens

More info

Usage docs for HTTPie are here.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap