我的 bitbucket 帐户上有一个团队,myteam
,其中包含一个名为 mainproject
的项目.每当我想在里面创建一个存储库时,我只需要执行这个命令行:
$ curl -X POST -v -u myaccount:passwd "https://api.bitbucket.org/2.0/repositories/myteam/repo1" -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks"}'
这有效。但是,当我创建名为
secondproject
的第二个项目时,问题出现了。 .我应该如何告诉 API 存储库应该属于哪个项目?我尝试在数据(-d)中指定项目信息:
$ curl -X POST -v -u myaccount:passwd "https://api.bitbucket.org/2.0/repositories/myteam/repo2" -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks", "project": {"name": "secondproject"} }'
或使用 key 参数:
$ curl -X POST -v -u myaccount:passwd "https://api.bitbucket.org/2.0/repositories/myteam/repo2" -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks", "project": {"key": "SEC"} }'
这将在项目
mainproject
中创建存储库 repo2 .我尝试使用 uuid 但发生同样的情况,repo 是在 mainproject 中创建的。
我尝试将项目名称放在链接中:
$ curl -X POST -v -u myaccount:passwd "https://api.bitbucket.org/2.0/repositories/myteam/secondproject/repo1" -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks"
...
{"error": {"message": "Resource not found", "detail": "There is no API hosted at this URL.\n\nFor information about our API's, please refer to the documentation at: https://confluence.atlassian.com/x/IYBGDQ"}}
如何指定我要创建的存储库属于哪个项目?
我不是在寻找 GUI 解决方案,我想坚持使用命令行,因为我需要以这种方式自动化存储库的创建。
最佳答案
内容类型必须指定为 curl
使用此参数:-H "Content-Type: application/json"
.然后是json
数据可以正常访问。所以最终的命令看起来像这样:
$ curl -X POST -v -u myaccount:passwd "https://api.bitbucket.org/2.0/repositories/myteam/repo2" -H "Content-Type: application/json" -d '{"has_wiki": true, "is_private": true, "project": {"key": "PRJ_KEY"}}'
关于bitbucket-api - Bitbucket API 2 - 在团队项目中创建存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38347458/