我想知道从git开始是否可以从bitbucket克隆团队中的所有存储库。
提前致谢。
答案 0 :(得分:8)
我已经组成this tiny Ruby script。测试它并从echo
调用中移除system()
,以便实际进行克隆。
#!/usr/bin/env ruby
# USAGE: ./clone ORG_NAME
# ( ./clone instedd )
require 'open-uri'
require 'json'
team = ARGV[0] || raise("Must specify organization name")
puts "Fetching https://bitbucket.org/!api/1.0/users/#{team}..."
data = JSON.parse(open("https://bitbucket.org/!api/1.0/users/#{team}").read)
data["repositories"].each do | repo |
# delete "echo" for _actually_ cloning them
system("echo #{repo["scm"]} clone https://bitbucket.org/#{team}/#{repo["slug"]}")
end
答案 1 :(得分:2)
git_cloner是一个免费的开源工具,我开发用于克隆一堆BitBucket或GitHub存储库。
示例:
git_cloner --type bitbucket --login user --password password https://my_bitbucket
使用REST API:
获取所有项目的JSON:
http://my_bitbucket/rest/api/1.0/projects
或者:
http://my_bitbucket/rest/api/1.0/<user>/projects
为每个项目获取带有存储库的JSON:
http://my_bitbucket/rest/api/1.0/projects/<project_name>/repos?limit=10000
通过JSON中的['links']['clone']['href']
参数克隆回购。
完整示例:https://github.com/artiomn/git_cloner/blob/master/src/git_cloner/bitbucket.py
答案 2 :(得分:0)
A=[teamslug]; BBCOKIE=[bb_cookie]; for repo in $(curl -s -o 'https://bitbucket.org/!api/1.0/users/$A' | jq --raw-output '.repositories[].slug'); do echo git clone https://bitbucket.org/$A/$repo >> all_team_repos; done
答案 3 :(得分:0)
对于我使用跟随脚本的hg,您可以将其用于git
import getpass
import requests
import urllib.parse
import json
import os
username = input('Username: ')
password = getpass.getpass("Password: ")
params = {
"pagelen": 100
}
url = "https://api.bitbucket.org/2.0/repositories/%s" % username
url = url + "?" + urllib.parse.urlencode(params)
repos_data = requests.get(url, auth=(username, password))
repos_data = json.loads(repos_data.content)
for repo in repos_data["values"]:
os.system("hg clone %s" % repo["links"]["clone"][1]["href"])