[FIX] runbot: fallback on splitting name when no common ancestor

This commit is contained in:
David Monjoie 2015-01-20 16:20:35 +01:00
parent d3fe1d9c3e
commit 51ab9cb5de

View File

@ -538,12 +538,12 @@ class runbot_build(osv.osv):
def get_closest_branch_name(self, cr, uid, ids, target_repo_id, hint_branches, context=None): def get_closest_branch_name(self, cr, uid, ids, target_repo_id, hint_branches, context=None):
"""Return the name of the closest common branch between both repos """Return the name of the closest common branch between both repos
Find common branch names, get merge-base with the branch name and Rules priority for choosing the branch from the other repo is:
return the most recent. 1. Same branch name
Fallback repos will not have always have the same names for branch 2. Common ancestors (git merge-base)
names. 3. Name splitting on '-' character
Pull request branches should not have any association with PR of other Note that PR numbers are replaced by the branch name from which the PR is made,
repos to prevent the above rules to mistakenly link PR of different repos together.
""" """
branch_pool = self.pool['runbot.branch'] branch_pool = self.pool['runbot.branch']
for build in self.browse(cr, uid, ids, context=context): for build in self.browse(cr, uid, ids, context=context):
@ -579,6 +579,9 @@ class runbot_build(osv.osv):
continue continue
if common_refs: if common_refs:
name = sorted(common_refs.iteritems(), key=operator.itemgetter(1), reverse=True)[0][0] name = sorted(common_refs.iteritems(), key=operator.itemgetter(1), reverse=True)[0][0]
else:
# If all else as failed, fallback on '-' splitting
name = build.branch_id.name.split('-', 1)[0]
return name return name
def path(self, cr, uid, ids, *l, **kw): def path(self, cr, uid, ids, *l, **kw):