Last active
October 13, 2018 19:59
-
-
Save pydevops/19c835ab31ab87a6f927ed76707aed9a to your computer and use it in GitHub Desktop.
bitbucket clone repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import json | |
import sys | |
import requests | |
import getpass | |
''' | |
Given the bitbucket.org user id, | |
As bitbucket returns paged collection for REST API, | |
we need to figure out the repositories names (till the last page) | |
''' | |
def get_repo_names(url, user_id, password): | |
repo_names = [] | |
response = requests.get(url, auth=(user_id, password)) | |
data = response.json() | |
repos = data['values'] | |
for repo in repos: | |
repo_names.append(repo['name']) | |
# if there is a next page, get the next page till it is no more next page | |
if 'next' in data: | |
next_page = data['next'] | |
repo_names.extend(get_repo_names(next_page, user_id, password)) | |
return repo_names | |
def main(): | |
bb_user_id=sys.argv[1] | |
bb_password=getpass.getpass('bitbucket.org password for {0}:'.format(bb_user_id)) | |
url='https://bitbucket.org/api/2.0/repositories/{0}'.format(bb_user_id) | |
repo_names=sorted(get_repo_names(url,bb_user_id,bb_password)) | |
for name in repo_names: | |
print(name) | |
if __name__ == '__main__': | |
main() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#Script to get all repositories under a user from bitbucket | |
#Usage: getAllRepos.sh [username] | |
./bitbucket.py $1 | \ | |
while read repo_name | |
do | |
#echo $repo_name | |
git clone ssh://[email protected]/$1/$repo_name $SRC_ROOT/$repo_name | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment