如何从curl或github cli创建webhook

Chr*_* G. 4 curl github github-api 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"}'
Run Code Online (Sandbox Code Playgroud)

给我留下了疑问:

  • 什么是-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"
}
Run Code Online (Sandbox Code Playgroud)

Ber*_*tel 7

使用卷曲

您可以使用以下命令来创建 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
Run Code Online (Sandbox Code Playgroud)

这个文档来看,name属性应该具有值web

姓名 类型 描述
姓名 细绳 身体 使用 web 创建 webhook。默认:网络。该参数仅接受值 web。

此处列出了可能的 Webhook 事件

使用 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"
  }
}'
Run Code Online (Sandbox Code Playgroud)

检查gh api