diff options
Diffstat (limited to 'nikola/plugins/command/github_deploy.py')
| -rw-r--r-- | nikola/plugins/command/github_deploy.py | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/nikola/plugins/command/github_deploy.py b/nikola/plugins/command/github_deploy.py index b5ad322..d2c1f3f 100644 --- a/nikola/plugins/command/github_deploy.py +++ b/nikola/plugins/command/github_deploy.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2014-2016 Puneeth Chaganti and others. +# Copyright © 2014-2020 Puneeth Chaganti and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -26,14 +26,13 @@ """Deploy site to GitHub Pages.""" -from __future__ import print_function import os import subprocess from textwrap import dedent from nikola.plugin_categories import Command from nikola.plugins.command.check import real_scan_files -from nikola.utils import get_logger, req_missing, clean_before_deployment, STDERR_HANDLER +from nikola.utils import req_missing, clean_before_deployment from nikola.__main__ import main from nikola import __version__ @@ -54,6 +53,12 @@ def check_ghp_import_installed(): req_missing(['ghp-import2'], 'deploy the site to GitHub Pages') +class DeployFailedException(Exception): + """An internal exception for deployment errors.""" + + pass + + class CommandGitHubDeploy(Command): """Deploy site to GitHub Pages.""" @@ -63,11 +68,9 @@ class CommandGitHubDeploy(Command): doc_purpose = 'deploy the site to GitHub Pages' doc_description = dedent( """\ - This command can be used to deploy your site to GitHub Pages. - - It uses ghp-import to do this task. + This command can be used to deploy your site to GitHub Pages. It uses ghp-import to do this task. It also optionally commits to the source branch. - """ + Configuration help: https://getnikola.com/handbook.html#deploying-to-github""" ) cmd_options = [ { @@ -76,15 +79,12 @@ class CommandGitHubDeploy(Command): 'long': 'message', 'default': 'Nikola auto commit.', 'type': str, - 'help': 'Commit message (default: Nikola auto commit.)', + 'help': 'Commit message', }, ] - logger = None def _execute(self, options, args): """Run the deployment.""" - self.logger = get_logger(CommandGitHubDeploy.name, STDERR_HANDLER) - # Check if ghp-import is installed check_ghp_import_installed() @@ -102,12 +102,10 @@ class CommandGitHubDeploy(Command): # Remove drafts and future posts if requested (Issue #2406) undeployed_posts = clean_before_deployment(self.site) if undeployed_posts: - self.logger.notice("Deleted {0} posts due to DEPLOY_* settings".format(len(undeployed_posts))) + self.logger.warning("Deleted {0} posts due to DEPLOY_* settings".format(len(undeployed_posts))) # Commit and push - self._commit_and_push(options['commit_message']) - - return + return self._commit_and_push(options['commit_message']) def _run_command(self, command, xfail=False): """Run a command that may or may not fail.""" @@ -122,7 +120,7 @@ class CommandGitHubDeploy(Command): 'Failed GitHub deployment -- command {0} ' 'returned {1}'.format(e.cmd, e.returncode) ) - raise SystemError(e.returncode) + raise DeployFailedException(e.returncode) def _commit_and_push(self, commit_first_line): """Commit all the files and push.""" @@ -145,9 +143,16 @@ class CommandGitHubDeploy(Command): if e != 0: self._run_command(['git', 'commit', '-am', commit_message]) else: - self.logger.notice('Nothing to commit to source branch.') + self.logger.info('Nothing to commit to source branch.') + + try: + source_commit = uni_check_output(['git', 'rev-parse', source]) + except subprocess.CalledProcessError: + try: + source_commit = uni_check_output(['git', 'rev-parse', 'HEAD']) + except subprocess.CalledProcessError: + source_commit = '?' - source_commit = uni_check_output(['git', 'rev-parse', source]) commit_message = ( '{0}\n\n' 'Source commit: {1}' @@ -161,7 +166,7 @@ class CommandGitHubDeploy(Command): if autocommit: self._run_command(['git', 'push', '-u', remote, source]) - except SystemError as e: + except DeployFailedException as e: return e.args[0] self.logger.info("Successful deployment") |
