Repository: buildbot/buildbot

Issue:
fix case of "GitHub" in "GithubStatusPush"
As discussed at today's meeting



Discussion:

Resolving patch:
diff --git a/master/buildbot/status/mail.py b/master/buildbot/status/mail.py
--- a/master/buildbot/status/mail.py
+++ b/master/buildbot/status/mail.py
@@ -49,7 +49,7 @@
 from buildbot import interfaces, util, config
 from buildbot.process.users import users
 from buildbot.status import base
-from buildbot.status.results import FAILURE, SUCCESS, WARNINGS, Results
+from buildbot.status.results import FAILURE, SUCCESS, WARNINGS, EXCEPTION, Results
 
 VALID_EMAIL = re.compile("[a-zA-Z0-9\.\_\%\-\+]+@[a-zA-Z0-9\.\_\%\-]+.[a-zA-Z]{2,6}")
 
@@ -92,6 +92,8 @@ def defaultMessage(mode, name, build, results, master_status):
             text += "The Buildbot has detected a restored build"
         else:
             text += "The Buildbot has detected a passing build"
+    elif results == EXCEPTION:
+        text += "The Buildbot has detected a build exception"
 
     projects = []
     if ss_list:
@@ -177,7 +179,7 @@ class MailNotifier(base.StatusReceiverMultiService):
                      "subject", "sendToInterestedUsers", "customMesg",
                      "messageFormatter", "extraHeaders"]
 
