def test_make_repo_starting_at_version(in_git_dir, fake_versions):
    # Write a version file (as if we've already run this before)
    in_git_dir.join('.version').write('0.23.1')
    # make sure this is gone afterwards
    in_git_dir.join('hooks.yaml').ensure()

    make_repo(
        '.',
        language='ruby',
        name='scss-lint',
        description='',
        entry='scss-lint',
        id='scss-lint',
        match_key='files',
        match_val=r'\.scss$',
        args='[]',
        require_serial='false',
        minimum_pre_commit_version='0',
    )

    assert not in_git_dir.join('hooks.yaml').exists()

    # Assert that we only got tags / commits for the stuff we added
    assert _cmd('git', 'tag', '-l').split() == ['v0.24.0', 'v0.24.1']
    log_lines = _cmd('git', 'log', '--oneline').splitlines()
    log_lines_split = [log_line.split() for log_line in log_lines]
    assert log_lines_split == [
        [mock.ANY, 'Mirror:', '0.24.1'],
        [mock.ANY, 'Mirror:', '0.24.0'],
    ]
def test_make_repo_starting_empty(in_git_dir, fake_versions):
    make_repo(
        '.',
        language='ruby', name='scss-lint', entry='scss-lint',
        match_key='files', match_val=r'\.scss$', args='[]',
        require_serial='false',
    )

    # Assert that our things got copied over
    assert in_git_dir.join('.pre-commit-hooks.yaml').exists()
    assert in_git_dir.join('pre_commit_fake_gem.gemspec').exists()
    # Assert that we set the version file correctly
    assert in_git_dir.join('.version').read().strip() == '0.24.1'

    # Assert some things about the gits
    assert _cmd('git', 'status', '--short') == ''
    expected = ['v0.23.1', 'v0.24.0', 'v0.24.1']
    assert _cmd('git', 'tag', '-l').split() == expected
    log_lines = _cmd('git', 'log', '--oneline').splitlines()
    log_lines_split = [log_line.split() for log_line in log_lines]
    assert log_lines_split == [
        [mock.ANY, 'Mirror:', '0.24.1'],
        [mock.ANY, 'Mirror:', '0.24.0'],
        [mock.ANY, 'Mirror:', '0.23.1'],
    ]
def test_make_repo_starting_empty(in_git_dir, fake_versions):
    make_repo(
        '.',
        language='ruby',
        name='scss-lint',
        description='',
        entry='scss-lint',
        id='scss-lint',
        match_key='files',
        match_val=r'\.scss$',
        args='[]',
        require_serial='false',
        minimum_pre_commit_version='0',
    )

    # Assert that our things got copied over
    assert in_git_dir.join('.pre-commit-hooks.yaml').exists()
    assert in_git_dir.join('pre_commit_fake_gem.gemspec').exists()
    # Assert that we set the version file correctly
    assert in_git_dir.join('.version').read().strip() == '0.24.1'

    # Assert some things about the gits
    assert _cmd('git', 'status', '--short') == ''
    expected = ['v0.23.1', 'v0.24.0', 'v0.24.1']
    assert _cmd('git', 'tag', '-l').split() == expected
    log_lines = _cmd('git', 'log', '--oneline').splitlines()
    log_lines_split = [log_line.split() for log_line in log_lines]
    assert log_lines_split == [
        [mock.ANY, 'Mirror:', '0.24.1'],
        [mock.ANY, 'Mirror:', '0.24.0'],
        [mock.ANY, 'Mirror:', '0.23.1'],
    ]
def test_make_repo_starting_empty():
    make_repo(
        '.', 'ruby', 'scss-lint', r'\.scss$', 'scss-lint',
        version_list_fn_map={'ruby': returns_some_versions},
    )

    # Assert that our things got copied over
    assert os.path.exists('hooks.yaml')
    assert os.path.exists('__fake_gem.gemspec')
    # Assert that we set the version fiel correctly
    assert os.path.exists('.version')
    assert io.open('.version').read() == '0.24.1'

    # Assert some things about hte gits
    assert get_output('git', 'status', '-s').strip() == ''
    assert get_output('git', 'tag', '-l').strip().split() == [
        'v0.23.1', 'v0.24.0', 'v0.24.1',
    ]
    log_lines = get_output('git', 'log', '--oneline').strip().splitlines()
    log_lines_split = [log_line.split() for log_line in log_lines]
    assert log_lines_split == [
        [mock.ANY, 'Mirror:', '0.24.1'],
        [mock.ANY, 'Mirror:', '0.24.0'],
        [mock.ANY, 'Mirror:', '0.23.1'],
    ]
