From e095170f8c98cbf1401ea33a2fea07ec6c058591 Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Wed, 17 Oct 2018 15:05:24 +0200 Subject: [PATCH] [FIX] runbot: build PR with corresponding community PR When searching for a matching PR in a target repo, the match was made on the 'base ref' which is the base branch that the PR targets. This means that the second case of the _get_closest_branch method was never reached. Example: An enterprise PR is created that targets Odoo branch 12.0 but with a matching community PR with a branch with the same name. The corresponding PR is never found by the runbot because the first rule match: '12.0' is the base ref of the PR. This could have been fixed by using the branch pull_head_name field to build the domain but that leads to a problem with the second rule: If a PR branch is named 'patch-1', the domain will match each PR with the same pull_head_name. With this commit, the pull_head_name field will store the pull head label. It's not a problem with older PR as a newly created PR in enterprise will not accidentally match with older ones. Another issue appeared with github branch naming like 'patch-'. If someone creates a PR with a branch auto-named 'patch-1', targeting the community repo and later creates an unrelated PR, targetting another repo depending of the community, they will be matched. To avoid that, the pull head names that ends with 'patch-n' are not stored. Those pull requests will be built against the target branch head. The actual behavior, before this commit, is a blocking point for the runbot_merge which is based on PR's only. It means that when a community PR is wrongly matched with with an enterprise PR runbot_merge will not merge the PR's. --- runbot/models/branch.py | 7 ++++--- runbot/models/build.py | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/runbot/models/branch.py b/runbot/models/branch.py index e3ce456a..52f0e488 100644 --- a/runbot/models/branch.py +++ b/runbot/models/branch.py @@ -6,7 +6,7 @@ from odoo import models, fields, api _logger = logging.getLogger(__name__) _re_coverage = re.compile(r'\bcoverage\b') - +_re_patch = re.compile(r'.*patch-\d+$') class runbot_branch(models.Model): @@ -72,8 +72,9 @@ class runbot_branch(models.Model): """compute pull head name""" for branch in self: pi = self._get_pull_info() - if pi: - branch.pull_head_name = pi['head']['ref'] + if pi and not _re_patch.match(pi['head']['label']): + # label is used to disambiguate PR with same branch name + branch.pull_head_name = pi['head']['label'] def _get_branch_quickconnect_url(self, fqdn, dest): self.ensure_one() diff --git a/runbot/models/build.py b/runbot/models/build.py index c1687495..24c02999 100644 --- a/runbot/models/build.py +++ b/runbot/models/build.py @@ -133,8 +133,7 @@ class runbot_build(models.Model): build = self branch, repo = build.branch_id, build.repo_id - pi = branch._get_pull_info() - name = pi['base']['ref'] if pi else branch.branch_name + name = branch.pull_head_name or branch.branch_name target_repo = self.env['runbot.repo'].browse(target_repo_id)