def test_ghp_import_error(self, mock_popen, mock_call, mock_get_config, mock_run_import, mock_get_prev_commit, mock_try_rebase): directory = tempfile.mkdtemp() open(os.path.join(directory, 'file'), 'a').close() try: popen = mock.Mock() mock_popen.return_value = popen error_string = 'TestError123' popen.communicate.return_value = ('', error_string) popen.wait.return_value = 1 result, ghp_error = ghp_import.ghp_import( directory, "test message", remote='fake-remote-name', branch='fake-branch-name') self.assertEqual(result, False) self.assertEqual(ghp_error, error_string) finally: shutil.rmtree(directory)
def gh_deploy(config, message=None): if not _is_cwd_git_repo(): log.error('Cannot deploy - this directory does not appear to be a git ' 'repository') if message is None: sha = _get_current_sha() message = default_message.format(version=mkdocs.__version__, sha=sha) remote_branch = config['remote_branch'] remote_name = config['remote_name'] log.info("Copying '%s' to '%s' branch and pushing to GitHub.", config['site_dir'], config['remote_branch']) ghp_import.ghp_import(config['site_dir'], message, remote_name, remote_branch) cname_file = os.path.join(config['site_dir'], 'CNAME') # Does this repository have a CNAME set for GitHub pages? if os.path.isfile(cname_file): # This GitHub pages repository has a CNAME configured. with (open(cname_file, 'r')) as f: cname_host = f.read().strip() log.info( 'Based on your CNAME file, your documentation should be ' 'available shortly at: http://%s', cname_host) log.info('NOTE: Your DNS records must be configured appropriately for ' 'your CNAME URL to work.') return host, path = _get_remote_url(remote_name) if host is None: # This could be a GitHub Enterprise deployment. log.info('Your documentation should be available shortly.') else: username, repo = path.split('/', 1) if repo.endswith('.git'): repo = repo[:-len('.git')] url = 'http://%s.github.io/%s' % (username, repo) log.info('Your documentation should shortly be available at: ' + url)
def test_ghp_import(self, mock_popen, mock_call, mock_get_config, mock_get_prev_commit, mock_try_rebase): directory = tempfile.mkdtemp() open(os.path.join(directory, 'file'), 'a').close() try: popen = mock.Mock() mock_popen.return_value = popen popen.communicate.return_value = ('', '') popen.wait.return_value = 0 ghp_import.ghp_import(directory, "test message", remote='fake-remote-name', branch='fake-branch-name') self.assertEqual(mock_popen.call_count, 2) self.assertEqual(mock_call.call_count, 0) finally: shutil.rmtree(directory)
def gh_deploy(config, message=None): if not _is_cwd_git_repo(): log.error("Cannot deploy - this directory does not appear to be a git " "repository") if message is None: sha = _get_current_sha() message = default_message.format(version=mkdocs.__version__, sha=sha) remote_branch = config["remote_branch"] remote_name = config["remote_name"] log.info("Copying '%s' to '%s' branch and pushing to GitHub.", config["site_dir"], config["remote_branch"]) ghp_import.ghp_import(config["site_dir"], message, remote_name, remote_branch) cname_file = os.path.join(config["site_dir"], "CNAME") # Does this repository have a CNAME set for GitHub pages? if os.path.isfile(cname_file): # This GitHub pages repository has a CNAME configured. with (open(cname_file, "r")) as f: cname_host = f.read().strip() log.info( "Based on your CNAME file, your documentation should be " "available shortly at: http://%s", cname_host ) log.info("NOTE: Your DNS records must be configured appropriately for " "your CNAME URL to work.") return host, path = _get_remote_url(remote_name) if host is None: # This could be a GitHub Enterprise deployment. log.info("Your documentation should be available shortly.") else: username, repo = path.split("/", 1) if repo.endswith(".git"): repo = repo[: -len(".git")] url = "http://%s.github.io/%s" % (username, repo) log.info("Your documentation should shortly be available at: " + url)
def gh_deploy(config, message=None, force=False, ignore_version=False): if not _is_cwd_git_repo(): log.error('Cannot deploy - this directory does not appear to be a git ' 'repository') remote_branch = config['remote_branch'] remote_name = config['remote_name'] if not ignore_version: _check_version(remote_branch) if message is None: message = default_message sha = _get_current_sha(os.path.dirname(config.config_file_path)) message = message.format(version=mkdocs.__version__, sha=sha) log.info("Copying '%s' to '%s' branch and pushing to GitHub.", config['site_dir'], config['remote_branch']) result, error = ghp_import.ghp_import(config['site_dir'], message, remote_name, remote_branch, force) if not result: log.error("Failed to deploy to GitHub with error: \n%s", error) raise SystemExit(1) else: cname_file = os.path.join(config['site_dir'], 'CNAME') # Does this repository have a CNAME set for GitHub pages? if os.path.isfile(cname_file): # This GitHub pages repository has a CNAME configured. with(open(cname_file, 'r')) as f: cname_host = f.read().strip() log.info('Based on your CNAME file, your documentation should be ' 'available shortly at: http://%s', cname_host) log.info('NOTE: Your DNS records must be configured appropriately for ' 'your CNAME URL to work.') return host, path = _get_remote_url(remote_name) if host is None: # This could be a GitHub Enterprise deployment. log.info('Your documentation should be available shortly.') else: username, repo = path.split('/', 1) if repo.endswith('.git'): repo = repo[:-len('.git')] url = 'https://%s.github.io/%s/' % (username, repo) log.info('Your documentation should shortly be available at: ' + url)
def test_ghp_import_error(self, mock_popen, mock_call, mock_get_config, mock_run_import, mock_get_prev_commit, mock_try_rebase): directory = tempfile.mkdtemp() open(os.path.join(directory, 'file'), 'a').close() try: popen = mock.Mock() mock_popen.return_value = popen error_string = 'TestError123' popen.communicate.return_value = ('', error_string) popen.wait.return_value = 1 result, ghp_error = ghp_import.ghp_import(directory, "test message", remote='fake-remote-name', branch='fake-branch-name') self.assertEqual(result, False) self.assertEqual(ghp_error, error_string) finally: shutil.rmtree(directory)
def gh_deploy(config, message=None, force=False, ignore_version=False): if not _is_cwd_git_repo(): log.error('Cannot deploy - this directory does not appear to be a git ' 'repository') page_type = config['page_type'] if page_type == 'user' or page_type == 'org': remote_branch = 'master' else: remote_branch = config['remote_branch'] remote_name = config['remote_name'] if not ignore_version: _check_version(remote_branch) if message is None: message = default_message sha = _get_current_sha(os.path.dirname(config.config_file_path)) message = message.format(version=mkdocs.__version__, sha=sha) log.info("Copying '%s' to '%s' branch and pushing to GitHub.", config['site_dir'], config['remote_branch']) result, error = ghp_import.ghp_import(config['site_dir'], message, remote_name, remote_branch, force) if not result: log.error("Failed to deploy to GitHub with error: \n%s", error) raise SystemExit(1) else: cname_file = os.path.join(config['site_dir'], 'CNAME') # Does this repository have a CNAME set for GitHub pages? if os.path.isfile(cname_file): # This GitHub pages repository has a CNAME configured. with (open(cname_file, 'r')) as f: cname_host = f.read().strip() log.info( 'Based on your CNAME file, your documentation should be ' 'available shortly at: http://%s', cname_host) log.info( 'NOTE: Your DNS records must be configured appropriately for ' 'your CNAME URL to work.') return host, path = _get_remote_url(remote_name) if host is None: # This could be a GitHub Enterprise deployment. log.info('Your documentation should be available shortly.') elif page_type == 'user' or page_type == 'org': username, repo = path.split('/', 1) url = 'https://{}.github.io/'.format(username) log.info('Your documentation should shortly be available at: ' + url) else: username, repo = path.split('/', 1) if repo.endswith('.git'): repo = repo[:-len('.git')] url = 'https://{}.github.io/{}/'.format(username, repo) log.info('Your documentation should shortly be available at: ' + url)