mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00
[IMP] runbot: add config_data to triggers
Adds support for config_data directly on the triggers. This will be used to share configs between triggers with different parameters.
This commit is contained in:
parent
db40e1b8c0
commit
98d0804b6e
@ -372,7 +372,7 @@ class Batch(models.Model):
|
|||||||
# in any case, search for an existing build
|
# in any case, search for an existing build
|
||||||
config = trigger_custom.config_id or trigger.config_id
|
config = trigger_custom.config_id or trigger.config_id
|
||||||
extra_params = trigger_custom.extra_params or ''
|
extra_params = trigger_custom.extra_params or ''
|
||||||
config_data = trigger_custom.config_data or {}
|
config_data = dict(trigger.config_data or {}) | dict(trigger_custom.config_data or {})
|
||||||
params_value = {
|
params_value = {
|
||||||
'version_id': version_id,
|
'version_id': version_id,
|
||||||
'extra_params': extra_params,
|
'extra_params': extra_params,
|
||||||
|
@ -14,6 +14,7 @@ from pathlib import Path
|
|||||||
from odoo import models, fields, api
|
from odoo import models, fields, api
|
||||||
from odoo.tools import file_open, mail
|
from odoo.tools import file_open, mail
|
||||||
from ..common import os, RunbotException, make_github_session, sanitize
|
from ..common import os, RunbotException, make_github_session, sanitize
|
||||||
|
from ..fields import JsonDictField
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
from odoo.tools.safe_eval import safe_eval
|
from odoo.tools.safe_eval import safe_eval
|
||||||
|
|
||||||
@ -70,6 +71,7 @@ class Trigger(models.Model):
|
|||||||
)
|
)
|
||||||
module_filters = fields.One2many('runbot.module.filter', 'trigger_id', string="Module filters", help='Will be combined with repo module filters when used with this trigger')
|
module_filters = fields.One2many('runbot.module.filter', 'trigger_id', string="Module filters", help='Will be combined with repo module filters when used with this trigger')
|
||||||
config_id = fields.Many2one('runbot.build.config', string="Config", required=True)
|
config_id = fields.Many2one('runbot.build.config', string="Config", required=True)
|
||||||
|
config_data = JsonDictField('Config Data')
|
||||||
batch_dependent = fields.Boolean('Batch Dependent', help="Force adding batch in build parameters to make it unique and give access to bundle")
|
batch_dependent = fields.Boolean('Batch Dependent', help="Force adding batch in build parameters to make it unique and give access to bundle")
|
||||||
|
|
||||||
ci_context = fields.Char("CI context", tracking=True)
|
ci_context = fields.Char("CI context", tracking=True)
|
||||||
|
@ -181,6 +181,64 @@ class TestBuildParams(RunbotCaseMinimalSetup):
|
|||||||
batch._process()
|
batch._process()
|
||||||
self.assertEqual(batch.state, 'done')
|
self.assertEqual(batch.state, 'done')
|
||||||
|
|
||||||
|
def test_trigger_config_data(self):
|
||||||
|
"""Test that a config_data on the trigger is given to the build"""
|
||||||
|
self.additionnal_setup()
|
||||||
|
self.start_patchers()
|
||||||
|
|
||||||
|
# A commit is found on the dev remote
|
||||||
|
branch_a_name = 'master-test-something'
|
||||||
|
self.push_commit(self.remote_server_dev, branch_a_name, 'nice subject', sha='d0d0caca')
|
||||||
|
# batch preparation
|
||||||
|
self.repo_server.project_id.process_delay = 10
|
||||||
|
self.repo_server._update_batches()
|
||||||
|
|
||||||
|
# set config data on the trigger
|
||||||
|
self.trigger_server.config_data = {'moc_var': 'bar'}
|
||||||
|
|
||||||
|
# create a custom trigger for the bundle
|
||||||
|
bundle = self.Bundle.search([('name', '=', branch_a_name), ('project_id', '=', self.project.id)])
|
||||||
|
|
||||||
|
self.repo_server.project_id.process_delay = 0
|
||||||
|
bundle.last_batch._process()
|
||||||
|
build_slot = bundle.last_batch.slot_ids.filtered(lambda rec: rec.trigger_id == self.trigger_server)
|
||||||
|
self.assertIn(
|
||||||
|
'moc_var', build_slot.params_id.config_data
|
||||||
|
)
|
||||||
|
self.assertEqual('bar', build_slot.params_id.config_data['moc_var'])
|
||||||
|
|
||||||
|
def test_trigger_config_data_custom_trigger(self):
|
||||||
|
"""Test that a config_data on a custom trigger overrides the config_data on the trigger"""
|
||||||
|
self.additionnal_setup()
|
||||||
|
self.start_patchers()
|
||||||
|
|
||||||
|
# A commit is found on the dev remote
|
||||||
|
branch_a_name = 'master-test-something'
|
||||||
|
self.push_commit(self.remote_server_dev, branch_a_name, 'nice subject', sha='d0d0caca')
|
||||||
|
# batch preparation
|
||||||
|
self.repo_server.project_id.process_delay = 10
|
||||||
|
self.repo_server._update_batches()
|
||||||
|
|
||||||
|
# set config data on the trigger
|
||||||
|
self.trigger_server.config_data = {'moc_var': 'bar'}
|
||||||
|
|
||||||
|
# create a custom trigger for the bundle
|
||||||
|
bundle = self.Bundle.search([('name', '=', branch_a_name), ('project_id', '=', self.project.id)])
|
||||||
|
|
||||||
|
# create a custom trigger with the custom config linked to the bundle
|
||||||
|
self.env['runbot.bundle.trigger.custom'].create({
|
||||||
|
'trigger_id': self.trigger_server.id,
|
||||||
|
'bundle_id': bundle.id,
|
||||||
|
'config_data': {'moc_var': 'foo'},
|
||||||
|
})
|
||||||
|
|
||||||
|
self.repo_server.project_id.process_delay = 0
|
||||||
|
bundle.last_batch._process()
|
||||||
|
build_slot = bundle.last_batch.slot_ids.filtered(lambda rec: rec.trigger_id == self.trigger_server)
|
||||||
|
self.assertIn(
|
||||||
|
'moc_var', build_slot.params_id.config_data
|
||||||
|
)
|
||||||
|
self.assertEqual('foo', build_slot.params_id.config_data['moc_var'])
|
||||||
|
|
||||||
class TestBuildResult(RunbotCase):
|
class TestBuildResult(RunbotCase):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user