def test_python_integration(in_git_dir):
    make_repo(
        '.',
        language='python',
        name='flake8',
        description='',
        entry='flake8',
        id='flake8',
        match_key='files',
        match_val=r'\.py$',
        args='[]',
        require_serial='false',
        minimum_pre_commit_version='0',
    )
    # Our files should exist
    assert in_git_dir.join('.version').exists()
    assert in_git_dir.join('.pre-commit-hooks.yaml').exists()
    assert in_git_dir.join('setup.py').exists()

    # Should have made _some_ tags
    assert _cmd('git', 'tag', '-l')
    # Should have made _some_ commits
    assert _cmd('git', 'log', '--oneline')

    # To make sure the name is valid
    subprocess.check_call((sys.executable, 'setup.py', 'egg_info'))
def test_python_integration():
    make_repo('.', 'python', 'flake8', r'\.py$', 'flake8')
    # Our files should exist
    assert os.path.exists('.version')
    assert os.path.exists('hooks.yaml')
    assert os.path.exists('setup.py')

    # Should have _some_ tags
    assert get_output('git', 'tag', '-l').strip()
    # Should have _some_ commits
    assert get_output('git', 'log', '--oneline').strip()
def test_node_integration():
    make_repo('.', 'node', 'jshint', r'\.js$', 'jshint')
    # Our files should exist
    assert os.path.exists('.version')
    assert os.path.exists('hooks.yaml')
    assert os.path.exists('package.json')

    # Should have made _some_ tags
    assert get_output('git', 'tag', '-l').strip()
    # Should have made _some_ commits
    assert get_output('git', 'log', '--oneline').strip()
def test_ruby_integration():
    make_repo('.', 'ruby', 'scss-lint', r'\.scss$', 'scss-lint')
    # Our files should exist
    assert os.path.exists('.version')
    assert os.path.exists('hooks.yaml')
    assert os.path.exists('__fake_gem.gemspec')

    # Should have made _some_ tags
    assert get_output('git', 'tag', '-l').strip()
    # Should have made _some_ commits
    assert get_output('git', 'log', '--oneline').strip()
def main(argv: Optional[Sequence[str]] = None) -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument(
        'repo_path',
        help='Local path where the git repo is checked out.',
    )
    parser.add_argument(
        '--language',
        required=True,
        choices=LIST_VERSIONS,
        help='Which language to use.',
    )
    parser.add_argument(
        '--package-name',
        required=True,
        help='Package name as it appears on the remote package manager.',
    )

    mutex = parser.add_mutually_exclusive_group(required=True)
    mutex.add_argument(
        '--files-regex',
        help='Files regex to use in hooks.yaml',
    )
    mutex.add_argument('--types', help='`identify` type to match')

    parser.add_argument(
        '--entry',
        help='Entry point, defaults to the package name.',
    )
    parser.add_argument(
        '--args',
        help=('Comma separated arguments for the hook.  Escape commas in args '
              'with a backslash (\\).  '
              r"For example: --args='-i,--ignore=E265\,E501' would give "
              'you [-i, --ignore=E265,E501]'),
    )
    parser.add_argument(
        '--require-serial',
        action='store_true',
        help='Set `require_serial: true` for the hook',
    )
    args = parser.parse_args(argv)

    make_repo(
        args.repo_path,
        name=args.package_name,
        language=args.language,
        entry=args.entry or args.package_name,
        match_key='types' if args.types else 'files',
        match_val=f'[{args.types}]' if args.types else args.files_regex,
        args=json.dumps(split_by_commas(args.args)),
        require_serial=json.dumps(args.require_serial),
    )
    return 0
