From 39b049c575b7e6c9e8b11f9ff3b7876ad8ec393c Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Wed, 19 Feb 2025 12:12:54 +0100 Subject: [PATCH] [IMP] runbot: allow to use base commit on new batch --- runbot/controllers/frontend.py | 4 ++-- runbot/models/batch.py | 7 ++++++- runbot/templates/bundle.xml | 7 +++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/runbot/controllers/frontend.py b/runbot/controllers/frontend.py index 9058a430..f9e7a1c0 100644 --- a/runbot/controllers/frontend.py +++ b/runbot/controllers/frontend.py @@ -226,13 +226,13 @@ class Runbot(Controller): '/runbot/bundle//force', '/runbot/bundle//force/', ], type='http', auth="user", methods=['GET', 'POST'], csrf=False) - def force_bundle(self, bundle, auto_rebase=False, **_post): + def force_bundle(self, bundle, auto_rebase=False, use_base_commits=False,**_post): if not request.env.user.has_group('runbot.group_runbot_advanced_user') and ':' not in bundle.name: raise Forbidden("Only users with a specific group can do that. Please contact runbot administrators") _logger.info('user %s forcing bundle %s', request.env.user.name, bundle.name) # user must be able to read bundle batch = bundle.sudo()._force() batch._log('Batch forced by %s', request.env.user.name) - batch._prepare(auto_rebase) + batch._prepare(auto_rebase=bool(auto_rebase), use_base_commits=bool(use_base_commits)) batch._process() return werkzeug.utils.redirect('/runbot/batch/%s' % batch.id) diff --git a/runbot/models/batch.py b/runbot/models/batch.py index 3729d0c9..bd6f496d 100644 --- a/runbot/models/batch.py +++ b/runbot/models/batch.py @@ -174,8 +174,10 @@ class Batch(models.Model): build._github_status() return link_type, build - def _prepare(self, auto_rebase=False): + def _prepare(self, auto_rebase=False, use_base_commits=False): _logger.info('Preparing batch %s', self.id) + if use_base_commits: + self._warning('This batch will use base commits instead of bundle commits') if not self.bundle_id.base_id: # in some case the base can be detected lately. If a bundle has no base, recompute the base before preparing self.bundle_id._compute_base_id() @@ -359,6 +361,8 @@ class Batch(models.Model): commit_link.commit_id = commit_link.commit_id._rebase_on(commit_link.base_commit_id) commit_link_by_repos = {commit_link.commit_id.repo_id.id: commit_link for commit_link in self.commit_link_ids} base_commit_link_by_repos = {commit_link.commit_id.repo_id.id: commit_link for commit_link in self.base_reference_batch_id.commit_link_ids} + if use_base_commits: + commit_link_by_repos = base_commit_link_by_repos version_id = self.bundle_id.version_id.id project_id = self.bundle_id.project_id.id trigger_customs = {} @@ -376,6 +380,7 @@ class Batch(models.Model): config_data = dict(trigger.config_data or {}) | dict(trigger_custom.config_data or {}) trigger_commit_link_by_repos = commit_link_by_repos if trigger_custom.use_base_commits and self.base_reference_batch_id: + self._warning(f'This batch will use base commits instead of bundle commits for trigger {trigger.name}') trigger_commit_link_by_repos = base_commit_link_by_repos commits_links = [trigger_commit_link_by_repos[repo.id].id for repo in trigger_repos] params_value = { diff --git a/runbot/templates/bundle.xml b/runbot/templates/bundle.xml index b8c411eb..20addbd9 100644 --- a/runbot/templates/bundle.xml +++ b/runbot/templates/bundle.xml @@ -16,11 +16,14 @@ - + - + + + +