我想知道是否可以从Bitbucket的团队中克隆所有存储库。
预先感谢。
我已经编造了这个小红宝石脚本。对其进行测试,从system()
中删除echo
,以实际执行克隆。
#!/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
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
['links']['clone']['href']
参数的克隆回购。
完整示例:https://github.com/artiomn/git_cloner/blob/master/src/src/git_cloner/bitbucket.py
- 下载JQ
- 提取https://bitbucket.org/capi/1.0/users/[teamslug] w/perseed浏览器检查cookie,并找到bb_session cookie
- 执行以下更换[TeamSlug]和[BB_COOKIE]
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
- sh all_team_repos
对于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"])