首页 文章

Bitbucket Server:REST API仅返回公共存储库,而不是私有存储库

提问于
浏览
1

我的一个客户是在他们的内联网上运行Atlassian Bitbucket Server v5.14.0(不是Bitbucket Cloud!)的实例 . 我尝试使用REST API获取项目列表,对于我正在处理的项目列表,获取git存储库列表:

# first REST API call: returns list of projects on server,
# `?limit=1000` appended to work around / disable pagination:
# https://docs.atlassian.com/bitbucket-server/ ...
#  ... rest/5.14.0/bitbucket-rest.html#idm46783597898304
curl --header "Authorization: Bearer <my access token>" \
     https://<bitbucket hostname>/rest/api/1.0/projects?limit=1000

# second REST API call: returns list of repos in <project ID>
# https://docs.atlassian.com/bitbucket-server/ ...
#  ... rest/5.14.0/bitbucket-rest.html#idm45701776945568
curl --header "Authorization: Bearer <my access token>" \
     https://<bitbucket hostname>/rest/api/1.0/projects/<project key>/repos?limit=1000

总的来说,这很有效 . 然而问题是第二次调用仅返回具有公共可见性的存储库,虽然我在登录后能够在Web应用程序中看到公共和私有存储库,但似乎没有任何方法可以使用REST API获取私有存储库 .

我也试过了

# alternate approach: list repo by name
# https://docs.atlassian.com/bitbucket-server/ ...
#  ... rest/5.14.0/bitbucket-rest.html#idm46783597782384
curl --header "Authorization: Bearer <my access token>" \
     https://<bitbucket hostname>/rest/api/1.0/repos?name=<name of private repo>

但这也不会返回存储库信息 .

我已经彻底搜索了文档,但到目前为止,这似乎只是Bitbucket中的一个错误,并且通过REST API获取私有存储库根本不可能 .

Q: 有人如何让这个工作?
Q: 是否有人使用Bitbucket Server REST API?你的经历/印象是什么?

1 回答

  • 0

    它可能与您的用户拥有的权限有关 . 是管理员用户吗?

    我用这个脚本来获取所有的回购:

    #!/usr/bin/python
    
    import stashy
    import os
    import sys
    import urllib2
    import json
    import base64
    
    bitbucketBaseUrl = "https://bitbucket.company.com"
    bitbucketUserName = "admin"
    
    def validateScriptParameters():
        if len(sys.argv) != 2:
            sys.exit("Usage: {} [Bit Bucket admin password]".format(
                os.path.basename(sys.argv[0])))
    
    
    
    
    validateScriptParameters
    
    bitbucketPassword = sys.argv[1].strip()
    bitbucket = stashy.connect(bitbucketBaseUrl, bitbucketUserName, bitbucketPassword)
    projectList = bitbucket.projects.list()
    total = 0
    for project in projectList:
            projectName = project['key']
            repoList = bitbucket.projects[projectName].repos.list()
            for repo in repoList:
                print repo['name']
    

    此脚本以admin用户身份运行,您需要stashy lib:

    pip install stashy
    

    我发现REST API非常好,要弄清楚正确的请求如何,但文档就在那里可能有点棘手 . 虽然很难找到 . 他们在每个版本中发布新文档,它们往往是最好的:

    https://docs.atlassian.com/bitbucket-server/rest/5.15.0/bitbucket-rest.html?utm_source=%2Fstatic%2Frest%2Fbitbucket-server%2Flatest%2Fbitbucket-rest.html&utm_medium=301

    还有一个用于bitbucket的REST API插件,它允许您直接针对服务器测试请求:

    REST API Browser

相关问题