首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Bitbucket Server: REST只返回公共的,而不是私有的repos

Bitbucket Server: REST只返回公共的,而不是私有的repos
EN

Stack Overflow用户
提问于 2018-10-05 13:16:29
回答 2查看 2.1K关注 0票数 2

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

代码语言:javascript
复制
# 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应用程序中的公共和私有repos,但似乎没有任何方法可以使用REST获取私有存储库。

我也试过

代码语言:javascript
复制
# 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中的一个bug,通过REST获得私有存储库是不可能的。

Q:,有没有人能让它工作?

Q:是否有人使用Bit斗ServerRESTAPI?你的经历/印象如何?

EN

回答 2

Stack Overflow用户

发布于 2018-10-23 17:57:53

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

我使用了这个脚本来获得所有的回复:

代码语言:javascript
复制
#!/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']

这个脚本是以管理员用户的身份运行的,您需要stashy:

代码语言:javascript
复制
pip install stashy

我发现REST非常好,想知道如何提出正确的请求可能有点棘手,但是文档已经存在了。不过很难找到。每个版本都会发布新的文档,而且它们往往是最好的:

medium=301

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

票数 0
EN

Stack Overflow用户

发布于 2022-08-10 00:18:19

也有同样的问题。基本资产不退还私人项目。我不得不使用OAuth,现在它获取私有存储库。我遵循了这些指令。

https://stackoverflow.com/a/72103398/51759

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52666503

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档