summaryrefslogtreecommitdiff
path: root/zuul/reporter
diff options
context:
space:
mode:
authorJoshua Hesketh <josh@nitrotech.org>2015-08-11 23:42:08 +1000
committerJoshua Hesketh <josh@nitrotech.org>2015-12-06 14:48:32 +1100
commit352264b3c22b501ae53c1643e31df2ccdfc89388 (patch)
treeac684e58d1b9ad9eb35b70614a3634d665f53f16 /zuul/reporter
parent70b13490a3f6fbed8e292337a2b3dd1533864ed3 (diff)
downloadzuul-352264b3c22b501ae53c1643e31df2ccdfc89388.tar.gz
Add support for 'connection' concept
This is a large refactor and as small as I could feasibly make it while keeping the tests working. I'll do the documentation and touch ups in the next commit to make digesting easier. Change-Id: Iac5083996a183d1d8a9b6cb8f70836f7c39ee910
Diffstat (limited to 'zuul/reporter')
-rw-r--r--zuul/reporter/__init__.py18
-rw-r--r--zuul/reporter/gerrit.py24
-rw-r--r--zuul/reporter/smtp.py55
3 files changed, 46 insertions, 51 deletions
diff --git a/zuul/reporter/__init__.py b/zuul/reporter/__init__.py
index a9df257bc..d9857daf1 100644
--- a/zuul/reporter/__init__.py
+++ b/zuul/reporter/__init__.py
@@ -24,19 +24,25 @@ class BaseReporter(object):
Defines the exact public methods that must be supplied.
"""
- @abc.abstractmethod
- def __init__(self, *args, **kwargs):
- # TODO(jhesketh): Fix *args to just a connection
- pass
+ def __init__(self, reporter_config={}, sched=None, connection=None):
+ self.reporter_config = reporter_config
+ self.sched = sched
+ self.connection = connection
+
+ def stop(self):
+ """Stop the reporter."""
@abc.abstractmethod
- def report(self, source, change, message, params):
+ def report(self, source, change, message):
"""Send the compiled report message."""
- def getSubmitAllowNeeds(self, params):
+ def getSubmitAllowNeeds(self):
"""Get a list of code review labels that are allowed to be
"needed" in the submit records for a change, with respect
to this queue. In other words, the list of review labels
this reporter itself is likely to set before submitting.
"""
return []
+
+ def postConfig(self):
+ """Run tasks after configuration is reloaded"""
diff --git a/zuul/reporter/gerrit.py b/zuul/reporter/gerrit.py
index f24c3b3c1..e1b05714a 100644
--- a/zuul/reporter/gerrit.py
+++ b/zuul/reporter/gerrit.py
@@ -13,6 +13,7 @@
# under the License.
import logging
+import voluptuous as v
from zuul.reporter import BaseReporter
@@ -24,25 +25,26 @@ class GerritReporter(BaseReporter):
name = 'gerrit'
log = logging.getLogger("zuul.reporter.gerrit.Reporter")
- def __init__(self, gerrit):
- """Set up the reporter."""
- # TODO: make default_gerrit come from a connection
- self.default_gerrit = gerrit
-
- def report(self, source, change, message, params):
+ def report(self, source, change, message):
"""Send a message to gerrit."""
self.log.debug("Report change %s, params %s, message: %s" %
- (change, params, message))
+ (change, self.reporter_config, message))
changeid = '%s,%s' % (change.number, change.patchset)
change._ref_sha = source.getRefSha(change.project.name,
'refs/heads/' + change.branch)
- return self.default_gerrit.review(
- change.project.name, changeid, message, params)
- def getSubmitAllowNeeds(self, params):
+ return self.connection.review(change.project.name, changeid, message,
+ self.reporter_config)
+
+ def getSubmitAllowNeeds(self):
"""Get a list of code review labels that are allowed to be
"needed" in the submit records for a change, with respect
to this queue. In other words, the list of review labels
this reporter itself is likely to set before submitting.
"""
- return params
+ return self.reporter_config
+
+
+def getSchema():
+ gerrit_reporter = v.Any(str, v.Schema({}, extra=True))
+ return gerrit_reporter
diff --git a/zuul/reporter/smtp.py b/zuul/reporter/smtp.py
index 2a3ed6a98..4daa6df38 100644
--- a/zuul/reporter/smtp.py
+++ b/zuul/reporter/smtp.py
@@ -13,9 +13,7 @@
# under the License.
import logging
-import smtplib
-
-from email.mime.text import MIMEText
+import voluptuous as v
from zuul.reporter import BaseReporter
@@ -26,40 +24,29 @@ class SMTPReporter(BaseReporter):
name = 'smtp'
log = logging.getLogger("zuul.reporter.smtp.Reporter")
- def __init__(self, smtp_default_from, smtp_default_to,
- smtp_server='localhost', smtp_port=25):
- """Set up the reporter.
-
- Takes parameters for the smtp server.
- """
- self.smtp_server = smtp_server
- self.smtp_port = smtp_port
- self.smtp_default_from = smtp_default_from
- self.smtp_default_to = smtp_default_to
-
- def report(self, source, change, message, params):
+ def report(self, source, change, message):
"""Send the compiled report message via smtp."""
self.log.debug("Report change %s, params %s, message: %s" %
- (change, params, message))
+ (change, self.reporter_config, message))
- # Create a text/plain email message
- from_email = params['from']\
- if 'from' in params else self.smtp_default_from
- to_email = params['to']\
- if 'to' in params else self.smtp_default_to
- msg = MIMEText(message)
- if 'subject' in params:
- subject = params['subject'].format(change=change)
+ from_email = self.reporter_config['from'] \
+ if 'from' in self.reporter_config else None
+ to_email = self.reporter_config['to'] \
+ if 'to' in self.reporter_config else None
+
+ if 'subject' in self.reporter_config:
+ subject = self.reporter_config['subject'].format(change=change)
else:
subject = "Report for change %s" % change
- msg['Subject'] = subject
- msg['From'] = from_email
- msg['To'] = to_email
- try:
- s = smtplib.SMTP(self.smtp_server, self.smtp_port)
- s.sendmail(from_email, to_email.split(','), msg.as_string())
- s.quit()
- except:
- return "Could not send email via SMTP"
- return
+ self.connection.sendMail(subject, message, from_email, to_email)
+
+
+def getSchema():
+ smtp_reporter = v.Schema({
+ 'connection': str,
+ 'to': str,
+ 'from': str,
+ 'subject': str,
+ })
+ return smtp_reporter