summaryrefslogtreecommitdiff
path: root/zuul
diff options
context:
space:
mode:
authorWayne <wayne@puppetlabs.com>2015-06-12 16:56:30 -0700
committerJesse Keating <omgjlk@us.ibm.com>2017-05-02 08:19:50 -0700
commit40f4004425fb9fe921fd4b0a5cb653caf216d12d (patch)
tree277d9ac9be7c6e224868cdf6ef1dd4afe316a2db /zuul
parent4fc12549072d02b97fa46ab36b4618f320ce507f (diff)
downloadzuul-40f4004425fb9fe921fd4b0a5cb653caf216d12d.tar.gz
Add basic Github Zuul Reporter.
Change-Id: I3c34bb1354adb7c360e173c227f00bf987b7d30e Co-Authored-By: Jan Hruban <jan.hruban@gooddata.com>
Diffstat (limited to 'zuul')
-rw-r--r--zuul/driver/github/__init__.py7
-rw-r--r--zuul/driver/github/githubconnection.py8
-rw-r--r--zuul/driver/github/githubreporter.py38
3 files changed, 52 insertions, 1 deletions
diff --git a/zuul/driver/github/__init__.py b/zuul/driver/github/__init__.py
index af29b62d7..4e54f11d7 100644
--- a/zuul/driver/github/__init__.py
+++ b/zuul/driver/github/__init__.py
@@ -17,6 +17,7 @@ from zuul.driver import SourceInterface
import githubconnection
import githubtrigger
import githubsource
+import githubreporter
class GithubDriver(Driver, ConnectionInterface, TriggerInterface,
@@ -32,5 +33,11 @@ class GithubDriver(Driver, ConnectionInterface, TriggerInterface,
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 3878949f0..db1279982 100644
--- a/zuul/driver/github/githubconnection.py
+++ b/zuul/driver/github/githubconnection.py
@@ -164,7 +164,7 @@ class GithubConnection(BaseConnection):
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 @@ class GithubConnection(BaseConnection):
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 000000000..685c60e8d
--- /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