From 366bec84da8aac2b36caeb2993f8bf6008121d93 Mon Sep 17 00:00:00 2001
From: Jeremy Cline <jeremy@jcline.org>
Date: May 10 2017 19:09:40 +0000
Subject: [PATCH 1/4] Add a gitignore file.


Signed-off-by: Jeremy Cline <jeremy@jcline.org>

---

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c52bac5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,22 @@
+# Build artifacts
+__pycache__/
+*.py[cod]
+build/
+dist/
+sdist/
+docs/_build/
+eggs/
+*egg-info/
+*.egg
+
+# Vim temporary files
+*~
+*.swp
+*.swo
+
+# Unit tests and coverage reports
+.tox/
+.coverage
+.cache
+coverage.xml
+htmlcov

From 5cec0b8c7b43fe8d3e0f20ac96265b8780c3c442 Mon Sep 17 00:00:00 2001
From: Jeremy Cline <jeremy@jcline.org>
Date: May 10 2017 19:10:28 +0000
Subject: [PATCH 2/4] Add a skeleton Python project


Signed-off-by: Jeremy Cline <jeremy@jcline.org>

---

diff --git a/dev-requirements.txt b/dev-requirements.txt
new file mode 100644
index 0000000..0f26762
--- /dev/null
+++ b/dev-requirements.txt
@@ -0,0 +1,9 @@
+# Testing requirements
+flake8
+mock
+pytest
+pytest-cov
+
+# Documentation build requirements
+sphinx
+sphinxcontrib-httpdomain
diff --git a/greenwave/__init__.py b/greenwave/__init__.py
new file mode 100644
index 0000000..8490c3e
--- /dev/null
+++ b/greenwave/__init__.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of the Greenwave project.
+# Copyright (C) 2017 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+"""
+Greenwave is a web application built using `Flask`_ and `SQLAlchemy`_.
+
+It provides a :ref:`http-api` for applications to use.
+
+.. _Flask: http://flask.pocoo.org/
+.. _SQLAlchemy: http://sqlalchemy.org/
+"""
+
+__version__ = '0.1.0'
diff --git a/greenwave/tests/__init__.py b/greenwave/tests/__init__.py
new file mode 100644
index 0000000..b3e8c0f
--- /dev/null
+++ b/greenwave/tests/__init__.py
@@ -0,0 +1,54 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of the Greenwave project.
+# Copyright (C) 2017 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+"""
+Greenwave uses the Python `unittest`_ framework for unit tests.
+
+Patches should be accompanied by one or more tests to demonstrate the feature
+or bugfix works. This makes the review process much easier since it allows the
+reviewer to run your code with very little effort, and it lets developers know
+when they break your code.
+
+
+Running Tests
+=============
+
+Tests are run with `py.test`_ via `tox`_. You can run individual environments by
+using the ``-e`` flag. For example, ``tox -e lint`` runs the linter.
+
+
+Test Organization
+=================
+
+The test organization is as follows:
+
+1. Each module in the application has a corresponding test module. These
+   modules is organized in the test package to mirror the package they test.
+   That is, ``greenwave/app.py`` has a test module in located at
+   ``greenwave/tests/test_app.py``
+
+2. Within each test module, follow the unittest code organization guidelines.
+
+3. Include documentation blocks for each test case that explain the goal of the
+   test.
+
+
+.. _unittest: https://docs.python.org/3/library/unittest.html
+.. _py.test: https://docs.pytest.org/en/latest/
+.. _tox: https://tox.readthedocs.io/en/latest/
+"""
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..e39cea1
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,2 @@
+flask
+sqlalchemy
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..5f64370
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,113 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of the Greenwave project.
+# Copyright (C) 2017 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import os
+import re
+
+from setuptools import setup, find_packages
+
+
+here = os.path.abspath(os.path.dirname(__file__))
+with open(os.path.join(here, 'README.md')) as fd:
+    README = fd.read()
+
+
+def get_project_version(version_file='greenwave/__init__.py'):
+    """
+    Read the declared version of the project from the source code.
+
+    Args:
+        version_file: The file with the version string in it. The version must
+            be in the format ``__version__ = '<version>'`` and the file must be
+            UTF-8 encoded.
+    """
+    with open(version_file, "rb") as f:
+        version_pattern = b"^__version__ = '(.+)'$"
+        match = re.search(version_pattern, f.read(), re.MULTILINE)
+    if match is None:
+        err_msg = "No line matching  %r found in %r"
+        raise ValueError(err_msg % (version_pattern, version_file))
+    return match.groups()[0].decode("utf-8")
+
+
+def get_requirements(requirements_file='requirements.txt'):
+    """Get the contents of a file listing the requirements.
+
+    Args:
+        requirements_file (str): The path to the requirements file, relative
+                                 to this file.
+
+    Returns:
+        list: the list of requirements, or an empty list if
+              ``requirements_file`` could not be opened or read.
+    """
+    with open(requirements_file) as fd:
+        lines = fd.readlines()
+    dependencies = []
+    for line in lines:
+        maybe_dep = line.strip()
+        if maybe_dep.startswith('#'):
+            # Skip pure comment lines
+            continue
+        if maybe_dep.startswith('git+'):
+            # VCS reference for dev purposes, expect a trailing comment
+            # with the normal requirement
+            __, __, maybe_dep = maybe_dep.rpartition('#')
+        else:
+            # Ignore any trailing comment
+            maybe_dep, __, __ = maybe_dep.partition('#')
+        # Remove any whitespace and assume non-empty results are dependencies
+        maybe_dep = maybe_dep.strip()
+        if maybe_dep:
+            dependencies.append(maybe_dep)
+    return dependencies
+
+
+setup(
+    name='greenwave',
+    version=get_project_version(),
+    description=(
+        'Greenwave is a service to decide whether a software artifact can pass'
+        ' certain gating points in a software delivery pipeline'
+    ),
+    long_description=README,
+    # Possible options are at https://pypi.python.org/pypi?%3Aaction=list_classifiers
+    classifiers=[
+        'Development Status :: 1 - Planning',
+        'Framework :: Flask',
+        'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
+        'Operating System :: POSIX :: Linux',
+        'Programming Language :: Python :: 2.7',
+        'Programming Language :: Python :: 3',
+        'Programming Language :: Python :: 3.4',
+        'Programming Language :: Python :: 3.5',
+        'Programming Language :: Python :: 3.6',
+    ],
+    license='GPLv2+',
+    maintainer='Fedora Infrastructure Team',
+    maintainer_email='infrastructure@lists.fedoraproject.org',
+    platforms=['Fedora', 'GNU/Linux'],
+    url='https://pagure.io/greenwave/',
+    packages=find_packages(exclude=('greenwave.tests', 'greenwave.tests.*')),
+    include_package_data=True,
+    zip_safe=False,
+    install_requires=get_requirements(),
+    tests_require=get_requirements(requirements_file='dev-requirements.txt'),
+    test_suite='greenwave.tests',
+)

From 65174d6069353bdceebd232a5f6dea5f77ec810f Mon Sep 17 00:00:00 2001
From: Jeremy Cline <jeremy@jcline.org>
Date: May 10 2017 19:10:55 +0000
Subject: [PATCH 3/4] Setup tests and coverage configuration


Signed-off-by: Jeremy Cline <jeremy@jcline.org>

---

diff --git a/.coveragerc b/.coveragerc
new file mode 100644
index 0000000..c8a9dcf
--- /dev/null
+++ b/.coveragerc
@@ -0,0 +1,13 @@
+[run]
+branch = True
+include =
+    greenwave/*
+
+[report]
+fail_under = 100
+exclude_lines =
+    pragma: no cover
+    if __name__ == .__main__.:
+omit =
+    greenwave/tests/*
+
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..6079f6a
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,36 @@
+[tox]
+envlist = lint,py27,py34,py35,py36,docs
+# If the user is missing an interpreter, don't fail
+skip_missing_interpreters = True
+
+[testenv]
+deps =
+    -rrequirements.txt
+    -rdev-requirements.txt
+whitelist_externals =
+    rm
+commands =
+    rm -rf htmlcov coverage.xml
+    py.test --cov-config .coveragerc --cov=greenwave --cov-report term \
+        --cov-report xml --cov-report html
+
+[testenv:docs]
+changedir = docs
+whitelist_externals =
+    mkdir
+    rm
+commands=
+    mkdir -p _static
+    rm -rf _build/
+    sphinx-build -W -b html -d {envtmpdir}/doctrees .  _build/html
+
+[testenv:lint]
+deps =
+    flake8 > 3.0
+commands =
+    python -m flake8 {posargs}
+
+[flake8]
+show-source = True
+max-line-length = 100
+exclude = .git,.tox,dist,*egg

From adfe1e58482b9ca40b8856292059b3c8ce8af0d1 Mon Sep 17 00:00:00 2001
From: Jeremy Cline <jeremy@jcline.org>
Date: May 10 2017 19:11:15 +0000
Subject: [PATCH 4/4] Add a Sphinx project


Signed-off-by: Jeremy Cline <jeremy@jcline.org>

---

diff --git a/docs/Makefile b/docs/Makefile
new file mode 100644
index 0000000..e9941b5
--- /dev/null
+++ b/docs/Makefile
@@ -0,0 +1,20 @@
+# Minimal makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS    =
+SPHINXBUILD   = sphinx-build
+SPHINXPROJ    = Greenwave
+SOURCEDIR     = .
+BUILDDIR      = _build
+
+# Put it first so that "make" without argument is like "make help".
+help:
+	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+.PHONY: help Makefile
+
+# Catch-all target: route all unknown targets to Sphinx using the new
+# "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
+%: Makefile
+	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
\ No newline at end of file
diff --git a/docs/api.rst b/docs/api.rst
new file mode 100644
index 0000000..4e2488b
--- /dev/null
+++ b/docs/api.rst
@@ -0,0 +1,11 @@
+==============
+Greenwave APIs
+==============
+
+.. automodule:: greenwave
+
+
+.. _http-api:
+
+HTTP REST API
+=============
diff --git a/docs/conf.py b/docs/conf.py
new file mode 100644
index 0000000..5e920dc
--- /dev/null
+++ b/docs/conf.py
@@ -0,0 +1,185 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# Greenwave documentation build configuration file, created by
+# sphinx-quickstart on Wed May 10 13:18:15 2017.
+#
+# This file is execfile()d with the current directory set to its
+# containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#
+# import os
+# import sys
+# sys.path.insert(0, os.path.abspath('.'))
+import greenwave
+
+
+# -- General configuration ------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#
+needs_sphinx = '1.3'
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
+# ones.
+extensions = [
+    'sphinx.ext.autodoc',
+    'sphinx.ext.intersphinx',
+    'sphinx.ext.viewcode',
+    'sphinx.ext.napoleon',
+    'sphinxcontrib.autohttp.flask',
+]
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix(es) of source filenames.
+# You can specify multiple suffix as a list of string:
+#
+source_suffix = ['.rst', '.md']
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = 'Greenwave'
+copyright = '2017, Red Hat, Inc. and others'
+author = 'Red Hat, Inc. and others'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = '.'.join(greenwave.__version__.split('.')[:2])
+# The full version, including alpha/beta/rc tags.
+release = greenwave.__version__
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#
+# This is also used if you do content translation via gettext catalogs.
+# Usually you set "language" from the command line for these cases.
+language = None
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+# This patterns also effect to html_static_path and html_extra_path
+exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# If true, `todo` and `todoList` produce output, else they produce nothing.
+todo_include_todos = False
+
+
+# -- Options for HTML output ----------------------------------------------
+
+# The theme to use for HTML and HTML Help pages.  See the documentation for
+# a list of builtin themes.
+#
+html_theme = 'alabaster'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further.  For a list of options available for each theme, see the
+# documentation.
+#
+# html_theme_options = {}
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+
+# -- Options for HTMLHelp output ------------------------------------------
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'Greenwavedoc'
+
+
+# -- Options for LaTeX output ---------------------------------------------
+
+latex_elements = {
+    # The paper size ('letterpaper' or 'a4paper').
+    #
+    # 'papersize': 'letterpaper',
+
+    # The font size ('10pt', '11pt' or '12pt').
+    #
+    # 'pointsize': '10pt',
+
+    # Additional stuff for the LaTeX preamble.
+    #
+    # 'preamble': '',
+
+    # Latex figure (float) alignment
+    #
+    # 'figure_align': 'htbp',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title,
+#  author, documentclass [howto, manual, or own class]).
+latex_documents = [
+    (master_doc, 'Greenwave.tex', 'Greenwave Documentation',
+     'Red Hat, Inc. and others', 'manual'),
+]
+
+
+# -- Options for manual page output ---------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+    (master_doc, 'greenwave', 'Greenwave Documentation',
+     [author], 1)
+]
+
+
+# -- Options for Texinfo output -------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+#  dir menu entry, description, category)
+texinfo_documents = [
+    (master_doc, 'Greenwave', 'Greenwave Documentation',
+     author, 'Greenwave', 'One line description of project.',
+     'Miscellaneous'),
+]
+
+
+# -- Options for Epub output ----------------------------------------------
+
+# Bibliographic Dublin Core info.
+epub_title = project
+epub_author = author
+epub_publisher = author
+epub_copyright = copyright
+
+# The unique identifier of the text. This can be a ISBN number
+# or the project homepage.
+#
+# epub_identifier = ''
+
+# A unique identification for the text.
+#
+# epub_uid = ''
+
+# A list of files that should not be packed into the epub file.
+epub_exclude_files = ['search.html']
+
+
+# Example configuration for intersphinx: refer to the Python standard library.
+intersphinx_mapping = {'https://docs.python.org/': None}
diff --git a/docs/contributing.rst b/docs/contributing.rst
new file mode 100644
index 0000000..4fc92f0
--- /dev/null
+++ b/docs/contributing.rst
@@ -0,0 +1,45 @@
+=======================
+Contribution Guidelines
+=======================
+
+Please follow the following contribution guidelines when contributing a pull
+request.
+
+
+Code style
+==========
+
+We follow the `PEP 8`_ style guide for Python. The test suite includes a test
+that enforces the required style, so all you need to do is run the tests to
+ensure your code follows the style. If the unit test passes, you are good to go!
+
+
+Unit tests
+==========
+
+.. automodule:: greenwave.tests
+
+
+Documentation
+=============
+Greenwave uses `sphinx <http://www.sphinx-doc.org/>`_ to create its documentation.
+New packages, modules, classes, methods, functions, and attributes all should be
+documented using `"Google style" <http://www.sphinx-doc.org/en/latest/ext/example_google.html>`_
+docstrings.
+
+Python API documentation is automatically generated from the code using Sphinx's
+`autodoc <http://www.sphinx-doc.org/en/stable/tutorial.html#autodoc>`_ extension.
+HTTP REST API documentation is automatically generated from the code using the
+`httpdomain <http://pythonhosted.org/sphinxcontrib-httpdomain/>`_ extension.
+
+
+Development Environment
+=======================
+
+Set up a Python virtual environment and then install Greenwave::
+
+  $ pip install -r dev-requirements.txt
+  $ pip install -e .
+
+
+.. _PEP 8: https://www.python.org/dev/peps/pep-0008/
diff --git a/docs/index.rst b/docs/index.rst
new file mode 100644
index 0000000..7ae75b5
--- /dev/null
+++ b/docs/index.rst
@@ -0,0 +1,22 @@
+.. Greenwave documentation master file, created by
+   sphinx-quickstart on Wed May 10 13:18:15 2017.
+   You can adapt this file completely to your liking, but it should at least
+   contain the root `toctree` directive.
+
+Greenwave
+=========
+
+.. toctree::
+   :maxdepth: 2
+   :caption: Contents:
+
+   contributing
+   api
+
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`

