mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[REF] runbot: store the target branch name
In the case of PR, the name contains 'refs/pull/3175', the branch_name
contains '3175' and because of the previous fix e095170f8c
, the
pull_head_name sontains something like 'blah:12.0-something'.
In that case, the _get_closest_branch_name reaches the fallback.
With this commit, the target_branch_name is stored in a new field and is
used as the fallback.
This commit is contained in:
parent
e095170f8c
commit
1330d52098
@ -6,7 +6,7 @@
|
|||||||
'author': "Odoo SA",
|
'author': "Odoo SA",
|
||||||
'website': "http://runbot.odoo.com",
|
'website': "http://runbot.odoo.com",
|
||||||
'category': 'Website',
|
'category': 'Website',
|
||||||
'version': '2.3',
|
'version': '2.4',
|
||||||
'depends': ['website', 'base'],
|
'depends': ['website', 'base'],
|
||||||
'data': [
|
'data': [
|
||||||
'security/runbot_security.xml',
|
'security/runbot_security.xml',
|
||||||
|
@ -16,9 +16,10 @@ class runbot_branch(models.Model):
|
|||||||
|
|
||||||
repo_id = fields.Many2one('runbot.repo', 'Repository', required=True, ondelete='cascade')
|
repo_id = fields.Many2one('runbot.repo', 'Repository', required=True, ondelete='cascade')
|
||||||
name = fields.Char('Ref Name', required=True)
|
name = fields.Char('Ref Name', required=True)
|
||||||
branch_name = fields.Char(compute='_get_branch_name', type='char', string='Branch', readonly=1, store=True)
|
branch_name = fields.Char(compute='_get_branch_infos', string='Branch', readonly=1, store=True)
|
||||||
branch_url = fields.Char(compute='_get_branch_url', type='char', string='Branch url', readonly=1)
|
branch_url = fields.Char(compute='_get_branch_infos', string='Branch url', readonly=1)
|
||||||
pull_head_name = fields.Char(compute='_get_pull_head_name', type='char', string='PR HEAD name', readonly=1, store=True)
|
pull_head_name = fields.Char(compute='_get_branch_infos', string='PR HEAD name', readonly=1, store=True)
|
||||||
|
target_branch_name = fields.Char(compute='_get_branch_infos', string='PR target branch', readonly=1, store=True)
|
||||||
sticky = fields.Boolean('Sticky')
|
sticky = fields.Boolean('Sticky')
|
||||||
coverage = fields.Boolean('Coverage')
|
coverage = fields.Boolean('Coverage')
|
||||||
coverage_result = fields.Float(compute='_get_last_coverage', type='Float', string='Last coverage', store=False)
|
coverage_result = fields.Float(compute='_get_last_coverage', type='Float', string='Last coverage', store=False)
|
||||||
@ -28,21 +29,21 @@ class runbot_branch(models.Model):
|
|||||||
priority = fields.Boolean('Build priority', default=False)
|
priority = fields.Boolean('Build priority', default=False)
|
||||||
|
|
||||||
@api.depends('name')
|
@api.depends('name')
|
||||||
def _get_branch_name(self):
|
def _get_branch_infos(self):
|
||||||
"""compute the branch name based on ref name"""
|
"""compute branch_name, branch_url, pull_head_name and target_branch_name based on name"""
|
||||||
for branch in self:
|
for branch in self:
|
||||||
if branch.name:
|
if branch.name:
|
||||||
branch.branch_name = branch.name.split('/')[-1]
|
branch.branch_name = branch.name.split('/')[-1]
|
||||||
|
|
||||||
@api.depends('branch_name')
|
|
||||||
def _get_branch_url(self):
|
|
||||||
"""compute the branch url based on branch_name"""
|
|
||||||
for branch in self:
|
|
||||||
if branch.name:
|
|
||||||
if re.match('^[0-9]+$', branch.branch_name):
|
if re.match('^[0-9]+$', branch.branch_name):
|
||||||
branch.branch_url = "https://%s/pull/%s" % (branch.repo_id.base, branch.branch_name)
|
branch.branch_url = "https://%s/pull/%s" % (branch.repo_id.base, branch.branch_name)
|
||||||
else:
|
else:
|
||||||
branch.branch_url = "https://%s/tree/%s" % (branch.repo_id.base, branch.branch_name)
|
branch.branch_url = "https://%s/tree/%s" % (branch.repo_id.base, branch.branch_name)
|
||||||
|
pi = self._get_pull_info()
|
||||||
|
if pi:
|
||||||
|
branch.target_branch_name = pi['base']['ref']
|
||||||
|
if 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_pull_info(self):
|
def _get_pull_info(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
@ -67,15 +68,6 @@ class runbot_branch(models.Model):
|
|||||||
vals.setdefault('coverage', _re_coverage.search(vals.get('name') or '') is not None)
|
vals.setdefault('coverage', _re_coverage.search(vals.get('name') or '') is not None)
|
||||||
return super(runbot_branch, self).create(vals)
|
return super(runbot_branch, self).create(vals)
|
||||||
|
|
||||||
@api.depends('branch_name')
|
|
||||||
def _get_pull_head_name(self):
|
|
||||||
"""compute pull head name"""
|
|
||||||
for branch in self:
|
|
||||||
pi = self._get_pull_info()
|
|
||||||
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):
|
def _get_branch_quickconnect_url(self, fqdn, dest):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
r = {}
|
r = {}
|
||||||
|
@ -134,6 +134,7 @@ class runbot_build(models.Model):
|
|||||||
build = self
|
build = self
|
||||||
branch, repo = build.branch_id, build.repo_id
|
branch, repo = build.branch_id, build.repo_id
|
||||||
name = branch.pull_head_name or branch.branch_name
|
name = branch.pull_head_name or branch.branch_name
|
||||||
|
target_branch = branch.target_branch_name or 'master'
|
||||||
|
|
||||||
target_repo = self.env['runbot.repo'].browse(target_repo_id)
|
target_repo = self.env['runbot.repo'].browse(target_repo_id)
|
||||||
|
|
||||||
@ -216,7 +217,7 @@ class runbot_build(models.Model):
|
|||||||
return target_id, b, 'fuzzy'
|
return target_id, b, 'fuzzy'
|
||||||
|
|
||||||
# 5. last-resort value
|
# 5. last-resort value
|
||||||
return target_repo_id, 'master', 'default'
|
return target_repo_id, target_branch, 'default'
|
||||||
|
|
||||||
@api.depends('name', 'branch_id.name')
|
@api.depends('name', 'branch_id.name')
|
||||||
def _get_dest(self):
|
def _get_dest(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user