mirror of
https://github.com/mkdocs/mkdocs.git
synced 2026-03-27 09:58:31 +07:00
Merge pull request #516 from mbacho/master
Adding custom commit message option to gh_deploy
This commit is contained in:
@@ -80,6 +80,13 @@ google_analytics: ['UA-36723568-3', 'mkdocs.org']
|
||||
**default**: `null`
|
||||
|
||||
|
||||
### remote_branch
|
||||
|
||||
Set the remote branch to commit to when using `gh-deploy` to update Github Pages. This option can be overriden by a commandline option in `gh-deploy`.
|
||||
|
||||
**default**: `gh-pages`
|
||||
|
||||
|
||||
## Documentation layout
|
||||
|
||||
### pages
|
||||
|
||||
@@ -38,6 +38,10 @@ theme_help = "The theme to use when building your documentation."
|
||||
theme_choices = utils.get_theme_names()
|
||||
site_dir_help = "The directory to output the result of the documentation build."
|
||||
reload_help = "Enable and disable the live reloading in the development server."
|
||||
commit_message_help = ("A commit message to use when commiting to the "
|
||||
"Github Pages remote branch")
|
||||
remote_branch_help = ("The remote branch to commit to for Github Pages. This "
|
||||
"overrides the value specified in config")
|
||||
|
||||
|
||||
@click.group()
|
||||
@@ -120,13 +124,16 @@ def json_command(clean, config_file, strict, site_dir):
|
||||
@cli.command(name="gh-deploy")
|
||||
@click.option('--clean', is_flag=True, help=clean_help)
|
||||
@click.option('--config-file', type=click.File('rb'), help=config_file_help)
|
||||
def gh_deploy_command(config_file, clean):
|
||||
@click.option('--message', '-m', help=commit_message_help)
|
||||
@click.option('--remote-branch', '-b', help=remote_branch_help)
|
||||
def gh_deploy_command(config_file, clean, message, remote_branch):
|
||||
"""Deply your documentation to GitHub Pages"""
|
||||
config = load_config(
|
||||
config_file=config_file
|
||||
config_file=config_file,
|
||||
remote_branch=remote_branch
|
||||
)
|
||||
build.build(config, clean_site_dir=clean)
|
||||
gh_deploy.gh_deploy(config)
|
||||
gh_deploy.gh_deploy(config, message=message)
|
||||
|
||||
|
||||
@cli.command(name="new")
|
||||
|
||||
@@ -103,4 +103,7 @@ DEFAULT_SCHEMA = (
|
||||
# MkDocs itself. A good example here would be including the current
|
||||
# project version.
|
||||
('extra', config_options.Type(dict, default={})),
|
||||
|
||||
# the remote branch to commit to when using gh-deploy
|
||||
('remote_branch', config_options.Type(str, default='gh-pages')),
|
||||
)
|
||||
|
||||
@@ -5,19 +5,24 @@ import os
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def gh_deploy(config):
|
||||
def gh_deploy(config, message=None):
|
||||
|
||||
if not os.path.exists('.git'):
|
||||
log.info('Cannot deploy - this directory does not appear to be a git '
|
||||
'repository')
|
||||
return
|
||||
|
||||
log.info("Copying '%s' to `gh-pages` branch and pushing to GitHub.",
|
||||
config['site_dir'])
|
||||
command = ['ghp-import', '-p', config['site_dir']]
|
||||
|
||||
command.extend(['-b', config['remote_branch']])
|
||||
|
||||
if message is not None:
|
||||
command.extend(['-m', message])
|
||||
|
||||
log.info("Copying '%s' to '%s' branch and pushing to GitHub.",
|
||||
config['site_dir'], config['remote_branch'])
|
||||
|
||||
try:
|
||||
command = ['ghp-import', '-p', config['site_dir']]
|
||||
if 'remote_branch' in config:
|
||||
command.extend(['-b', config['remote_branch']])
|
||||
subprocess.check_call(command)
|
||||
except Exception:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user