def _cfg_set( gh_config_name="foo", ssh_url='made-up-ssh-url', http_url='made-up-http-url', api_url='made-up-api-url', disable_tls_validation=False, webhook_token='made-up-token', available_protocols=['https', 'ssh'], tu_username='******', tu_password='******', tu_private_key='first key line \n second key line \n third key line', tu_auth_token='made-up-token', tu_email_address='*****@*****.**', ): cfg_set_mock = MagicMock() gh_cfg = GithubConfig( name=gh_config_name, raw_dict={ 'sshUrl': ssh_url, 'httpUrl': http_url, 'apiUrl': api_url, 'disable_tls_validation': disable_tls_validation, 'webhook_token': webhook_token, 'available_protocols': available_protocols, 'technical_users': [{ 'username': tu_username, 'password': tu_password, 'privateKey': tu_private_key, 'authToken': tu_auth_token, 'emailAddress': tu_email_address, }], }, ) cfg_set_mock.github.return_value = gh_cfg return cfg_set_mock
def clone_into( target_directory: str, github_cfg: GithubConfig, github_repo_path: str, checkout_branch: str = None, ) -> 'GitHelper': protocol = github_cfg.preferred_protocol() if protocol is Protocol.SSH: cmd_env, tmp_id = _ssh_auth_env(github_cfg=github_cfg) url = urljoin(github_cfg.ssh_url(), github_repo_path) elif protocol is Protocol.HTTPS: url = url_with_credentials(github_cfg, github_repo_path) else: raise NotImplementedError args = ['--quiet'] if checkout_branch is not None: args += ['--branch', checkout_branch, '--single-branch'] args += [url, target_directory] repo = git.Git() if protocol is Protocol.SSH: with repo.custom_environment(**cmd_env): repo.clone(*args) else: repo.clone(*args) if protocol is Protocol.SSH: os.unlink(tmp_id.name) return GitHelper( repo=target_directory, github_cfg=github_cfg, github_repo_path=github_repo_path, )