Skip to content

Commit 01697cb

Browse files
d-fenceXavier-Do
authored andcommitted
[IMP] runbot: stop notifying when an error is fixed
When an error is assigned to a user, a notification is sent to the user, even if the error is not active. So it happens when we want to mark an error as fixed and add the fixing informations at the same time (e.g.: the fixing PR, the user that fixed ...).
1 parent 1a661a0 commit 01697cb

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

runbot/models/build_error.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,10 @@ def write(self, vals):
507507
if not vals['active'] and build_error.active and build_error.last_seen_date and build_error.last_seen_date + relativedelta(days=1) > datetime.datetime.now():
508508
raise UserError("This error broke less than one day ago can only be deactivated by admin")
509509

510-
if (responsible_id := vals.get('responsible')):
510+
if (responsible_id := vals.get('responsible')) and vals.get('active', True):
511511
responsible = self.env['res.users'].browse(responsible_id)
512512
for build_error in self:
513-
if responsible != self.env.user:
513+
if build_error.active and responsible != self.env.user:
514514
_logger.info('Notifying responsible %s of build error %s', responsible.name, build_error.id)
515515
build_error.message_notify(
516516
body=f'Error {build_error.id} was assigned to you by {self.env.user.name}',

runbot/tests/test_build_error.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import hashlib
2+
from unittest.mock import patch
23

34
from odoo import fields
45
from odoo.exceptions import ValidationError
6+
from odoo.tests import new_test_user
7+
58
from .common import RunbotCase
69

710
RTE_ERROR = """FAIL: TestUiTranslate.test_admin_tour_rte_translator
@@ -684,6 +687,31 @@ def test_dashboard_tile_simple(self):
684687

685688
self.assertEqual(dashboard.build_ids, failed_build)
686689

690+
def test_build_error_notification(self):
691+
self.stop_patcher('isfile') # prevent user creation
692+
responsible = new_test_user(self.env, login='fixman', name='fixman', password='fixpass')
693+
694+
# check that a message is sent when an error is assigned to someone
695+
error = self.BuildError.create({})
696+
with patch.object(self.env.registry['runbot.build.error'], 'message_notify') as message_notify:
697+
error.responsible = responsible
698+
message_notify.assert_called()
699+
700+
# check that a message is NOT sent when an error disabled AND assigned to someone
701+
fixed_error = self.BuildError.create({})
702+
with patch.object(self.env.registry['runbot.build.error'], 'message_notify') as message_notify:
703+
fixed_error.write({
704+
'responsible': responsible.id,
705+
'active': False,
706+
})
707+
message_notify.assert_not_called()
708+
709+
# Finally check that a message is not sent when adding a responsible on an already fixed error
710+
innactive_error = self.BuildError.create({'active': False})
711+
with patch.object(self.env.registry['runbot.build.error'], 'message_notify') as message_notify:
712+
innactive_error.responsible = responsible
713+
message_notify.assert_not_called()
714+
687715

688716
class TestErrorMerge(TestBuildErrorCommon):
689717

0 commit comments

Comments
 (0)