From f10d52dbfae3741d65e73f64eb8c1ccfcad6496c Mon Sep 17 00:00:00 2001 From: Chomba Ng'ang'a Date: Mon, 11 May 2015 19:33:59 +0300 Subject: [PATCH 1/7] Adding 'ghp_message' option to gh_deploy --- mkdocs/gh_deploy.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mkdocs/gh_deploy.py b/mkdocs/gh_deploy.py index 34ab121f..3dc6b765 100644 --- a/mkdocs/gh_deploy.py +++ b/mkdocs/gh_deploy.py @@ -16,8 +16,11 @@ def gh_deploy(config): config['site_dir']) try: command = ['ghp-import', '-p', config['site_dir']] - if 'remote_branch' in config: - command.extend(['-b', config['remote_branch']]) + extra_options = [('-b', 'remote_branch'), ('-b', 'ghp_message')] + for cmd_arg, config_option in extra_options: + if config_option in config: + command.extend([cmd_arg, config[config_option]]) + subprocess.check_call(command) except Exception: return From 47ab1c68092d1cb41b305db3f49dc0fa8ed947c9 Mon Sep 17 00:00:00 2001 From: Chomba Ng'ang'a Date: Mon, 11 May 2015 20:55:44 +0300 Subject: [PATCH 2/7] Fix ghp-import commandline flag in gh_deploy --- mkdocs/gh_deploy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdocs/gh_deploy.py b/mkdocs/gh_deploy.py index 3dc6b765..57abf2d0 100644 --- a/mkdocs/gh_deploy.py +++ b/mkdocs/gh_deploy.py @@ -16,7 +16,7 @@ def gh_deploy(config): config['site_dir']) try: command = ['ghp-import', '-p', config['site_dir']] - extra_options = [('-b', 'remote_branch'), ('-b', 'ghp_message')] + extra_options = [('-b', 'remote_branch'), ('-m', 'ghp_message')] for cmd_arg, config_option in extra_options: if config_option in config: command.extend([cmd_arg, config[config_option]]) From 4138474abc133514b5ae573ce729e8e5c6a65ff1 Mon Sep 17 00:00:00 2001 From: Chomba Ng'ang'a Date: Tue, 12 May 2015 13:36:58 +0300 Subject: [PATCH 3/7] Get custom commit message from cli option not config Fix logging message to indicate correct remote branch to deploy to --- mkdocs/cli.py | 7 +++++-- mkdocs/gh_deploy.py | 21 ++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/mkdocs/cli.py b/mkdocs/cli.py index b857183c..bdf38b92 100644 --- a/mkdocs/cli.py +++ b/mkdocs/cli.py @@ -38,6 +38,8 @@ 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") @click.group() @@ -120,13 +122,14 @@ 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('--commit-message', is_flag=False, help=commit_message_help) +def gh_deploy_command(config_file, clean, commit_message): """Deply your documentation to GitHub Pages""" config = load_config( config_file=config_file ) build.build(config, clean_site_dir=clean) - gh_deploy.gh_deploy(config) + gh_deploy.gh_deploy(config, commit_message=commit_message) @cli.command(name="new") diff --git a/mkdocs/gh_deploy.py b/mkdocs/gh_deploy.py index 57abf2d0..7706b3ef 100644 --- a/mkdocs/gh_deploy.py +++ b/mkdocs/gh_deploy.py @@ -5,22 +5,25 @@ import os log = logging.getLogger(__name__) -def gh_deploy(config): +def gh_deploy(config, commit_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']) - try: - command = ['ghp-import', '-p', config['site_dir']] - extra_options = [('-b', 'remote_branch'), ('-m', 'ghp_message')] - for cmd_arg, config_option in extra_options: - if config_option in config: - command.extend([cmd_arg, config[config_option]]) + command = ['ghp-import', '-p', config['site_dir']] + remote_branch = config.get('remote_branch', 'gh-pages') + command.extend(['-b', config['remote_branch']]) + + if commit_message is not None: + command.extend(['-m', commit_message]) + + log.info("Copying '%s' to `%s` branch and pushing to GitHub.", + config['site_dir'], remote_branch) + + try: subprocess.check_call(command) except Exception: return From 42c4e3da27cff91e677790de4ef4ac4fb75e8c9e Mon Sep 17 00:00:00 2001 From: Chomba Ng'ang'a Date: Tue, 12 May 2015 23:12:56 +0300 Subject: [PATCH 4/7] Update gh_deploy command option, add default config for remote_branch --- mkdocs/cli.py | 6 +++--- mkdocs/config/defaults.py | 3 +++ mkdocs/gh_deploy.py | 12 ++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/mkdocs/cli.py b/mkdocs/cli.py index bdf38b92..7ab31a1b 100644 --- a/mkdocs/cli.py +++ b/mkdocs/cli.py @@ -122,14 +122,14 @@ 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) -@click.option('--commit-message', is_flag=False, help=commit_message_help) -def gh_deploy_command(config_file, clean, commit_message): +@click.option('--message', '-m', help=commit_message_help) +def gh_deploy_command(config_file, clean, message): """Deply your documentation to GitHub Pages""" config = load_config( config_file=config_file ) build.build(config, clean_site_dir=clean) - gh_deploy.gh_deploy(config, commit_message=commit_message) + gh_deploy.gh_deploy(config, message=message) @cli.command(name="new") diff --git a/mkdocs/config/defaults.py b/mkdocs/config/defaults.py index 6ce0922e..9d7bcd6d 100644 --- a/mkdocs/config/defaults.py +++ b/mkdocs/config/defaults.py @@ -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')), ) diff --git a/mkdocs/gh_deploy.py b/mkdocs/gh_deploy.py index 7706b3ef..19d6ecf0 100644 --- a/mkdocs/gh_deploy.py +++ b/mkdocs/gh_deploy.py @@ -5,7 +5,7 @@ import os log = logging.getLogger(__name__) -def gh_deploy(config, commit_message=None): +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 ' @@ -14,13 +14,13 @@ def gh_deploy(config, commit_message=None): command = ['ghp-import', '-p', config['site_dir']] - remote_branch = config.get('remote_branch', 'gh-pages') - command.extend(['-b', config['remote_branch']]) + remote_branch = config['remote_branch'] + command.extend(['-b', remote_branch]) - if commit_message is not None: - command.extend(['-m', commit_message]) + if message is not None: + command.extend(['-m', message]) - log.info("Copying '%s' to `%s` branch and pushing to GitHub.", + log.info("Copying '%s' to '%s' branch and pushing to GitHub.", config['site_dir'], remote_branch) try: From 955abb678a5f696cc3ecb77a13cd8dce33147422 Mon Sep 17 00:00:00 2001 From: Chomba Ng'ang'a Date: Thu, 14 May 2015 19:38:53 +0300 Subject: [PATCH 5/7] Add documentation on remote_branch config option --- docs/user-guide/configuration.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/user-guide/configuration.md b/docs/user-guide/configuration.md index 97824ff0..bc83ca36 100644 --- a/docs/user-guide/configuration.md +++ b/docs/user-guide/configuration.md @@ -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. + +**default**: `gh-pages` + + ## Documentation layout ### pages From db167bec2a8fdf0b80d37e1ffe6aaf0a9e2fb3b6 Mon Sep 17 00:00:00 2001 From: Chomba Ng'ang'a Date: Thu, 14 May 2015 19:43:32 +0300 Subject: [PATCH 6/7] Add remote_branch as an optional CLI argument to gh_deploy --- mkdocs/cli.py | 6 ++++-- mkdocs/gh_deploy.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mkdocs/cli.py b/mkdocs/cli.py index 7ab31a1b..c5a6ec55 100644 --- a/mkdocs/cli.py +++ b/mkdocs/cli.py @@ -40,6 +40,7 @@ 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" @click.group() @@ -123,13 +124,14 @@ def json_command(clean, config_file, strict, site_dir): @click.option('--clean', is_flag=True, help=clean_help) @click.option('--config-file', type=click.File('rb'), help=config_file_help) @click.option('--message', '-m', help=commit_message_help) -def gh_deploy_command(config_file, clean, message): +@click.option('--branch', '-b', help=remote_branch_help) +def gh_deploy_command(config_file, clean, message, branch): """Deply your documentation to GitHub Pages""" config = load_config( config_file=config_file ) build.build(config, clean_site_dir=clean) - gh_deploy.gh_deploy(config, message=message) + gh_deploy.gh_deploy(config, message=message, branch=branch) @cli.command(name="new") diff --git a/mkdocs/gh_deploy.py b/mkdocs/gh_deploy.py index 19d6ecf0..bd136ee4 100644 --- a/mkdocs/gh_deploy.py +++ b/mkdocs/gh_deploy.py @@ -5,7 +5,7 @@ import os log = logging.getLogger(__name__) -def gh_deploy(config, message=None): +def gh_deploy(config, message=None, branch=None): if not os.path.exists('.git'): log.info('Cannot deploy - this directory does not appear to be a git ' @@ -14,7 +14,7 @@ def gh_deploy(config, message=None): command = ['ghp-import', '-p', config['site_dir']] - remote_branch = config['remote_branch'] + remote_branch = config['remote_branch'] if branch is None else branch command.extend(['-b', remote_branch]) if message is not None: From 0d2c63b97dfc301b01f1f3cc554454ce5257c807 Mon Sep 17 00:00:00 2001 From: Chomba Ng'ang'a Date: Fri, 15 May 2015 12:56:05 +0300 Subject: [PATCH 7/7] Small fixes to gh-deploy command Rename CLI option 'branch' to 'remote-branch' Pass CLI remote-branch option value to load_config instead of gh_deploy in cli.py Update documentation --- docs/user-guide/configuration.md | 2 +- mkdocs/cli.py | 12 +++++++----- mkdocs/gh_deploy.py | 7 +++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/user-guide/configuration.md b/docs/user-guide/configuration.md index bc83ca36..924e6207 100644 --- a/docs/user-guide/configuration.md +++ b/docs/user-guide/configuration.md @@ -82,7 +82,7 @@ google_analytics: ['UA-36723568-3', 'mkdocs.org'] ### remote_branch -Set the remote branch to commit to when using `gh-deploy` to update Github Pages. +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` diff --git a/mkdocs/cli.py b/mkdocs/cli.py index c5a6ec55..2eaeafb0 100644 --- a/mkdocs/cli.py +++ b/mkdocs/cli.py @@ -40,7 +40,8 @@ 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" +remote_branch_help = ("The remote branch to commit to for Github Pages. This " + "overrides the value specified in config") @click.group() @@ -124,14 +125,15 @@ def json_command(clean, config_file, strict, site_dir): @click.option('--clean', is_flag=True, help=clean_help) @click.option('--config-file', type=click.File('rb'), help=config_file_help) @click.option('--message', '-m', help=commit_message_help) -@click.option('--branch', '-b', help=remote_branch_help) -def gh_deploy_command(config_file, clean, message, branch): +@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, message=message, branch=branch) + gh_deploy.gh_deploy(config, message=message) @cli.command(name="new") diff --git a/mkdocs/gh_deploy.py b/mkdocs/gh_deploy.py index bd136ee4..b948f6ac 100644 --- a/mkdocs/gh_deploy.py +++ b/mkdocs/gh_deploy.py @@ -5,7 +5,7 @@ import os log = logging.getLogger(__name__) -def gh_deploy(config, message=None, branch=None): +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 ' @@ -14,14 +14,13 @@ def gh_deploy(config, message=None, branch=None): command = ['ghp-import', '-p', config['site_dir']] - remote_branch = config['remote_branch'] if branch is None else branch - command.extend(['-b', remote_branch]) + 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'], remote_branch) + config['site_dir'], config['remote_branch']) try: subprocess.check_call(command)