BitBucket API:如何从存储库 UUID 获取分支列表

BitBucket API: How to get a list of branches from a repository UUID

BitBucket API 到目前为止是一个有趣的体验,比方说。

我们有时会在各种 URL 中生成非常简短的文档,其中包含 bitbucket.org/rest/api/1.0api.bitbucket.org/2.0 等之间的一些功能以及获取存储库列表的方法:

GET https://api.bitbucket.org/2.0/repositories?role=x

此响应包含文档所说的回购的 UUID:

This can be used as a substitute for the slug segment in URLs. Doing this guarantees your URLs will survive renaming of the repository by its owner, or even transfer of the repository to a different user.

对我来说听起来像是常识!那么 getting a list of branches 呢?

GET https://api.bitbucket.org/2.0/repositories/{username}/{repo_slug}/refs/branches

UUID可以用来代替repo_slug,这很好。但它也很奇怪地想要 username (这也可能是组织名称,这很容易混淆)。因此,关于对移动存储库具有弹性的观点是毫无意义的。存储库列表 return 是这个吗? 没有.

那么如何使用存储库 UUID 找到 username,或者更好的是获得仅包含 UUID 的分支列表,这将是明智的支持,例如 GitLab/GitHub ?谢谢。

看起来一旦你有了 repo UUID,你就可以将 %7B%7D 替换为一个空的 user/team 名称。

来自this documentation

Once you have the UUID for a repository you no longer need a username or team name to make the API call so long as you use an empty field.

This helps you resolve repositories no matter if the username or team name changes.

Call with team name (1team) and repository name (moxie):

curl https://api.bitbucket.org/2.0/repositories/1team/moxie

Call with UUID and empty field:

curl https://api.bitbucket.org/2.0/repositories/%7B%7D/%7B21fa9bf8-b5b2-4891-97ed-d590bad0f871%7D

Call with UUID and teamname:

curl https://api.bitbucket.org/2.0/repositories/1team/%7B21fa9bf8-b5b2-4891-97ed-d590bad0f871%7D