我遇到了bitbucket API 2.0的繁琐限制 - 我希望有一种方法可以使它更有用。
当想要从bitbucket API 2.0中检索存储库列表时,可以使用以下URL:
https://api.bitbucket.org/2.0/repositories/{teamname}
这将返回列表中的前10个回购。要访问下一个10,只需添加一个页面参数:
https://api.bitbucket.org/2.0/repositories/{teamname}?page=2
这将返回下一个10.还可以使用pagelen参数调整返回的结果数,如下所示:
https://api.bitbucket.org/2.0/repositories/{teamname}?pagelen=100
最大数量可能因帐户而异,但100是任何团队能够通过每个API调用请求的最大数量。繁琐的部分是我无法找到一个方法来获取第2页的pagelen为100.我尝试了以下变化:
https://api.bitbucket.org/2.0/repositories/{teamname}?pagelen=100&page=2
https://api.bitbucket.org/2.0/repositories/{teamname}?page=2&pagelen=100
我也试过使用limit
或size
这样的参数无济于事。我寻求的行为是否可能? Some relevant documentation can be found here.
编辑:看起来这种行为是可能的,但是如果整个网址都在引号中,bitbucket 2.0 API将只识别多个参数。
例:
curl "https://api.bitbucket.org/2.0/repositories/{teamname}?pagelen=100&page=2"
原始答案:我能够通过创建一个循环遍历10个结果的每个页面的bash脚本来解决这个问题,将每个新的10个存储库添加到一个临时文件中,然后克隆到这10个存储库中。唯一需要做的手动是将for循环中的上限更新为预期的最后一页。
这是一个示例脚本:
for thisPage in {1..23}
do
curl https://api.bitbucket.org/2.0/repositories/[organization]?page=$thisPage -u [username]:[password] > repoinfo
for repo_name in `cat repoinfo | sed -r 's/("slug": )/\n\1/g' | sed -r 's/"slug": "(.*)"/\1/' | sed -e 's/{//' | cut -f1 -d\" | tr '\n' ' '`
do
echo "Cloning " $repo_name
git clone https://[username]@bitbucket.org/[organization]/$repo_name
echo "---"
done
done
从以下方面收集了很多帮助:https://haroldsoh.com/2011/10/07/clone-all-repos-from-a-bitbucket-source/和http://adomingues.github.io/2015/01/10/clone-all-repositories-from-a-user-bitbucket/谢谢!