<commit_before>from twisted.internet import defer
from buildbot.status import mail
from buildbot.status.results import FAILURE, SUCCESS, WARNINGS, EXCEPTION, Results

from ..factories import TravisSpawnerFactory
from ..travisyml import TravisYml, TravisYmlInvalid


class MailNotifier(mail.MailNotifier):

    def getConfiguration(self, build):
        for step in build.getSteps():
            for log in step.getLogs():
                if log.getName() != '.travis.yml':
                    continue

                config = TravisYml()
                config.parse(log.getText())
                return config
        raise TravisYmlInvalid("No configuration found in branch")

    def isMailNeeded(self, build, results):
        builder = build.getBuilder()
        builder_config = filter(lambda b: b.name == builder.name, self.master.config.builders)[0]

        # This notifier will only generate emails for the "spawner" builds
        if not isinstance(builder_config.factory, TravisSpawnerFactory):
            return False

        # That have valid configuration
        try:
            config = self.getConfiguration(build)
        except TravisYmlInvalid:
            return False

        # And emails are enabled
        if not config.email.enabled:
            return False

        def decide(config):
            if config == "never":
                return False
            elif config == "always":
                return True
            elif config == "change":
                prev = build.getPreviousBuild()
                return prev.getResults() != results

        if results == SUCCESS:
            decide(config.email.success)
        else:
            decide(config.email.failure)

        return False

    def getTravisAddresses(self, build):
        config = self.getConfiguration(build)
        return config.email.addresses

    @defer.inlineCallbacks
    def useLookup(self, build):
        recipients = self.getTravisAddresses(build)
        if not recipients:
            recipients = yield mail.MailNotifier.useLookup(self, build)
        defer.returnValue(recipients)

    @defer.inlineCallbacks
    def useUsers(self, build):
        recipients = self.getTravisAddresses(build)
        if not recipients:
            recipients = yield mail.MailNotifier.useUsers(self, build)
        defer.returnValue(recipients)

<commit_msg>Fix whether or not to send email<commit_after>from twisted.internet import defer
from buildbot.status import mail
from buildbot.status.results import FAILURE, SUCCESS, WARNINGS, EXCEPTION, Results

from ..factories import TravisSpawnerFactory
from ..travisyml import TravisYml, TravisYmlInvalid


class MailNotifier(mail.MailNotifier):

    def getConfiguration(self, build):
        for step in build.getSteps():
            for log in step.getLogs():
                if log.getName() != '.travis.yml':
                    continue

                config = TravisYml()
                config.parse(log.getText())
                return config
        raise TravisYmlInvalid("No configuration found in branch")

    def isMailNeeded(self, build, results):
        builder = build.getBuilder()
        builder_config = filter(lambda b: b.name == builder.name, self.master.config.builders)[0]

        # This notifier will only generate emails for the "spawner" builds
        if not isinstance(builder_config.factory, TravisSpawnerFactory):
            return False

        # That have valid configuration
        try:
            config = self.getConfiguration(build)
        except TravisYmlInvalid:
            return False

        # And emails are enabled
        if not config.email.enabled:
            return False

        def decide(config):
            if config == "never":
                return False
            elif config == "always":
                return True
            elif config == "change":
                prev = build.getPreviousBuild()
                return prev.getResults() != results
            return False

        if results == SUCCESS:
            return decide(config.email.success)
        return decide(config.email.failure)

    def getTravisAddresses(self, build):
        config = self.getConfiguration(build)
        return config.email.addresses

    @defer.inlineCallbacks
    def useLookup(self, build):
        recipients = self.getTravisAddresses(build)
        if not recipients:
            recipients = yield mail.MailNotifier.useLookup(self, build)
        defer.returnValue(recipients)

    @defer.inlineCallbacks
    def useUsers(self, build):
        recipients = self.getTravisAddresses(build)
        if not recipients:
            recipients = yield mail.MailNotifier.useUsers(self, build)
        defer.returnValue(recipients)


{'fraction_non_alphanumeric': 0.07790844183116338, 'fraction_numerical': 0.00041999160016799666, 'mean_word_length': 2.181696726786907, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3284782', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1189, 'n_words': 335}