Fix default merge failure reports

Commit 385d11e2ed moved the logic
that performs report formatting into the reporters themselves.  But
it also contained a logic change to the formatting.

Previously, if an item was not mergeable, it was reported without
a job list, regardless if the merge-failure or standard failure
reporter was used.  With that change, if a pipeline specified a
merge-failure message reporter, it would not format the job list,
but if no merge-failure reporter was supplied, and the standard
failure reporter was used, the standard failure reporter would not
check whether a merge-failure happened and instead always try to
format the job list.

Change-Id: If65d4f64d6558a544d3d0c2cc0b32ad7786a6bcd
changes/58/277958/1
James E. Blair 2016-02-09 08:44:52 -08:00
parent 52a249718e
commit f760f0e49f
2 changed files with 27 additions and 0 deletions

View File

@ -3477,6 +3477,31 @@ For CI problems and help debugging, contact ci@example.org"""
self.assertEqual('The merge failed! For more information...',
self.smtp_messages[0]['body'])
def test_default_merge_failure_reports(self):
"""Check that the default merge failure reports are correct."""
# A should report success, B should report merge failure.
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
A.addPatchset(['conflict'])
B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
B.addPatchset(['conflict'])
A.addApproval('CRVW', 2)
B.addApproval('CRVW', 2)
self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
self.waitUntilSettled()
self.assertEqual(3, len(self.history)) # A jobs
self.assertEqual(A.reported, 2)
self.assertEqual(B.reported, 2)
self.assertEqual(A.data['status'], 'MERGED')
self.assertEqual(B.data['status'], 'NEW')
self.assertIn('Build succeeded', A.messages[1])
self.assertIn('Merge Failed', B.messages[1])
self.assertIn('automatically merged', B.messages[1])
self.assertNotIn('logs.example.com', B.messages[1])
self.assertNotIn('SKIPPED', B.messages[1])
def test_swift_instructions(self):
"Test that the correct swift instructions are sent to the workers"
self.config.set('zuul', 'layout_config',

View File

@ -84,6 +84,8 @@ class BaseReporter(object):
def _formatItemReportFailure(self, pipeline, item):
if item.dequeued_needing_change:
msg = 'This change depends on a change that failed to merge.\n'
elif not pipeline.didMergerSucceed(item):
msg = pipeline.merge_failure_message
else:
msg = (pipeline.failure_message + '\n\n' +
self._formatItemReportJobs(pipeline, item))