Capriatto
Capriatto

Reputation: 965

How to Clone all repositories into Team from Bitbucket using GIT

i want to know if it's possible to clone all repositories in a team from bitbucket since git.

Thanks in advance.

Upvotes: 3

Views: 6787

Answers (4)

Gosha null
Gosha null

Reputation: 641

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"])

Upvotes: 0

A.N.
A.N.

Reputation: 288

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:

  1. Get JSON with all projects: http://my_bitbucket/rest/api/1.0/projects

    Or: http://my_bitbucket/rest/api/1.0/<user>/projects

  2. Get JSON with repositories for every project:

    http://my_bitbucket/rest/api/1.0/projects/<project_name>/repos?limit=10000
    
  3. 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

Upvotes: 2

user1034710
user1034710

Reputation: 1

  1. download jq
  2. fetch https://bitbucket.org/!api/1.0/users/[teamslug] w/ authed browser inspect cookies, and find the bb_session cookie
  3. exec the following replacing [teamslug] and [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

  1. sh all_team_repos

Upvotes: 0

mgarciaisaia
mgarciaisaia

Reputation: 15630

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

Upvotes: 8

Related Questions