-    possible_modes = ("change", "failing", "passing", "problem", "warnings")
+    possible_modes = ("change", "failing", "passing", "problem", "warnings", "exception")
 
     def __init__(self, fromaddr, mode=("failing", "passing", "warnings"),
                  categories=None, builders=None, addLogs=False,
@@ -220,6 +222,8 @@ def __init__(self, fromaddr, mode=("failing", "passing", "warnings"),
                      - "problem": send mail about a build which failed
                                   when the previous build passed
                      - "warnings": send mail if a build contain warnings
+                     - "exception": send mail if a build fails due to an exception
+                     - "all": always send mail
                      Defaults to ("failing", "passing", "warnings").
 
         @type  builders: list of strings
@@ -316,7 +320,7 @@ def __init__(self, fromaddr, mode=("failing", "passing", "warnings"),
         self.fromaddr = fromaddr
         if isinstance(mode, basestring):
             if mode == "all":
-                mode = ("failing", "passing", "warnings")
+                mode = ("failing", "passing", "warnings", "exception")
             elif mode == "warnings":
                 mode = ("failing", "warnings")
             else:
@@ -434,6 +438,8 @@ def isMailNeeded(self, build, results):
                 return True
         if "warnings" in self.mode and results == WARNINGS:
             return True
+        if "exception" in self.mode and results == EXCEPTION:
+            return True
 
         return False
 


Test patch:
diff --git a/master/buildbot/test/unit/test_status_mail.py b/master/buildbot/test/unit/test_status_mail.py
--- a/master/buildbot/test/unit/test_status_mail.py
+++ b/master/buildbot/test/unit/test_status_mail.py
@@ -17,7 +17,7 @@
 from mock import Mock
 from buildbot import config
 from twisted.trial import unittest
-from buildbot.status.results import SUCCESS, FAILURE
+from buildbot.status.results import SUCCESS, FAILURE, WARNINGS, EXCEPTION
 from buildbot.status.mail import MailNotifier
 from twisted.internet import defer
 from buildbot.test.fake import fakedb
@@ -440,15 +440,70 @@ def test_buildFinished_ignores_unspecified_categories(self):
 
         self.assertEqual(None, mn.buildFinished('dummyBuilder', build, SUCCESS))
 
-    def test_buildFinished_mode_all_always_sends_email(self):
+    def run_simple_test_sends_email_for_mode(self, mode, result):
         mock_method = Mock()
         self.patch(MailNotifier, "buildMessage", mock_method)
-        mn = MailNotifier('from@example.org', mode=("failing", "passing", "warnings"))
+        mn = MailNotifier('from@example.org', mode=mode)
 
         build = FakeBuildStatus(name="build")
-        mn.buildFinished('dummyBuilder', build, FAILURE)
+        mn.buildFinished('dummyBuilder', build, result)
 
-        mock_method.assert_called_with('dummyBuilder', [build], FAILURE)
+        mock_method.assert_called_with('dummyBuilder', [build], result)
+
+    def run_simple_test_ignores_email_for_mode(self, mode, result):
+        mock_method = Mock()
+        self.patch(MailNotifier, "buildMessage", mock_method)
+        mn = MailNotifier('from@example.org', mode=mode)
+
+        build = FakeBuildStatus(name="build")
+        mn.buildFinished('dummyBuilder', build, result)
+
+        self.assertFalse(mock_method.called)
+
+    def test_buildFinished_mode_all_for_success(self):
+        self.run_simple_test_sends_email_for_mode("all", SUCCESS)
+    def test_buildFinished_mode_all_for_failure(self):
+        self.run_simple_test_sends_email_for_mode("all", FAILURE)
+    def test_buildFinished_mode_all_for_warnings(self):
+        self.run_simple_test_sends_email_for_mode("all", WARNINGS)
+    def test_buildFinished_mode_all_for_exception(self):
+        self.run_simple_test_sends_email_for_mode("all", EXCEPTION)
+
+    def test_buildFinished_mode_failing_for_success(self):
+        self.run_simple_test_ignores_email_for_mode("failing", SUCCESS)
+    def test_buildFinished_mode_failing_for_failure(self):
+        self.run_simple_test_sends_email_for_mode("failing", FAILURE)
+    def test_buildFinished_mode_failing_for_warnings(self):
+        self.run_simple_test_ignores_email_for_mode("failing", WARNINGS)
+    def test_buildFinished_mode_failing_for_exception(self):
+        self.run_simple_test_ignores_email_for_mode("failing", EXCEPTION)
+
+    def test_buildFinished_mode_exception_for_success(self):
+        self.run_simple_test_ignores_email_for_mode("exception", SUCCESS)
+    def test_buildFinished_mode_exception_for_failure(self):
+        self.run_simple_test_ignores_email_for_mode("exception", FAILURE)
+    def test_buildFinished_mode_exception_for_warnings(self):
+        self.run_simple_test_ignores_email_for_mode("exception", WARNINGS)
+    def test_buildFinished_mode_exception_for_exception(self):
+        self.run_simple_test_sends_email_for_mode("exception", EXCEPTION)
+
+    def test_buildFinished_mode_warnings_for_success(self):
+        self.run_simple_test_ignores_email_for_mode("warnings", SUCCESS)
+    def test_buildFinished_mode_warnings_for_failure(self):
+        self.run_simple_test_sends_email_for_mode("warnings", FAILURE)
+    def test_buildFinished_mode_warnings_for_warnings(self):
+        self.run_simple_test_sends_email_for_mode("warnings", WARNINGS)
+    def test_buildFinished_mode_warnings_for_exception(self):
+        self.run_simple_test_ignores_email_for_mode("warnings", EXCEPTION)
+
+    def test_buildFinished_mode_passing_for_success(self):
+        self.run_simple_test_sends_email_for_mode("passing", SUCCESS)
+    def test_buildFinished_mode_passing_for_failure(self):
+        self.run_simple_test_ignores_email_for_mode("passing", FAILURE)
+    def test_buildFinished_mode_passing_for_warnings(self):
+        self.run_simple_test_ignores_email_for_mode("passing", WARNINGS)
+    def test_buildFinished_mode_passing_for_exception(self):
+        self.run_simple_test_ignores_email_for_mode("passing", EXCEPTION)
 
     def test_buildFinished_mode_failing_ignores_successful_build(self):
         mn = MailNotifier('from@example.org', mode=("failing",))