def file_config(tmpdir): dir1 = tmpdir.join('1') dir2 = tmpdir.join('2') rev1 = init_repo(dir1) rev2 = init_repo(dir2) repos_json = tmpdir.join('repos.json') repos_json.write(json.dumps({'repo1': str(dir1), 'repo2': str(dir2)})) cfg = tmpdir.join('config.json') cfg.write( json.dumps({ 'output_dir': 'output', 'source': 'all_repos.source.json_file', 'source_settings': { 'filename': str(repos_json) }, 'push': 'all_repos.push.merge_to_master', 'push_settings': {}, })) cfg.chmod(0o600) return auto_namedtuple( output_dir=tmpdir.join('output'), cfg=cfg, repos_json=repos_json, dir1=dir1, dir2=dir2, rev1=rev1, rev2=rev2, )
def fake_bitbucket_repo(tmpdir): # hax: make the repo end with proj/slug so it "looks" like a bitbucket repo src = tmpdir.join('proj/slug') init_repo(src) dest = tmpdir.join('dest') subprocess.check_call(('git', 'clone', src, dest)) subprocess.check_call(( 'git', '-C', dest, 'checkout', 'origin/master', '-b', 'feature', )) subprocess.check_call(( 'git', '-C', dest, 'commit', '--allow-empty', '-m', 'This is a commit message\n\nHere is some more information!', )) settings = Settings('user', 'token', 'bitbucket.domain.com') return auto_namedtuple(src=src, dest=dest, settings=settings)
def fake_github_repo(tmpdir): # hax: make the repo end with :repo/slug so it "looks" like a github repo src = tmpdir.join('repo:user/slug') init_repo(src) dest = tmpdir.join('dest') subprocess.check_call(('git', 'clone', src, dest)) subprocess.check_call(( 'git', '-C', dest, 'checkout', 'origin/master', '-b', 'feature', )) subprocess.check_call(( 'git', '-C', dest, 'commit', '--allow-empty', '-m', 'This is a commit message\n\nHere is some more information!', )) settings = github_pull_request.Settings(api_key='fake', username='******') return auto_namedtuple(src=src, dest=dest, settings=settings)
def cloned(tmpdir): src = tmpdir.join('repo') init_repo(src) dest = tmpdir.join('dest') subprocess.check_call(('git', 'clone', src, dest)) subprocess.check_call(( 'git', '-C', dest, 'checkout', 'origin/master', '-b', 'feature', )) subprocess.check_call(( 'git', '-C', dest, 'commit', '--allow-empty', '-m', 'This is a commit message\n\nHere is some more information!', )) return auto_namedtuple(src=src, dest=dest)
def fake_autoupdatable(tmpdir): repo = tmpdir.join('autoupdatable') update_repo = tmpdir.join('autoupdatable_clone') git.init_repo(repo) def init(contents): repo.join('.pre-commit-config.yaml').write(contents) git.commit(repo) subprocess.check_call(('git', 'clone', repo, update_repo)) def fake_autoupdate(): with open('.pre-commit-config.yaml') as f: contents = f.read() with open('.pre-commit-config.yaml', 'w') as f: f.write(contents.replace('rev: v1.4.0-1', 'rev: v2.0.0')) with mock.patch.object( pre_commit_autopep8_migrate, 'autoupdate', fake_autoupdate, ): with mock.patch.object(pre_commit_autopep8_migrate, 'check_fix'): yield auto_namedtuple( init=init, repo=repo, update_repo=update_repo, )
def repo(tmpdir): src_repo = tmpdir.join('hook_repo') init_repo(src_repo) write_file_commit(src_repo, 'azure-pipelines.yml', SAMPLE) update_repo = tmpdir.join('update_repo') subprocess.check_call(('git', 'clone', src_repo, update_repo)) return auto_namedtuple(src_repo=src_repo, update_repo=update_repo)
def fake_clone(tmpdir_factory): src = tmpdir_factory.mktemp('repo') init_repo(src) write_file_commit(src, 'job--pre-commit.yml', 'jobs: []') subprocess.check_call(('git', '-C', src, 'tag', 'v1.0.0')) write_file_commit(src, 'README.md', '# template repo') def clone_func(service, repo, path): subprocess.check_call(('git', 'clone', src, path)) subprocess.check_call(('git', 'fetch', 'origin', 'HEAD'), cwd=path) with mock.patch.object(azure_pipelines_autoupdate, '_clone', clone_func): yield
def setup_py_repo(tmpdir): src_repo = tmpdir.join('hook_repo') init_repo(src_repo) src_repo.join('setup.cfg').write('[bdist_wheel]\nuniversal = true\n') write_file_commit( src_repo, 'setup.py', 'from setuptools import setup\n' 'setup(name="pkg", version="1.0")\n', ) update_repo = tmpdir.join('update_repo') subprocess.check_call(('git', 'clone', src_repo, update_repo)) return auto_namedtuple(src_repo=src_repo, update_repo=update_repo)
def autoupdatable(tmpdir): hook_repo = tmpdir.join('hook_repo') init_repo(hook_repo) hook_repo.join('.pre-commit-hooks.yaml').write( '- id: hook\n' ' name: Hook\n' ' entry: echo hi\n' ' language: system\n' ' types: [file]\n', ) subprocess.check_call(('git', '-C', hook_repo, 'add', '.')) subprocess.check_call(( 'git', '-C', hook_repo, 'commit', '-m', 'add hook', )) rev = revparse(hook_repo) subprocess.check_call(('git', '-C', hook_repo, 'tag', 'v1')) consuming_repo = tmpdir.join('consuming') init_repo(consuming_repo) consuming_repo.join('.pre-commit-config.yaml').write( f'- repo: {hook_repo}\n' f' rev: {rev}\n' f' hooks:\n' f' - id: hook\n', ) subprocess.check_call(('git', '-C', consuming_repo, 'add', '.')) subprocess.check_call(( 'git', '-C', consuming_repo, 'commit', '-m', 'consume hook', )) update_repo = tmpdir.join('update_repo') subprocess.check_call(('git', 'clone', consuming_repo, update_repo)) return auto_namedtuple( hook_repo=hook_repo, hook_repo_rev=rev, consuming_repo=consuming_repo, update_repo=update_repo, )
def fake_autoupdatable(tmpdir): repo = tmpdir.join('autoupdatable') update_repo = tmpdir.join('autoupdatable_clone') git.init_repo(repo) def init(contents): repo.join('.pre-commit-config.yaml').write(contents) git.commit(repo) subprocess.check_call(('git', 'clone', repo, update_repo)) with mock.patch.object(_pre_commit_hook_migrate, 'autoupdate'): with mock.patch.object(pre_commit_flake8_migrate, 'check_fix'): yield auto_namedtuple( init=init, repo=repo, update_repo=update_repo, )