handkerchief 0.2
simple offline issue reader for GitHub Issues
License: MIT
Keywords: github,issues,offline

Handkerchief - a simple offline issue reader for GitHub Issues
==============================================================

This script allows you to easily download the open issues of a GitHub
Repository and store them in a offline browsable, single standalone html file.

The name
--------

I chose the name, because the obvious pun name "tissues" was already taken. It
also fits, because being offline is somewhat oldfashioned, just like the word
handkerchief.

There are three ways to set handkerchief up:

Using pip
---------

This is the easiest way and probably the right choice for most people. Make
sure you have `pip <https://pip.pypa.io/en/stable/>`_ installed and type

.. code:: bash

   pip install handkerchief

into your terminal to install handkerchief and all dependencies onto your
computer. This might require admin access.

You can now invoke handkerchief from everywhere using

.. code:: bash

   handkerchief

In a virtualenv
---------------

If a system wide installation with pip is too intrusive for you, and you need
handkerchief only in a certain environment, you can try
`virtualenv <https://virtualenv.pypa.io/en/latest/>`_. Within the activated
virtualenv, just type

.. code:: bash

   pip install handkerchief

You can then invoke handkerchief while you are in the virtualenv by typing

.. code:: bash

   handkerchief

As standalone script
--------------------

You can take just the handkerchief.py from the repository and put it where you need it. No installation required. From there you can invoke it with

.. code:: bash

   python handkerchief.py --remote-layouts

From repository
---------------

You can also clone the repository to some place on your computer and use it
from there. Depending on your system, you might want to make it available from
everywhere by putting the repo in your PATH, define an alias or something else.

For example, if you are on a mac you can optionally add the following to your
~/.bash_profile.

.. code:: bash

   function handkerchief {
     # change this path to the location of handkerchief.py
     hand=~/handkerchief/handkerchief.py
     if [[ $1 != "" ]] ; then
       python $hand --remote-layouts $1
        else
       repo=$(git remote -v | head -n1 | awk '{print $2}' | sed -e 's,.*:\(.*/\)\?,,' -e 's/\.git$//')
       if [[ $repo == *https://* ]] ; then
         python $hand ${repo#https://github.com/}
       elif [[ $repo == *git@github.com* ]] ; then
         python $hand ${repo#git@github.com:}
       else
         echo "Provide parameter"
       fi
     fi
   }


Specifying repositories
-----------------------

The simplest way to use handkerchief is to call it with the user or
organisation and repository name

.. code:: bash

   handkerchief jreinhardt/tissues

If you are calling handkerchief from within a git repository, it tries to figure out a GitHub repo for it

.. code:: bash

   cd /path/to/repository
   handkerchief

Or if you have one or many .html files generated by handkerchief in a
directory, it extracts the repositories to check from them.

.. code:: bash

   cd /path/to/directory/with/handkerchief/htmls
   handkerchief

Commandline parameters
----------------------

There are a few options available, for example to choose a layout, specify how to authenticate (to avoid GitHubs rate limits) and much more.

For details see

.. code:: bash

   handkerchief --help`.


Layouts
-------

Handkerchief offers a simple way to modify the visual appearance and
functionality of the resulting offline html file, by changing to a different layout.

Handkerchief ships with a default layout that is available when installing with
pip. For developing layouts it is convenient to ask handkerchief to search for
layouts in a specific place using the `--layout-dir`. When using handkerchief
as a standalone script, it can look layouts up at the handkerchief GitHub
repository using the `--remote-layouts` option.

A layout consists of a parameter and a template file, and a number of
javascript and css files, which reside in a subfolder of the layouts folder in
the handkerchief repository. To produce the output file, the template file gets
populated with the data, and the javascript and css files are inlined. If not
told otherwise, handkerchief will fetch layouts from the handkerchief GitHub
repository, so that always the most up to date version of the layout is used.

The parameter file is a json file with the same name as the subfolder in which
it resides. It contains an associative array with three keys:

* html: the file name of the template file
* css: a list of filenames of stylesheets to inline
* js: a list of filenames of javascript files to inline

The template is processed by `Jinja2 <http://jinja.pocoo.org/>`_, and the
following variables are available:

* reponame: a string with the name of the repository in the form
  username/reponame
* repo: a dictionary containing information about the repository, see
  `GitHub API docs (1) <https://developer.github.com/v3/repos/>`_
* issues: a list of dictionaries containing issue data, see
  `GitHub API docs (2) <https://developer.github.com/v3/issues/>`_. Each
  issue has an additional field:
  - 'labelnames' with a list of all labels for this issue

  - 'comments_list' with a list of all comments  for this issue
    (see `GitHub API docs (3) <https://developer.github.com/v3/issues/comments>`_).
    The comment data is augmented by a string in `comment['user']['avatar_class']`
    which contains a css class that sets the avatar of the user as background
    image of the element.

  - `issue['user']['avatar_class']` which works in the same way as in comments.
* labels: a list of dictionaries containing label data, see
  `GitHub API docs (4) <https://developer.github.com/v3/issues/labels>`_
* milestones: a list of dictionaries containing milestone data, see
  `GitHub API docs (5) <https://developer.github.com/v3/issues/milestones>`_
* assignees: a list of dictionaries contining information about assigness, see
  `GitHub API docs (6) <https://developer.github.com/v3/issues/assignees>`_
* javascript: a list of dictionaries with the names and contents of the
  javascript files.
* stylesheets: a list with the contents of the stylesheets. Additionally it
  contains a stylesheet that defines classes of the form `avatar_username` that
  set the avatar of a user as background image of an element.

If you have created a new layout or improved a existing one, feel free to open
a pull request, contributions are always welcome!

Dependencies
------------

Requires `Python 2.7 <http://www.python.org>`_, the
`Jinja2 template system <http://jinja.pocoo.org/>`_  and the
`requests library <http://www.python-requests.org/>`_.

For most Linux distributions, these should be available via the package
manager. On MacOS you can install the dependencies by:

.. code:: bash

   # using homebrew
   brew install python
   # using pip
   pip install -r requirements.txt

For Windows there is an installer for Python available from the
`Python Website <http://www.python.org/downloads>`_, and the rest can be
installed via pip:

.. code:: bash

   pip install -r requirements.txt

Contributors
------------

There are a few people that contributed to handkerchief and therefore deserve to credit:

* lukasoppermann turned the initial HTML template from horrible to beauti- and useful
* laurentj contributed several small layout fixes
* DonnchaC added code for authenticating by token
* philfreo contributed a requirements.txt


License
-------

Handkerchief is licensed under the `MIT license <http://opensource.org/licenses/MIT>`_

    The MIT License (MIT)

    Copyright (c) 2013 Johannes Reinhardt <jreinhardt@ist-dein-freund.de>

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.