如何从 curl 或 github cli 创建 webhook

How to create a webhook from curl or github cli

如何从 curl 或 github cli 创建 webhook?

这个文档。没有太大帮助: https://docs.github.com/en/rest/reference/repos#create-a-repository-webhook--code-samples

试过这个:

curl -u <user>:<token>\
    -X POST \
    -H "Accept: application/vnd.github.v3+json" \
    https://api.github.com/repos/<org>/<repo>/hooks \
    -d '{"name":"name"}'

给我留下问题:

错误:

{
    "message": "Validation Failed",
    "errors": [
    {
        "resource": "Hook",
        "code": "custom",
        "message": "Config must contain URL for webhooks"
    }
    ],
    "documentation_url": "https://docs.github.com/rest/reference/repos#create-a-repository-webhook"
}

使用卷曲

您可以使用以下方法创建 webhook:

curl "https://api.github.com/repos/<org>/<repo>/hooks" \
     -H "Authorization: Token YOUR_TOKEN" \
     -d @- << EOF
{
  "name": "web",
  "active": true,
  "events": [
    "push"
  ],
  "config": {
    "url": "http://some_webhook.ngrok.io/webhook",
    "content_type": "json"
  }
}
EOF

this doc 开始,name 属性 的值应该是 web

Name Type In Description
name string body Use web to create a webhook. Default: web. This parameter only accepts the value web.

列出了可能的 webhook 事件 here

使用 Github CLI

gh api /repos/<org>/<repo>/hooks \
   --input - <<< '{
  "name": "web",
  "active": true,
  "events": [
    "watch"
  ],
  "config": {
    "url": "https://some_webhook.ngrok.io/webhook",
    "content_type": "json"
  }
}'

结帐gh api