i want to know if it's possible to clone all repositories in a team from bitbucket since git.
Thanks in advance.
i want to know if it's possible to clone all repositories in a team from bitbucket since git.
Thanks in advance.
I've made up this tiny Ruby script. Test it and remove the echo
from within the system()
call for it to actually do the cloning.
#!/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 is a free and open-source tool that I have developed to clone a bunch of BitBucket or GitHub repositories.
Example:
git_cloner --type bitbucket --login user --password password https://my_bitbucket
Use REST API:
Get JSON with all projects:
http://my_bitbucket/rest/api/1.0/projects
Or:
http://my_bitbucket/rest/api/1.0/<user>/projects
Get JSON with repositories for every project:
http://my_bitbucket/rest/api/1.0/projects/<project_name>/repos?limit=10000
Clone repos by ['links']['clone']['href']
parameter from the JSON.
Full example: https://github.com/artiomn/git_cloner/blob/master/src/git_cloner/bitbucket.py
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
For hg i used follow script, you can use it for 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"])