Skip to content

Instantly share code, notes, and snippets.

@mrprompt
Created September 26, 2019 18:25
Show Gist options
  • Save mrprompt/0f3bcae97c1d1b1e82dde5b0e5942f79 to your computer and use it in GitHub Desktop.
Save mrprompt/0f3bcae97c1d1b1e82dde5b0e5942f79 to your computer and use it in GitHub Desktop.
Clone all bitbucket repositories
import subprocess
import json
cmd = "curl -u <bitbucket_username>:<bitbucket_password> https://api.bitbucket.org/2.0/repositories/<team_name_or_project_name>"
cmd = cmd.split()
while 1:
from_api = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
from_api = from_api.communicate()
json_from_api = json.loads(from_api[0])
for unit_dict in json_from_api["values"]:
clone_cmd = "git clone " + unit_dict["links"]["clone"][1]["href"]
clone_cmd = clone_cmd.split()
clone_out = subprocess.call(clone_cmd, shell=False)
if "next" not in json_from_api:
break
else:
cmd[-1] = json_from_api["next"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment