2011-09-06 69 views
2

部署键github上我下面在这里发布的指导方针:http://develop.github.com/p/repo.html问题将通过API

我想公钥添加到我的一套部署按键,使用GitHub的API。

创建回购工作正常:

curl -F "login=username" -F "token=ApiToken" https://github.com/api/v2/json/repos/create -F name=myrepo 

{"repository":{"owner":"username","has_downloads":true,"forks":1,"url":"https://github.com/username/myrepo","watchers":1,"has_wiki":true,"fork":false,"size":0,"open_issues":0,"created_at":"2011/09/06 02:42:08 -0700","name":"myrepo","private":false,"has_issues":true}} 

我可以列出键(emtpy现在):(!保持为空,即使加入后)

curl -F "login=username" -F "token=ApiToken" https://github.com/api/v2/json/repos/keys/username/myrepo 

{"public_keys":[]} 

但我不能添加键:

curl -X POST -F "login=username" -F "token=ApiToken" https://github.com/api/v2/json/repos/key/username/myrepo/add -F "title=TheTitle" -F "key=ssh-rsa xxxxx..." 

{"public_keys":[]} 

对于GitHub API有什么限制吗?

+0

你有没有试着用简单的引号代替双引号? – VonC

+0

是的,我做过。我认为问题在于我试图添加的密钥已经分配给另一个用户,并且github不允许将一个密钥关联到多个帐户。用户界面中的错误消息或多或少清楚:“糟糕!密钥已被使用.',但通过API的回复是无声的。 – dangonfast

+0

你尝试添加一个伪造的密钥,只是为了看看API是否工作? – VonC

回答

3

我发现这个问题,所以在这里可以参考。 Github不允许将公钥与几个用户关联。 如果您尝试使用Web界面添加键,您将得到以下信息:

Oops! The key has already been taken. 

的API是沉默。这就是我困惑的原因。

采用了全新的按键,该API工作正常,并回复:

curl -X POST -F "login=username" -F "token=ApiToken" https://github.com/api/v2/json/repos/key/username/myrepo/add -F "title=Bogus" -F "key=ssh-rsa xxxxx...." 

{"public_keys":[{"title":"Bogus","id":1199679,"key":"ssh-rsa xxxx..."}]} 
+0

非常好。感谢您的反馈和+1 – VonC

+0

在v3中找不到任何内容 – ashim888