Skip to content

Commit

Permalink
broke out _defaultMessageSourceStamps()
Browse files Browse the repository at this point in the history
Broke out code for generating source stamps info for build result
email from buildbot.status.mail.defaultMessage() function into a
new function.
  • Loading branch information
Elmir Jagudin committed Jan 6, 2014
1 parent fd8c2fe commit e7bed9f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 18 deletions.
45 changes: 27 additions & 18 deletions master/buildbot/status/mail.py
Expand Up @@ -127,6 +127,32 @@ def _defaultMessageProjects(source_stamps, master_status):
return ', '.join(projects)


def _defaultMessageSourceStamps(source_stamps):
text = ""

for ss in source_stamps:
source = ""

if ss.branch:
source += "[branch %s] " % ss.branch

if ss.revision:
source += str(ss.revision)
else:
source += "HEAD"

if ss.patch:
source += " (plus patch)"

discriminator = ""
if ss.codebase:
discriminator = " '%s'" % ss.codebase

text += "Build Source Stamp%s: %s\n" % (discriminator, source)

return text


def defaultMessage(mode, name, build, results, master_status):
"""Generate a buildbot mail message and return a tuple of message text
and type."""
Expand All @@ -145,25 +171,8 @@ def defaultMessage(mode, name, build, results, master_status):

text += "Buildslave for this Build: %s\n\n" % build.getSlavename()
text += "Build Reason: %s\n" % build.getReason()

for ss in ss_list:
source = ""
if ss and ss.branch:
source += "[branch %s] " % ss.branch
if ss and ss.revision:
source += str(ss.revision)
else:
source += "HEAD"
if ss and ss.patch:
source += " (plus patch)"

discriminator = ""
if ss.codebase:
discriminator = " '%s'" % ss.codebase
text += "Build Source Stamp%s: %s\n" % (discriminator, source)

text += _defaultMessageSourceStamps(ss_list)
text += "Blamelist: %s\n" % ",".join(build.getResponsibleUsers())

text += "\n"

t = build.getText()
Expand Down
39 changes: 39 additions & 0 deletions master/buildbot/test/unit/test_status_mail.py
Expand Up @@ -985,3 +985,42 @@ def testMultiSourceStampsProject(self):
source_stamp2,
source_stamp3],
Mock()))


# Test buildbot.status.mail._defaultMessageSourceStamps() function
class TestDefaultMessageSourceStamps(unittest.TestCase):

# utility function to create mocked source stamp object
def setUpSourceStamp(self, branch=None, revision=None, patch=None,
codebase=""):

source_stamp = Mock()
source_stamp.branch = branch
source_stamp.revision = revision
source_stamp.patch = patch
source_stamp.codebase = codebase

return source_stamp

# test the case where build does not have any source stamps
def testNoSourceStamps(self):
self.assertEqual(mail._defaultMessageSourceStamps([]), "")

# test the case with one single minimal source stamp
def testOneSourceStamp(self):
source_stamp = self.setUpSourceStamp()

self.assertEqual("Build Source Stamp: HEAD\n",
mail._defaultMessageSourceStamps([source_stamp]))

# test the case with multiple source stamps, with branches, revisions,
# patch and codebase specifications
def testMultipleSourceStamps(self):
sstamp1 = self.setUpSourceStamp(branch="branch1", revision="rev1")
sstamp2 = self.setUpSourceStamp(branch="branch2", revision="rev2",
patch="dummy", codebase="base1")

self.assertEqual("Build Source Stamp: [branch branch1] rev1\n"
"Build Source Stamp 'base1': [branch branch2] rev2 "
"(plus patch)\n",
mail._defaultMessageSourceStamps([sstamp1, sstamp2]))

0 comments on commit e7bed9f

Please sign in to comment.