def main(argv: Optional[Sequence[str]] = None) -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument(
        'repo_path',
        help='Local path where the git repo is checked out.',
    )
    parser.add_argument(
        '--language', required=True, choices=LIST_VERSIONS,
        help='Which language to use.',
    )
    parser.add_argument(
        '--package-name', required=True,
        help='Package name as it appears on the remote package manager.',
    )

    mutex = parser.add_mutually_exclusive_group(required=True)
    mutex.add_argument(
        '--files-regex', help='Files regex to use in hooks.yaml',
    )
    mutex.add_argument('--types', help='`identify` type to match')

    parser.add_argument(
        '--entry', help='Entry point, defaults to the package name.',
    )
    parser.add_argument(
        '--args',
        help=(
            'Comma separated arguments for the hook.  Escape commas in args '
            'with a backslash (\\).  '
            r"For example: --args='-i,--ignore=E265\,E501' would give "
            'you [-i, --ignore=E265,E501]'
        ),
    )
    parser.add_argument(
        '--require-serial', action='store_true',
        help='Set `require_serial: true` for the hook',
    )
    args = parser.parse_args(argv)

    make_repo(
        args.repo_path,
        name=args.package_name,
        language=args.language,
        entry=args.entry or args.package_name,
        match_key='types' if args.types else 'files',
        match_val=f'[{args.types}]' if args.types else args.files_regex,
        args=json.dumps(split_by_commas(args.args)),
        require_serial=json.dumps(args.require_serial),
    )
    return 0
def test_node_integration(in_git_dir):
    make_repo(
        '.',
        language='node', name='jshint', entry='jshint',
        match_key='files', match_val=r'\.js$', args='[]',
    )
    # Our files should exist
    assert in_git_dir.join('.version').exists()
    assert in_git_dir.join('.pre-commit-hooks.yaml').exists()
    assert in_git_dir.join('package.json').exists()

    # Should have made _some_ tags
    assert _cmd('git', 'tag', '-l')
    # Should have made _some_ commits
    assert _cmd('git', 'log', '--oneline')
def test_ruby_integration(in_git_dir):
    make_repo(
        '.',
        language='ruby', name='scss-lint', entry='scss-lint',
        match_key='files', match_val=r'\.scss$', args='[]',
    )
    # Our files should exist
    assert in_git_dir.join('.version').exists()
    assert in_git_dir.join('.pre-commit-hooks.yaml').exists()
    assert in_git_dir.join('__fake_gem.gemspec').exists()

    # Should have made _some_ tags
    assert _cmd('git', 'tag', '-l')
    # Should have made _some_ commits
    assert _cmd('git', 'log', '--oneline')
def test_node_integration(in_git_dir):
    make_repo(
        '.',
        language='node', name='jshint', entry='jshint',
        match_key='files', match_val=r'\.js$', args='[]',
        require_serial='false',
    )
    # Our files should exist
    assert in_git_dir.join('.version').exists()
    assert in_git_dir.join('.pre-commit-hooks.yaml').exists()
    assert in_git_dir.join('package.json').exists()

    # Should have made _some_ tags
    assert _cmd('git', 'tag', '-l')
    # Should have made _some_ commits
    assert _cmd('git', 'log', '--oneline')
Exemple #14
0
def test_rust_integration(in_git_dir):
    make_repo(
        '.',
        language='rust', name='shellharden', entry='shellharden',
        match_key='types', match_val='shell', args='["--replace"]',
        require_serial='false',
    )
    # Our files should exist
    assert in_git_dir.join('.version').exists()
    assert in_git_dir.join('.pre-commit-hooks.yaml').exists()
    assert in_git_dir.join('Cargo.toml').exists()
    assert in_git_dir.join('main.rs').exists()

    # Should have made _some_ tags
    assert _cmd('git', 'tag', '-l')
    # Should have made _some_ commits
    assert _cmd('git', 'log', '--oneline')
def test_python_integration(in_git_dir):
    make_repo(
        '.',
        language='python', name='flake8', entry='flake8',
        match_key='files', match_val=r'\.py$', args='[]',
        require_serial='false',
    )
    # Our files should exist
    assert in_git_dir.join('.version').exists()
    assert in_git_dir.join('.pre-commit-hooks.yaml').exists()
    assert in_git_dir.join('setup.py').exists()

    # Should have made _some_ tags
    assert _cmd('git', 'tag', '-l')
    # Should have made _some_ commits
    assert _cmd('git', 'log', '--oneline')

    # To make sure the name is valid
    subprocess.check_call((sys.executable, 'setup.py', 'egg_info'))
