Last active
May 15, 2019 16:01
-
-
Save gravcat/3948c24460415f18a32d4c1d2f79a7ba to your computer and use it in GitHub Desktop.
works on stash/bitbucket server 5.3.1+(?)
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
import os | |
import json | |
import argparse | |
import stashy | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-u','--username', help='Stash username used in API authentication.') | |
parser.add_argument('-p', '--password', help='Stash password used in API authentication.') | |
args = parser.parse_args() | |
stash_username = args.username | |
stash_password = args.password | |
stash_server_url = 'https://bitbucket/' | |
stash_server_ssh_url = 'ssh://git@bitbucket:7999' | |
stash_project_key = 'iac' | |
user_home = os.path.expanduser('~') | |
# open connection to stash, disable ssl verification cuz #selfsigned #yolo | |
stash = stashy.connect(stash_server_url, stash_username, stash_password, verify=False) | |
# get repository list of a given project | |
stash_repos = stash.projects[stash_project_key].repos.list() | |
# clone chef_main | |
if not os.path.isdir(f"{user_home}/chef_main"): | |
os.system(f"git clone {stash_server_ssh_url}/{stash_project_key}/chef_main {user_home}/chef_main") | |
# construct git urls and clone, exclude chef_main. clone into chef_main/cookbooks per project recommendations | |
for repo in stash_repos: | |
if 'chef_main' not in repo['name']: | |
if not os.path.isdir(f"{user_home}/chef/cookbooks/{repo['name']}"): | |
print(f"Cloning repository for {repo['name']}") | |
os.system(f"git clone {stash_server_ssh_url}/{stash_project_key}/{repo['name']}.git {user_home}/chef/cookbooks/{repo['name']}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment