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

2024-03-27

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

这将在项目中创建存储库 repo2mainproject.

我尝试使用 uuid 但同样的情况发生,repo 是在主项目中创建的。

我尝试将项目名称放入链接中:

$ 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"}}'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Bitbucket API 2 - 在团队项目中创建存储库 的相关文章

随机推荐