mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00
[IMP] runbot_merge: allow filtering out branches from repositories
This commit is contained in:
parent
6b3c81a177
commit
dd22f687bf
@ -1,3 +1,4 @@
|
||||
import ast
|
||||
import base64
|
||||
import collections
|
||||
import datetime
|
||||
@ -217,6 +218,7 @@ class Repository(models.Model):
|
||||
"`success` for a PR or staging to be valid",
|
||||
default='legal/cla,ci/runbot'
|
||||
)
|
||||
branch_filter = fields.Char(default='[(1, "=", 1)]', help="Filter branches valid for this repository")
|
||||
|
||||
def github(self, token_field='github_token'):
|
||||
return github.GH(self.project_id[token_field], self.name)
|
||||
@ -284,6 +286,10 @@ class Repository(models.Model):
|
||||
'repository': {'full_name': self.name},
|
||||
})
|
||||
|
||||
def having_branch(self, branch):
|
||||
branches = self.env['runbot_merge.branch'].search
|
||||
return self.filtered(lambda r: branch in branches(ast.literal_eval(r.branch_filter)))
|
||||
|
||||
class Branch(models.Model):
|
||||
_name = _description = 'runbot_merge.branch'
|
||||
_order = 'sequence, name'
|
||||
@ -388,7 +394,7 @@ class Branch(models.Model):
|
||||
|
||||
Batch = self.env['runbot_merge.batch']
|
||||
staged = Batch
|
||||
meta = {repo: {} for repo in self.project_id.repo_ids}
|
||||
meta = {repo: {} for repo in self.project_id.repo_ids.having_branch(self)}
|
||||
for repo, it in meta.items():
|
||||
gh = it['gh'] = repo.github()
|
||||
it['head'] = gh.head(self.name)
|
||||
@ -435,7 +441,7 @@ class Branch(models.Model):
|
||||
})
|
||||
# create staging branch from tmp
|
||||
token = self.project_id.github_token
|
||||
for r in self.project_id.repo_ids:
|
||||
for r in self.project_id.repo_ids.having_branch(self):
|
||||
it = meta[r]
|
||||
staging_head = heads[r.name]
|
||||
_logger.info(
|
||||
@ -1573,7 +1579,7 @@ class Stagings(models.Model):
|
||||
logger.info("Checking active staging %s (state=%s)", self, self.state)
|
||||
project = self.target.project_id
|
||||
if self.state == 'success':
|
||||
gh = {repo.name: repo.github() for repo in project.repo_ids}
|
||||
gh = {repo.name: repo.github() for repo in project.repo_ids.having_branch(self.target)}
|
||||
staging_heads = json.loads(self.heads)
|
||||
self.env.cr.execute('''
|
||||
SELECT 1 FROM runbot_merge_pull_requests
|
||||
|
@ -716,3 +716,31 @@ class TestBlocked:
|
||||
|
||||
with repo_b: b.post_comment('hansen p=0', config['role_reviewer']['token'])
|
||||
assert not pr_a.blocked
|
||||
|
||||
def test_different_branches(env, project, repo_a, repo_b, config):
|
||||
project.write({
|
||||
'branch_ids': [(0, 0, {'name': 'dev'})]
|
||||
})
|
||||
# repo_b only works with master
|
||||
env['runbot_merge.repository'].search([('name', '=', repo_b.name)])\
|
||||
.branch_filter = '[("name", "=", "master")]'
|
||||
with repo_a, repo_b:
|
||||
make_branch(repo_a, 'dev', 'initial', {'a': '0'})
|
||||
make_branch(repo_a, 'master', 'initial', {'b': '0'})
|
||||
make_branch(repo_b, 'master', 'initial', {'b': '0'})
|
||||
|
||||
pr_a = make_pr(
|
||||
repo_a, 'xxx', [{'a': '1'}],
|
||||
target='dev',
|
||||
user=config['role_user']['token'],
|
||||
reviewer=config['role_reviewer']['token']
|
||||
)
|
||||
env.run_crons()
|
||||
|
||||
with repo_a:
|
||||
pr_a.post_comment('hansen r+', config['role_reviewer']['token'])
|
||||
repo_a.post_status('heads/staging.dev', 'success', 'legal/cla')
|
||||
repo_a.post_status('heads/staging.dev', 'success', 'ci/runbot')
|
||||
env.run_crons()
|
||||
|
||||
assert to_pr(env, pr_a).state == 'merged'
|
||||
|
Loading…
Reference in New Issue
Block a user