From 11d230cc0f327be1bb0b9713a18908a501c202a8 Mon Sep 17 00:00:00 2001 From: Theo Chatzimichos Date: Nov 12 2017 22:00:09 +0000 Subject: bin/get_formulas.py: move the pull-request code and arg on top makes it more clear that this arg doesn't require destination, while everything else does --- diff --git a/bin/get_formulas.py b/bin/get_formulas.py index 0ef41ff..53e048f 100755 --- a/bin/get_formulas.py +++ b/bin/get_formulas.py @@ -8,6 +8,22 @@ import sys import yaml +def check_open_pull_requests(): + from github import Github + + g = Github() + for formula, data in FORMULAS.items(): + open_pull_requests = data.get('pending', []) + if open_pull_requests: + namespace = data.get('original_namespace', 'saltstack-formulas') + prefix = data.get('prefix', '') + org = g.get_organization(namespace) + for pull_request in open_pull_requests: + pr = int(pull_request.split('/')[-1]) + state = org.get_repo('%s%s-formula' % (prefix, formula)).get_pull(pr).state + print('%s is %s' % (pull_request, state)) + + def git(cmd, cwd=None, additional_env=None): # pygit2 is not available for python3 in Leap, use plain git instead @@ -64,54 +80,34 @@ def enable_remote(REMOTE, DEST): git(['checkout', '-qB', 'master', '%s/master' % REMOTE], cwd=FULL_PATH) -def check_open_pull_requests(): - from github import Github - - g = Github() - for formula, data in FORMULAS.items(): - open_pull_requests = data.get('pending', []) - if open_pull_requests: - namespace = data.get('original_namespace', 'saltstack-formulas') - prefix = data.get('prefix', '') - org = g.get_organization(namespace) - for pull_request in open_pull_requests: - pr = int(pull_request.split('/')[-1]) - state = org.get_repo('%s%s-formula' % (prefix, formula)).get_pull(pr).state - print('%s is %s' % (pull_request, state)) - - with open('FORMULAS.yaml', 'r') as f: FORMULAS = yaml.load(f) parser = argparse.ArgumentParser(description='Loads the formulas from FORMULAS.yaml and optionally clones them in a specified destination. Optionally it can also create a symlink from the cloned path to /srv/salt, useful for the CI worker. The internal gitlab fork will also be added as secondary remote.') +parser.add_argument('-p', '--pull-requests', action='store_true', help='Prints the status of the Pull Requests that are defined in FORMULAS.yaml under "pending".') parser.add_argument('-d', '--destination', nargs=1, help='Destination absolute path of the cloned (or to-be-cloned) repositories of the formulas.') parser.add_argument('-c', '--clone', action='store_true', help='Clone the formulas to the destination specified with "--destination". The gitlab fork will also be added as remote. If the repository is already cloned, then both remotes will be pulled/fetched.') parser.add_argument('-s', '--symlink', action='store_true', help='Creates symlink from the specified destination to /srv/salt.') parser.add_argument('-r', '--remote', nargs=1, help='Enable the specified remote. Available remotes: origin, opensuse. Default: origin') -parser.add_argument('-p', '--pull-requests', action='store_true', help='Prints the status of the Pull Requests that are defined in FORMULAS.yaml under "pending".') args = parser.parse_args() -if args.destination and not os.path.isabs(args.destination[0]): - parser.print_help() - sys.exit(1) +if args.pull_requests: + check_open_pull_requests() -if args.clone: - if not args.destination: +# Every option below requires the --destination argument to be set +if args.clone or args.symlink or args.remote: + if not args.destination or not os.path.isabs(args.destination[0]): parser.print_help() sys.exit(1) - clone_or_pull(args.destination[0]) -if args.symlink: - if not args.destination: - parser.print_help() - sys.exit(1) - create_symlinks(args.destination[0]) + if args.clone: + clone_or_pull(args.destination[0]) -if args.remote: - if args.remote[0] not in ['origin', 'opensuse'] or not args.destination: - parser.print_help() - sys.exit(1) - enable_remote(args.remote[0], args.destination[0]) + if args.symlink: + create_symlinks(args.destination[0]) -if args.pull_requests: - check_open_pull_requests() + if args.remote: + if args.remote[0] not in ['origin', 'opensuse']: + parser.print_help() + sys.exit(1) + enable_remote(args.remote[0], args.destination[0])