Bitbucket服务器:REST API仅返回公共仓库,而不返回私有仓库

时间:2018-10-05 13:16:30

标签: rest bitbucket bitbucket-server bitbucket-api

我的一位客户正在其Intranet中运行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获得私有存储库。

问:有没有人让它正常工作?
问:是否有人在使用Bitbucket Server REST API?您的经验/印象如何?

1 个答案:

答案 0 :(得分: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用户身份运行,您需要隐藏的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

相关问题