I am following the guidelines published here: http://develop.github.com/p/repo.html
I am trying to add a public key to my set of deploy keys, using the GitHub API.
Creating the repo works fine:
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}}
I can list the keys (emtpy for now):
curl -F "login=username" -F "token=ApiToken" https://github.com/api/v2/json/repos/keys/username/myrepo
{"public_keys":[]}
But I can not add keys (stays empty even after addition!):
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":[]}
Is there any limitation to the GitHub API, regarding key addition?
I found the problem, so for reference here it is. Github does not allow a public key to be associated to several users. If you try to add the key using the web interface, you will get the following message:
Oops! The key has already been taken.
The API is silent. That is why I was confused.
Using a brand new key, the API works as expected and replies with:
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..."}]}
精彩评论