Skip to content

Commit

Permalink
Implement share_test command.
Browse files Browse the repository at this point in the history
Make the tool test json blob produced by default. Add new command share_test - to publish this blob to gist (requires setting github credentials in ~/.planemo.yml) and produce a sharable URL to rich HTML report based on these results.

```
    % planemo test
    ...
    All 1 test(s) executed passed.
    simple_constructs[0]: passed
    % planemo share_test
    File published to Github Gist.
    Raw URL: https://gist.githubusercontent.com/jmchilton/457933350b28a3d1e752/raw/3888694aa109e0928a93ddd414b9acadaf578dc5/index
    Share results with URL: http://galaxyproject.github.io/planemo/tool_test_viewer.html?test_data_url=https://gist.githubusercontent.com/jmchilton/457933350b28a3d1e752/raw/3888694aa109e0928a93ddd414b9acadaf578dc5/index
    Embed results with markdown: [View Tool Test Results](http://galaxyproject.github.io/planemo/tool_test_viewer.html?test_data_url=https://gist.githubusercontent.com/jmchilton/457933350b28a3d1e752/raw/3888694aa109e0928a93ddd414b9acadaf578dc5/index)
```
  • Loading branch information
jmchilton committed Dec 9, 2014
1 parent 03f8e39 commit 32c6e7f
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/commands.rst
Expand Up @@ -16,6 +16,7 @@ documentation describes these commands.
.. include:: commands/lint.rst
.. include:: commands/project_init.rst
.. include:: commands/serve.rst
.. include:: commands/share_test.rst
.. include:: commands/shed_diff.rst
.. include:: commands/shed_upload.rst
.. include:: commands/syntax.rst
Expand Down
26 changes: 26 additions & 0 deletions docs/commands/share_test.rst
@@ -0,0 +1,26 @@

``share_test`` command
===============================

This section is auto-generated from the help text for the planemo command
``share_test``. This help message can be generated with ``planemo share_test
--help``.

**Usage**::

planemo share_test [OPTIONS] FILE_PATH

**Help**

Publish JSON test results to Github Gist and produce sharable URL.

Sharable URL can be used to share an HTML version of the report that
can be easily embedded in pull requests or commit messages. Requires
a ~/.planemo.yml with Github 'username' and 'password' defined in a
'github' section of that configuration file.

**Options**::


--help Show this message and exit.
22 changes: 22 additions & 0 deletions docs/planemo.reports.rst
@@ -0,0 +1,22 @@
planemo.reports package
=======================

Submodules
----------

planemo.reports.build_report module
-----------------------------------

.. automodule:: planemo.reports.build_report
:members:
:undoc-members:
:show-inheritance:


Module contents
---------------

.. automodule:: planemo.reports
:members:
:undoc-members:
:show-inheritance:
9 changes: 9 additions & 0 deletions docs/planemo.rst
Expand Up @@ -7,6 +7,7 @@ Subpackages
.. toctree::

planemo.commands
planemo.reports

Submodules
----------
Expand Down Expand Up @@ -51,6 +52,14 @@ planemo.galaxy_test module
:undoc-members:
:show-inheritance:

planemo.github_util module
--------------------------

.. automodule:: planemo.github_util
:members:
:undoc-members:
:show-inheritance:

planemo.io module
-----------------

Expand Down
38 changes: 38 additions & 0 deletions planemo/commands/cmd_create_gist.py
@@ -0,0 +1,38 @@
"""
"""
import click

from planemo.cli import pass_context
from planemo.io import info
from planemo import github_util

target_path = click.Path(
file_okay=True,
dir_okay=False,
resolve_path=True,
)


@click.command("create_gist")
@click.argument(
'path',
metavar="FILE_PATH",
type=target_path,
)
@click.option(
"--link_type",
type=click.Choice(["raw", "html"]),
default="raw",
help=("Link type to generate for the file.")
)
@pass_context
def cli(ctx, path, **kwds):
"""Download a tool repository as a tarball from the tool shed and extract
to the specified directory.
"""
file_url = github_util.publish_as_gist_file(ctx, path)
if kwds.get("link_type") == "raw":
share_url = file_url
else:
share_url = "http://htmlpreview.github.io/?%s" % file_url
info("File published to Github Gist - share with %s" % share_url)
43 changes: 43 additions & 0 deletions planemo/commands/cmd_share_test.py
@@ -0,0 +1,43 @@
"""
"""
import click

from planemo.cli import pass_context
from planemo.io import info
from planemo import github_util

PLANEMO_TEST_VIEWER_URL_TEMPLATE = (
"http://galaxyproject.github.io/planemo/tool_test_viewer.html"
"?test_data_url=%s"
)

target_path = click.Path(
file_okay=True,
dir_okay=False,
resolve_path=True,
)


@click.command("share_test")
@click.argument(
'path',
metavar="FILE_PATH",
type=target_path,
default="tool_test_output.json",
)
@pass_context
def cli(ctx, path, **kwds):
"""Publish JSON test results to Github Gist and produce sharable URL.
Sharable URL can be used to share an HTML version of the report that
can be easily embedded in pull requests or commit messages. Requires
a ~/.planemo.yml with Github 'username' and 'password' defined in a
'github' section of that configuration file.
"""
file_url = github_util.publish_as_gist_file(ctx, path)
share_url = PLANEMO_TEST_VIEWER_URL_TEMPLATE % file_url
info("File published to Github Gist.")
info("Raw URL: %s" % file_url)
info("Share results with URL: %s" % share_url)
markdown = "[View Tool Test Results](%s)" % share_url
info("Embed results with markdown: %s" % markdown)
2 changes: 1 addition & 1 deletion planemo/commands/cmd_test.py
Expand Up @@ -52,7 +52,7 @@
"--test_output_json",
type=click.Path(file_okay=True, resolve_path=True),
help="Output test report (planemo json).",
default=None,
default="tool_test_output.json",
)
@click.option(
"--job_output_files",
Expand Down
36 changes: 36 additions & 0 deletions planemo/github_util.py
@@ -0,0 +1,36 @@
"""
"""

try:
import github
has_github_lib = True
except ImportError:
github = None
has_github_lib = False

NO_GITHUB_DEP_ERROR = ("Cannot use github functionality - "
"PyGithub library not available.")


def get_github_config(ctx):
if "github" not in ctx.global_config:
return None
global_github_config = ctx.global_config["github"]
return GithubConfig(global_github_config)


class GithubConfig(object):

def __init__(self, config):
if not has_github_lib:
raise Exception(NO_GITHUB_DEP_ERROR)
self._github = github.Github(config["username"], config["password"])


def publish_as_gist_file(ctx, path, name="index"):
github_config = get_github_config(ctx)
user = github_config._github.get_user()
content = open(path, "r").read()
content_file = github.InputFileContent(content)
gist = user.create_gist(False, {name: content_file})
return gist.files[name].raw_url
8 changes: 7 additions & 1 deletion scripts/commands_to_rst.py
Expand Up @@ -15,7 +15,13 @@
planemo_cli = cli.planemo
runner = CliRunner()

INTERNAL_COMMANDS = ['travis_before_install', 'shed_download']
# Don't document the following commands - they should not be considered part
# of the planemo API.
INTERNAL_COMMANDS = [
'create_gist',
'travis_before_install',
'shed_download',
]

COMMAND_TEMPLATE = Template('''
``${command}`` command
Expand Down

0 comments on commit 32c6e7f

Please sign in to comment.