Add basic Github Zuul Reporter.

Change-Id: I3c34bb1354adb7c360e173c227f00bf987b7d30e
Co-Authored-By: Jan Hruban <jan.hruban@gooddata.com>
diff --git a/doc/source/reporters.rst b/doc/source/reporters.rst
index b01c8d1..4972e66 100644
--- a/doc/source/reporters.rst
+++ b/doc/source/reporters.rst
@@ -28,6 +28,12 @@
 A :ref:`connection` that uses the gerrit driver must be supplied to the
 trigger.
 
+GitHub
+------
+
+Zuul reports back to GitHub pull requests via GitHub API.
+It will create a comment containing the job status.
+
 SMTP
 ----
 
diff --git a/tests/base.py b/tests/base.py
index e33b510..d6304d7 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -693,6 +693,10 @@
         # just returns master for now
         return ['master']
 
+    def report(self, project, pr_number, message, params=None):
+        pull_request = self.pull_requests[pr_number - 1]
+        pull_request.addComment(message)
+
 
 class BuildHistory(object):
     def __init__(self, **kw):
diff --git a/tests/fixtures/layouts/basic-github.yaml b/tests/fixtures/layouts/basic-github.yaml
index 79d416a..f10fa6b 100644
--- a/tests/fixtures/layouts/basic-github.yaml
+++ b/tests/fixtures/layouts/basic-github.yaml
@@ -8,6 +8,10 @@
             - opened
             - changed
             - reopened
+    success:
+      github: {}
+    failure:
+      github: {}
 
 - job:
     name: project-test1
diff --git a/tests/unit/test_github_driver.py b/tests/unit/test_github_driver.py
index 58f456f..430cab3 100644
--- a/tests/unit/test_github_driver.py
+++ b/tests/unit/test_github_driver.py
@@ -50,3 +50,4 @@
         zuulvars = job.parameters['vars']['zuul']
         self.assertEqual(pr.number, zuulvars['change'])
         self.assertEqual(pr.head_sha, zuulvars['patchset'])
+        self.assertEqual(1, len(pr.comments))
diff --git a/zuul/driver/github/__init__.py b/zuul/driver/github/__init__.py
index af29b62..4e54f11 100644
--- a/zuul/driver/github/__init__.py
+++ b/zuul/driver/github/__init__.py
@@ -17,6 +17,7 @@
 import githubconnection
 import githubtrigger
 import githubsource
+import githubreporter
 
 
 class GithubDriver(Driver, ConnectionInterface, TriggerInterface,
@@ -32,5 +33,11 @@
     def getSource(self, connection):
         return githubsource.GithubSource(self, connection)
 
+    def getReporter(self, connection, config=None):
+        return githubreporter.GithubReporter(self, connection)
+
     def getTriggerSchema(self):
         return githubtrigger.getSchema()
+
+    def getReporterSchema(self):
+        return githubreporter.getSchema()
diff --git a/zuul/driver/github/githubconnection.py b/zuul/driver/github/githubconnection.py
index 3878949..db12799 100644
--- a/zuul/driver/github/githubconnection.py
+++ b/zuul/driver/github/githubconnection.py
@@ -164,7 +164,7 @@
     def _authenticateGithubAPI(self):
         token = self.connection_config.get('api_token', None)
         if token is not None:
-            self.github = github3.login(token)
+            self.github = github3.login(token=token)
             self.log.info("Github API Authentication successful.")
         else:
             self.github = None
@@ -219,6 +219,12 @@
     def getPullUrl(self, project, number):
         return '%s/pull/%s' % (self.getGitwebUrl(project), number)
 
+    def report(self, project, pr_number, message):
+        owner, proj = project.name.split('/')
+        repository = self.github.repository(owner, proj)
+        pull_request = repository.issue(pr_number)
+        pull_request.create_comment(message)
+
     def _ghTimestampToDate(self, timestamp):
         return time.strptime(timestamp, '%Y-%m-%dT%H:%M:%SZ')
 
diff --git a/zuul/driver/github/githubreporter.py b/zuul/driver/github/githubreporter.py
new file mode 100644
index 0000000..685c60e
--- /dev/null
+++ b/zuul/driver/github/githubreporter.py
@@ -0,0 +1,38 @@
+# Copyright 2015 Puppet Labs
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import logging
+import voluptuous as v
+
+from zuul.reporter import BaseReporter
+
+
+class GithubReporter(BaseReporter):
+    """Sends off reports to Github."""
+
+    name = 'github'
+    log = logging.getLogger("zuul.GithubReporter")
+
+    def report(self, source, pipeline, item):
+        """Comment on PR with test status."""
+        message = self._formatItemReport(pipeline, item)
+        project = item.change.project.name
+        pr_number = item.change.number
+
+        self.connection.report(project, pr_number, message)
+
+
+def getSchema():
+    github_reporter = v.Any(str, v.Schema({}, extra=True))
+    return github_reporter