如何获取bitbucket存储库列表?

时间:2018-02-15 06:49:33

标签: java repository bitbucket

有人可以告诉我如何获取bitbucket存储库列表,我正在访问此URL

https://api.bitbucket.org/2.0/repositories/{username}

但是当我点击这个URL时,我得到了这种JSON

{
    "pagelen": 10,
    "values": [],
    "page": 1,
    "size": 0
}

我相信这不是我想要的。是否需要设置任何标头参数或因为我没有设置任何标头参数,仅使用带有 GET 方法的上述网址。请帮帮我。 在此先感谢:)

3 个答案:

答案 0 :(得分:0)

我现在已经取得了一些成就,你可以获得存储库列表,但你也需要access_token。您可以参考documentation

希望这对你们有用。

答案 1 :(得分:0)

您还可以使用curl来获取存储库

  

curl --user用户名:password --insecur GET   http://localhost:7990/rest/api/1.0/projects/WORK/repos | q   --raw-output'.values []。slug'

答案 2 :(得分:0)

仅curl每次API调用只能获取10个结果,如果您有很多存储库,这将很繁琐。

这是一个小脚本,可按需向下钻取尽可能多的页面,并另外提取组织,描述以及存储库是否为私有。 ?role=member参数列出了您有权访问的所有存储库。

#!/bin/bash

read -p 'Bitbucket Username (not email): ' BB_USERNAME
read -sp 'Bitbucket Password: ' BB_PASSWORD

next_url="https://api.bitbucket.org/2.0/repositories?role=member"
while [ ! -z "$next_url" ]; do
    response_json=$( curl -s --user $BB_USERNAME:$BB_PASSWORD "$next_url" )
    echo "$response_json" | jq -r '.values | map([.slug, .workspace.slug, .description, .is_private] | @csv) | join("\n")'
    next_url=$( echo "$response_json" | jq -r '.next' )
done

或者,如果您不想创建Shell脚本,则可以将其复制并粘贴到命令行中(用您自己的Bitbucket登录详细信息替换YOUR_USERNAME和YOUR_PASSWORD):

(
next_url="https://api.bitbucket.org/2.0/repositories?role=member"
while [ ! -z "$next_url" ]; do
    response_json=$( curl -s --user YOUR_USERNAME:YOUR_PASSWORD "$next_url" )
    echo "$response_json" | jq -r '.values | map([.slug, .workspace.slug, .description, .is_private] | @csv) | join("\n")'
    next_url=$( echo "$response_json" | jq -r '.next' )
done
)

感谢https://stackoverflow.com/a/56812839/81269将我指向这个方向。

相关问题