def test_make_repo_starting_at_version():
    # Write a version file (as if we've already run this before)
    with io.open('.version', 'w') as version_file:
        version_file.write('0.23.1')

    make_repo(
        '.', 'ruby', 'scss-lint', r'\.scss$', 'scss-lint',
        version_list_fn_map={'ruby': returns_some_versions},
    )

    # Assert that we only got tags / commits for the stuff we added
    assert get_output('git', 'tag', '-l').strip().split() == [
        'v0.24.0', 'v0.24.1',
    ]
    log_lines = get_output('git', 'log', '--oneline').strip().splitlines()
    log_lines_split = [log_line.split() for log_line in log_lines]
    assert log_lines_split == [
        [mock.ANY, 'Mirror:', '0.24.1'],
        [mock.ANY, 'Mirror:', '0.24.0'],
    ]
def test_make_repo_starting_at_version(in_git_dir, fake_versions):
    # Write a version file (as if we've already run this before)
    in_git_dir.join('.version').write('0.23.1')
    # make sure this is gone afterwards
    in_git_dir.join('hooks.yaml').ensure()

    make_repo(
        '.',
        language='ruby', name='scss-lint', entry='scss-lint',
        match_key='files', match_val=r'\.scss$', args='[]',
        require_serial='false',
    )

    assert not in_git_dir.join('hooks.yaml').exists()

    # Assert that we only got tags / commits for the stuff we added
    assert _cmd('git', 'tag', '-l').split() == ['v0.24.0', 'v0.24.1']
    log_lines = _cmd('git', 'log', '--oneline').splitlines()
    log_lines_split = [log_line.split() for log_line in log_lines]
    assert log_lines_split == [
        [mock.ANY, 'Mirror:', '0.24.1'],
        [mock.ANY, 'Mirror:', '0.24.0'],
    ]
Exemple #18
0
def main(argv: Sequence[str] | None = None) -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument(
        'repo_path',
        help='Local path where the git repo is checked out.',
    )
    parser.add_argument(
        '--language',
        required=True,
        choices=LIST_VERSIONS,
        help='Which language to use.',
    )
    parser.add_argument(
        '--package-name',
        required=True,
        help='Package name as it appears on the remote package manager.',
    )
    parser.add_argument(
        '--description',
        help='Hook description.',
        default='',
    )

    mutex = parser.add_mutually_exclusive_group(required=True)
    mutex.add_argument(
        '--files-regex',
        help='Files regex to use in hooks.yaml',
    )
    mutex.add_argument('--types', help='`identify` type to AND match')
    mutex.add_argument(
        '--types-or',
        action='append',
        help='`identify` type to OR match',
    )

    parser.add_argument(
        '--id',
        help='Hook id, defaults to the entry point.',
    )
    parser.add_argument(
        '--entry',
        help='Entry point, defaults to the package name.',
    )
    parser.add_argument(
        '--args',
        help=('Comma separated arguments for the hook.  Escape commas in args '
              'with a backslash (\\).  '
              r"For example: --args='-i,--ignore=E265\,E501' would give "
              'you [-i, --ignore=E265,E501]'),
    )
    parser.add_argument(
        '--require-serial',
        action='store_true',
        help='Set `require_serial: true` for the hook',
    )
    args = parser.parse_args(argv)

    minimum_pre_commit_version = '0'

    if args.types_or:
        match_key = 'types_or'
        match_val = '[{}]'.format(', '.join(args.types_or))
        minimum_pre_commit_version = '2.9.2'
    elif args.types:
        match_key = 'types'
        match_val = f'[{args.types}]'
    else:
        match_key = 'files'
        match_val = args.files_regex

    make_repo(
        args.repo_path,
        name=args.package_name,
        description=args.description,
        language=args.language,
        entry=args.entry or args.package_name,
        id=args.id or args.entry or args.package_name,
        match_key=match_key,
        match_val=match_val,
        args=json.dumps(split_by_commas(args.args)),
        require_serial=json.dumps(args.require_serial),
        minimum_pre_commit_version=minimum_pre_commit_version,
    )
    return 0