Skip to content

Commit

Permalink
Merge pull request #160 from stopthatcow/feature/157_more_completion
Browse files Browse the repository at this point in the history
More completion
  • Loading branch information
stopthatcow committed Apr 9, 2019
2 parents 62dc890 + 8951fb9 commit 2471074
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
16 changes: 16 additions & 0 deletions tests/test_repo_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,19 @@ def test_describe(mocker, git_repo):
result = runner.invoke(zazu.cli.cli, ['repo', 'describe', '--prerelease=4', '--pep440'])
assert result.exit_code == 0
assert PEP440_RE.match(result.output)


def test_complete_repo(mocker):
mocked_scm_host = mocker.Mock()
mocked_repo = mocker.Mock()
mocked_repo.id = 'repo_id'
mocked_scm_host.repos = mocker.Mock(return_value=[mocked_repo])
mocked_config = mocker.Mock()
mocked_config.scm_hosts = mocker.Mock(return_value={'default': mocked_scm_host})
mocker.patch('zazu.config.Config', return_value=mocked_config)
assert zazu.repo.commands.complete_repo(None, [], '') == ['default/repo_id']
assert zazu.repo.commands.complete_repo(None, [], 'repo') == ['default/repo_id']
assert zazu.repo.commands.complete_repo(None, [], 'foo') == []
# Test with unresponsive host.
mocked_scm_host.repos = mocker.Mock(side_effect=IOError)
assert zazu.repo.commands.complete_repo(None, [], '') == []
6 changes: 3 additions & 3 deletions zazu/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def match_host(host, id):
try:
scm_repo = next((r for r in host.repos() if match_host(host_name, r.id)), None)
except IOError:
click.secho('Warning: unable to connect to "{}" SCM host'.format(host_name), fg='red')
zazu.util.warn('unable to connect to "{}" SCM host'.format(host_name))
scm_repo = None
if scm_repo is not None:
return scm_repo
Expand All @@ -296,8 +296,8 @@ def project_config(self):
self._project_config = find_and_load_yaml_file([self.repo_root], PROJECT_FILE_NAMES)
required_zazu_version = self._project_config.get('zazu', '')
if required_zazu_version and required_zazu_version != zazu.__version__:
click.secho('Warning: this repo has requested zazu {}, which doesn\'t match the installed version ({}). '
'Use "zazu upgrade" to fix this'.format(required_zazu_version, zazu.__version__), fg='red')
zazu.util.warn('this repo has requested zazu {}, which doesn\'t match the installed version ({}). '
'Use "zazu upgrade" to fix this'.format(required_zazu_version, zazu.__version__))
return self._project_config

def user_config(self):
Expand Down
2 changes: 1 addition & 1 deletion zazu/dev/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def start(config, name, no_verify, head, rename_flag, type):
try:
develop_is_current = develop_is_current_future.result()
except (git.exc.GitCommandError, AttributeError):
click.secho('WARNING: unable to fetch from origin!', fg='red')
zazu.util.warn('unable to fetch from origin!')
develop_is_current = True
existing_branch = find_branch_with_id(repo, issue_descriptor.id)
if existing_branch and not (rename_flag and repo.active_branch.name == existing_branch):
Expand Down
16 changes: 15 additions & 1 deletion zazu/repo/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,22 @@ def init(config):
zazu.git_helper.install_git_hooks(config.repo_root)


def complete_repo(ctx, args, incomplete):
"""Completion function that completes repos from SCM hosts."""
paths = []
for host_name, host in zazu.config.Config().scm_hosts().iteritems():
try:
for r in host.repos():
path = '/'.join([host_name, r.id])
if incomplete in path:
paths.append(path)
except IOError:
zazu.util.warn('unable to connect to "{}" SCM host.'.format(host_name))
return paths


@repo.command()
@click.argument('repository')
@click.argument('repository', autocompletion=complete_repo)
@click.argument('destination', required=False)
@click.option('--nohooks', is_flag=True, help='does not install git hooks in the cloned repo')
@click.option('--nosubmodules', is_flag=True, help='does not update submodules')
Expand Down
2 changes: 1 addition & 1 deletion zazu/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def styler_list(file, sets, keys):
@zazu.config.pass_config
@click.option('-v', '--verbose', is_flag=True, help='print files that are dirty')
@click.option('--check', is_flag=True, help='only check the repo for style violations, do not correct them')
@click.option('--cached', is_flag=True, help='only examine/fix files that are staged for CI commit')
@click.option('--cached', is_flag=True, help='only examine/fix files that are staged for SCM commit')
def style(config, verbose, check, cached):
"""Style repo files or check that they are valid style."""
config.check_repo()
Expand Down
5 changes: 5 additions & 0 deletions zazu/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,8 @@ def raise_uninstalled(pkg_name):
"""
raise click.ClickException('{0} not found, install it via "apt-get install {0}" or "brew install {0}"'.format(pkg_name))


def warn(text):
"""Emits a red warning to stderr."""
click.secho('Warning: {}'.format(text), fg='red', err=True)

0 comments on commit 2471074

Please sign in to comment.