Skip to content

Commit

Permalink
Fix #2198 -- github_deploy custom commit messages
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Dec 27, 2015
1 parent 55f7bb1 commit d65ccc2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,8 @@ New in master
Features
--------

* Allow for customizing ``github_deploy`` commit messages with ``-m``
(Issue #2198)
* Commit to source branch automatically in ``github_deploy``
if ``GITHUB_COMMIT_SOURCE`` is set to True (Issue #2186)
* Hugo-like shortcodes (Issue #1707)
Expand Down
2 changes: 1 addition & 1 deletion docs/man/nikola.rst
Expand Up @@ -92,7 +92,7 @@ The most basic commands needed to get by are:
check for dangling links or unknown files
``nikola deploy [[preset [preset...]]``
deploy the site using the ``DEPLOY_COMMANDS`` setting
``nikola github_deploy```
``nikola github_deploy [-m COMMIT_MESSAGE]```
deploy the site to GitHub Pages
``nikola serve [-p PORT] [-a ADDRESS] [-d|--detach] [-b|--browser] [-6|--ipv6]``
start development web server
Expand Down
3 changes: 2 additions & 1 deletion docs/manual.txt
Expand Up @@ -1199,7 +1199,8 @@ sure you have ``nikola`` and ``git`` installed on your PATH.

If you want to use a custom domain, create your ``CNAME`` file in
``files/CNAME`` on the source branch. Nikola will copy it to the
output directory.
output directory. To add a custom commit message, use the ``-m`` option,
followed by your message.

Comments and Annotations
------------------------
Expand Down
30 changes: 19 additions & 11 deletions nikola/plugins/command/github_deploy.py
Expand Up @@ -61,7 +61,7 @@ class CommandGitHubDeploy(Command):

name = 'github_deploy'

doc_usage = ''
doc_usage = '[-m COMMIT_MESSAGE]'
doc_purpose = 'deploy the site to GitHub Pages'
doc_description = dedent(
"""\
Expand All @@ -71,10 +71,19 @@ class CommandGitHubDeploy(Command):
"""
)

cmd_options = [
{
'name': 'commit_message',
'short': 'm',
'long': 'message',
'default': 'Nikola auto commit.',
'type': str,
'help': 'Commit message (default: Nikola auto commit.)',
},
]
logger = None

def _execute(self, command, args):
def _execute(self, options, args):
"""Run the deployment."""
self.logger = get_logger(CommandGitHubDeploy.name, STDERR_HANDLER)

Expand All @@ -93,7 +102,7 @@ def _execute(self, command, args):
os.unlink(f)

# Commit and push
self._commit_and_push()
self._commit_and_push(options['commit_message'])

return

Expand All @@ -112,18 +121,17 @@ def _run_command(self, command, xfail=False):
)
raise SystemError(e.returncode)

def _commit_and_push(self):
def _commit_and_push(self, commit_first_line):
"""Commit all the files and push."""
source = self.site.config['GITHUB_SOURCE_BRANCH']
deploy = self.site.config['GITHUB_DEPLOY_BRANCH']
remote = self.site.config['GITHUB_REMOTE_NAME']
autocommit = self.site.config['GITHUB_COMMIT_SOURCE']

try:
if autocommit:
commit_message = (
'Nikola auto commit.\n\n'
'Nikola version: {0}'.format(__version__)
'{0}\n\n'
'Nikola version: {1}'.format(commit_first_line, __version__)
)
e = self._run_command(['git', 'checkout', source], True)
if e != 0:
Expand All @@ -138,9 +146,9 @@ def _commit_and_push(self):

source_commit = uni_check_output(['git', 'rev-parse', source])
commit_message = (
'Nikola auto commit.\n\n'
'Source commit: {0}'
'Nikola version: {1}'.format(source_commit, __version__)
'{0}\n\n'
'Source commit: {1}'
'Nikola version: {2}'.format(commit_first_line, source_commit, __version__)
)
output_folder = self.site.config['OUTPUT_FOLDER']

Expand Down

0 comments on commit d65ccc2

Please sign in to comment.