diff --git a/runbot/models/event.py b/runbot/models/event.py index c0243b0c..97f4e611 100644 --- a/runbot/models/event.py +++ b/runbot/models/event.py @@ -15,6 +15,7 @@ class runbot_event(models.Model): _order = 'id' build_id = fields.Many2one('runbot.build', 'Build', index=True, ondelete='cascade') + active_step_id = fields.Many2one('runbot.build.config.step', 'Active step', index=True) type = fields.Selection(TYPES, string='Type', required=True, index=True) @api.model_cr @@ -28,6 +29,7 @@ CREATE OR REPLACE FUNCTION runbot_set_logging_build() RETURNS TRIGGER AS $runbot BEGIN IF (NEW.build_id IS NULL AND NEW.dbname IS NOT NULL AND NEW.dbname != current_database()) THEN NEW.build_id := split_part(NEW.dbname, '-', 1)::integer; + SELECT active_step INTO NEW.active_step_id FROM runbot_build WHERE runbot_build.id = NEW.build_id; END IF; IF (NEW.build_id IS NOT NULL) AND (NEW.type = 'server') THEN DECLARE diff --git a/runbot/tests/test_event.py b/runbot/tests/test_event.py index 72353531..9001b9e9 100644 --- a/runbot/tests/test_event.py +++ b/runbot/tests/test_event.py @@ -33,6 +33,7 @@ class TestIrLogging(common.TransactionCase): 'branch_id': self.branch.id, 'name': 'd0d0caca0000ffffffffffffffffffffffffffff', 'port': '1234', + 'active_step': self.env.ref('runbot.runbot_build_config_step_test_all').id, }) build.log_counter = 10 @@ -42,6 +43,7 @@ class TestIrLogging(common.TransactionCase): log_line = self.IrLogging.search([('func', '=', 'test function'), ('message', '=', 'test message'), ('level', '=', 'INFO')]) self.assertEqual(len(log_line), 1, "A build log event should have been created") self.assertEqual(log_line.build_id, build) + self.assertEqual(log_line.active_step_id, self.env.ref('runbot.runbot_build_config_step_test_all'), 'The active step should be set on the log line') # Test that a warn log line sets the build in warn self.simulate_log(build, 'test function', 'test message', level='WARNING')