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

标签 bitbucket-api

我的 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/

相关文章:

api - 使用 BitBucket API,列出哪些分支拥有 master 中的所有内容,哪些分支没有

java - 在 bitbucket api 方法中从 InputStream 读取内容

api - 使用 BitBucket 的 API 来 fork 存储库

rest - Bitbucket API 公共(public)问题创建

bitbucket - 使用 BitBucket REST API 过滤分支

git - 使用 LibGit2Sharp 的 Bitbucket 身份验证

bitbucket - 如何获取bitbucket的refresh_token?

javascript - 在 JavaScript 中生成格式正确的 SSH key

Bitbucket API - "push"事件的有效负载 - 如何最可靠地获取最新哈希值

BitBucket 1.0 REST API 检索存储库的所有拉取请求