Jef*_*rts 2 github github-api github-services
我正在尝试使用找到的create hook api创建一个钩子
http://developer.github.com/v3/repos/hooks/#create-a-hook
但是当我试图发帖时,我得到301,所以我确信我做错了...
几个问题......
1)如果github是私有的,我怎么知道我可以为该repo创建一个钩子?我确信我需要通过POST进行身份验证,但是如何进行身份验证?
2)以下curl语句是如何创建钩子的有效示例吗?
curl -v -H "Content-Type: application/json" -X POST -d "{ "name": "cia",
"active": true, "events": [ "push" ], "config": {
"url": "http://requestb.in/######", "content_type": "json" } }"
http://github.com/repos/#####/#####/hooks
Run Code Online (Sandbox Code Playgroud)
为了安全起见,我用#####替换了某些元素......
3)如果上述内容不正确,请问我是否有一个有效示例的片段为名为"cia"的webhook创建一个钩子?
curl -usigmavirus24 -v -H "Content-Type: application/json" -X POST -d '{"name": "cia", "active": true, "events": ["push"], "config": {"url": "...", "content_type": "json"}}' https://api.github.com/repos/sigmavirus24/reponame/hooks
Run Code Online (Sandbox Code Playgroud)
是正确的curl命令.您发布的URL必须是https://api.github.com/:endpoint
哪里:endpoint
在这种情况下repos/username/reponame/hooks
.您还需要使用'
S周围的JSON机构curl命令,否则你会得到的字符串就像"{ "
串联起来像命令的输出name
,cia
,active
,events
,等.
此外,该-u :username
选项对于curl是必要的,因此它将告诉curl它必须进行身份验证并要求您输入密码.
如果你不介意你的密码在你的bash历史中(你应该),你也可以这样做-u username:password
.或者甚至更好,您可以在表单中对您的凭据进行base64编码username:password
,然后将其作为标题发送,如下所示:Authentication: Basic <base64-encoded-credentials
.