代码之家  ›  专栏  ›  技术社区  ›  nanobar

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

  •  0
  • nanobar  · 技术社区  · 6 年前

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

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

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

    此响应包含repo的uuid,文档说:

    这可以用来代替 URL中的slug段。 这样做可以保证您的URL能够生存 重命名存储库 由其所有者,甚至转让 存储库到其他用户。

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

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

    UUID 可代替 repo_slug 哪一个是好的。但它也奇怪地想要 username (也可能是组织名称)。因此,能够灵活地移动存储库是毫无意义的。存储库列表是否返回此信息? .

    那么,如何使用存储库uuid来发现 用户名 或者更好的方法是得到一个只包含uuid的分支列表,这个uuid在gitlab/github上支持是明智的选择。谢谢。

    1 回复  |  直到 6 年前
        1
  •  1
  •   cody    6 年前

    看起来,一旦你有了报告,你就可以替换 %7B%7D 作为空用户名/团队名称。

    this documentation :

    一旦拥有了存储库的UUID,就不再需要用户名了 或者团队名称,以便在使用空字段的情况下调用API。

    这有助于您解析存储库,无论是用户名还是团队 名称更改。

    使用团队名称(1team)和存储库名称(moxie)调用:

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

    使用UUID和空字段调用:

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

    与Uuid和Gename联系:

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