Bitbucket API 2 - 在团队项目中创建存储库

Bitbucket API 2 - create repository in a team project

我的 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"} }'

或使用关键参数:

$ 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 是在主项目中创建的。

我试着把项目名称放在 link:

$ 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"}}'