2020-07-10 15:21:43 +07:00
|
|
|
import pytest
|
|
|
|
|
2024-12-02 20:17:28 +07:00
|
|
|
from utils import Commit, to_pr
|
|
|
|
|
2020-07-10 15:21:43 +07:00
|
|
|
|
|
|
|
@pytest.fixture
|
[ADD] *: per-repository webhook secret
Currently webhook secrets are configured per *project* which is an
issue both because different repositories may have different
administrators and thus creates safety concerns, and because multiple
repositories can feed into different projects (e.g. on mergebot,
odoo-dev/odoo is both an ancillary repository to the main RD project,
and the main repository to the minor / legacy master-wowl
project). This means it can be necessary to have multiple projects
share the same secret as well, this then mandates the secret for more
repositories per (1).
This is a pain in the ass, so just detach secrets from projects and
link them *only* to repositories, it's cleaner and easier to manage
and set up progressively.
This requires a lot of changes to the tests, as they all need to
correctly configure the signaling.
For `runbot_merge` there was *some* setup sharing already via the
module-level `repo` fixtures`, those were merged into a conftest-level
fixture which could handle the signaling setup. A few tests which
unnecessarily set up repositories ad-hoc were also moved to the
fixture. But for most of the ad-hoc setup in `runbot_merge`, as well
as `forwardport` where it's all ad-hoc, events sources setup was just
appended as is. This should probably be cleaned up at one point, with
the various requirements collected and organised into a small set of
fixtures doing the job more uniformly.
Fixes #887
2024-06-06 16:07:57 +07:00
|
|
|
def _setup_statuses(project, repo):
|
|
|
|
project.repo_ids.status_ids = [
|
|
|
|
(5, 0, 0),
|
|
|
|
(0, 0, {'context': 'ci'}),
|
|
|
|
# require the lint status on master
|
|
|
|
(0, 0, {
|
|
|
|
'context': 'lint',
|
|
|
|
'branch_filter': [('id', '=', project.branch_ids.id)]
|
|
|
|
}),
|
|
|
|
(0, 0, {'context': 'pr', 'stagings': False}),
|
|
|
|
(0, 0, {'context': 'staging', 'prs': False}),
|
|
|
|
]
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures('_setup_statuses')
|
2020-07-10 15:21:43 +07:00
|
|
|
def test_status_applies(env, repo, config):
|
|
|
|
""" If branches are associated with a repo status, only those branch should
|
|
|
|
require the status on their PRs & stagings
|
|
|
|
"""
|
|
|
|
with repo:
|
|
|
|
m = repo.make_commits(None, Commit('root', tree={'a': '1'}), ref='heads/master')
|
|
|
|
|
|
|
|
[c] = repo.make_commits(m, Commit('pr', tree={'a': '2'}), ref='heads/change')
|
|
|
|
pr = repo.make_pr(target='master', title="super change", head='change')
|
2024-12-02 20:17:28 +07:00
|
|
|
pr_id = to_pr(env, pr)
|
2020-07-10 15:21:43 +07:00
|
|
|
|
2024-12-03 17:15:11 +07:00
|
|
|
for context in ['ci', 'pr', 'lint']:
|
|
|
|
assert pr_id.state == 'opened'
|
|
|
|
with repo:
|
|
|
|
repo.post_status(c, 'success', context)
|
|
|
|
env.run_crons(None)
|
2020-07-10 15:21:43 +07:00
|
|
|
assert pr_id.state == 'validated'
|
|
|
|
|
|
|
|
with repo:
|
|
|
|
pr.post_comment('hansen r+', config['role_reviewer']['token'])
|
|
|
|
env.run_crons()
|
|
|
|
|
|
|
|
st = env['runbot_merge.stagings'].search([])
|
2024-12-03 17:15:11 +07:00
|
|
|
for context in ['ci', 'lint', 'staging']:
|
|
|
|
assert st.state == 'pending'
|
|
|
|
with repo:
|
|
|
|
repo.post_status('staging.master', 'success', context)
|
|
|
|
env.run_crons(None)
|
2020-07-10 15:21:43 +07:00
|
|
|
assert st.state == 'success'
|
|
|
|
|
[ADD] *: per-repository webhook secret
Currently webhook secrets are configured per *project* which is an
issue both because different repositories may have different
administrators and thus creates safety concerns, and because multiple
repositories can feed into different projects (e.g. on mergebot,
odoo-dev/odoo is both an ancillary repository to the main RD project,
and the main repository to the minor / legacy master-wowl
project). This means it can be necessary to have multiple projects
share the same secret as well, this then mandates the secret for more
repositories per (1).
This is a pain in the ass, so just detach secrets from projects and
link them *only* to repositories, it's cleaner and easier to manage
and set up progressively.
This requires a lot of changes to the tests, as they all need to
correctly configure the signaling.
For `runbot_merge` there was *some* setup sharing already via the
module-level `repo` fixtures`, those were merged into a conftest-level
fixture which could handle the signaling setup. A few tests which
unnecessarily set up repositories ad-hoc were also moved to the
fixture. But for most of the ad-hoc setup in `runbot_merge`, as well
as `forwardport` where it's all ad-hoc, events sources setup was just
appended as is. This should probably be cleaned up at one point, with
the various requirements collected and organised into a small set of
fixtures doing the job more uniformly.
Fixes #887
2024-06-06 16:07:57 +07:00
|
|
|
@pytest.mark.usefixtures('_setup_statuses')
|
2020-07-10 15:21:43 +07:00
|
|
|
def test_status_skipped(env, project, repo, config):
|
|
|
|
""" Branches not associated with a repo status should not require the status
|
|
|
|
on their PRs or stagings
|
|
|
|
"""
|
|
|
|
# add a second branch for which the lint status doesn't apply
|
|
|
|
project.write({'branch_ids': [(0, 0, {'name': 'maintenance'})]})
|
|
|
|
with repo:
|
|
|
|
m = repo.make_commits(None, Commit('root', tree={'a': '1'}), ref='heads/maintenance')
|
|
|
|
|
|
|
|
[c] = repo.make_commits(m, Commit('pr', tree={'a': '2'}), ref='heads/change')
|
|
|
|
pr = repo.make_pr(target='maintenance', title="super change", head='change')
|
2024-12-02 20:17:28 +07:00
|
|
|
pr_id = to_pr(env, pr)
|
2020-07-10 15:21:43 +07:00
|
|
|
|
2024-12-03 17:15:11 +07:00
|
|
|
for context in ['ci', 'pr']:
|
|
|
|
assert pr_id.state == 'opened'
|
|
|
|
with repo:
|
|
|
|
repo.post_status(c, 'success', context)
|
|
|
|
env.run_crons(None)
|
2020-07-10 15:21:43 +07:00
|
|
|
assert pr_id.state == 'validated'
|
|
|
|
|
|
|
|
with repo:
|
|
|
|
pr.post_comment('hansen r+', config['role_reviewer']['token'])
|
|
|
|
env.run_crons()
|
|
|
|
|
|
|
|
st = env['runbot_merge.stagings'].search([])
|
2024-12-03 17:15:11 +07:00
|
|
|
for context in ['staging', 'ci']:
|
|
|
|
assert st.state == 'pending'
|
|
|
|
with repo:
|
|
|
|
repo.post_status('staging.maintenance', 'success', context)
|
|
|
|
env.run_crons(None)
|
2020-07-10 15:21:43 +07:00
|
|
|
assert st.state == 'success'
|
2021-03-01 22:18:14 +07:00
|
|
|
|
|
|
|
def test_pseudo_version_tag(env, project, make_repo, setreviewers, config):
|
|
|
|
""" Because the last branch in the sequence is "live", if a PR's merged in
|
|
|
|
it it's hard to know where it landed in terms of other branches.
|
|
|
|
|
|
|
|
Therefore if a PR is merged in one such branch, tag it using the previous
|
|
|
|
branch of the sequence:
|
|
|
|
|
|
|
|
* if that ends with a number, increment the number by 1
|
|
|
|
* otherwise add 'post-' prefix (I guess)
|
|
|
|
"""
|
|
|
|
repo = make_repo('repo')
|
|
|
|
project.branch_ids.sequence = 1
|
|
|
|
project.write({
|
|
|
|
'repo_ids': [(0, 0, {'name': repo.name, 'required_statuses': 'ci'})],
|
|
|
|
'branch_ids': [
|
|
|
|
(0, 0, {'name': '2.0', 'sequence': 11}),
|
|
|
|
(0, 0, {'name': '1.0', 'sequence': 21})
|
|
|
|
],
|
|
|
|
})
|
|
|
|
setreviewers(*project.repo_ids)
|
[ADD] *: per-repository webhook secret
Currently webhook secrets are configured per *project* which is an
issue both because different repositories may have different
administrators and thus creates safety concerns, and because multiple
repositories can feed into different projects (e.g. on mergebot,
odoo-dev/odoo is both an ancillary repository to the main RD project,
and the main repository to the minor / legacy master-wowl
project). This means it can be necessary to have multiple projects
share the same secret as well, this then mandates the secret for more
repositories per (1).
This is a pain in the ass, so just detach secrets from projects and
link them *only* to repositories, it's cleaner and easier to manage
and set up progressively.
This requires a lot of changes to the tests, as they all need to
correctly configure the signaling.
For `runbot_merge` there was *some* setup sharing already via the
module-level `repo` fixtures`, those were merged into a conftest-level
fixture which could handle the signaling setup. A few tests which
unnecessarily set up repositories ad-hoc were also moved to the
fixture. But for most of the ad-hoc setup in `runbot_merge`, as well
as `forwardport` where it's all ad-hoc, events sources setup was just
appended as is. This should probably be cleaned up at one point, with
the various requirements collected and organised into a small set of
fixtures doing the job more uniformly.
Fixes #887
2024-06-06 16:07:57 +07:00
|
|
|
env['runbot_merge.events_sources'].create({'repository': repo.name})
|
2021-03-01 22:18:14 +07:00
|
|
|
|
|
|
|
with repo:
|
|
|
|
[m] = repo.make_commits(None, Commit('c1', tree={'a': '1'}), ref='heads/master')
|
|
|
|
repo.make_ref('heads/1.0', m)
|
|
|
|
repo.make_ref('heads/2.0', m)
|
|
|
|
repo.make_ref('heads/bonk', m)
|
|
|
|
|
|
|
|
with repo:
|
|
|
|
repo.make_commits(m, Commit('pr1', tree={'b': '1'}), ref='heads/change')
|
|
|
|
pr = repo.make_pr(target='master', head='change')
|
|
|
|
repo.post_status(pr.ref, 'success', 'ci')
|
|
|
|
pr.post_comment('hansen r+', config['role_reviewer']['token'])
|
|
|
|
env.run_crons() # should create staging
|
2024-12-02 20:17:28 +07:00
|
|
|
pr_id = to_pr(env, pr)
|
2021-03-01 22:18:14 +07:00
|
|
|
assert pr_id.state == 'ready'
|
|
|
|
assert pr_id.staging_id
|
|
|
|
with repo:
|
|
|
|
repo.post_status('staging.master', 'success', 'ci')
|
|
|
|
env.run_crons() # should merge staging
|
|
|
|
assert pr_id.state == 'merged'
|
|
|
|
assert pr.labels >= {'2.1'}
|
|
|
|
|
|
|
|
# now the second branch is non-numeric, therefore the label should just be prefixed by "post-"
|
|
|
|
project.write({'branch_ids': [(0, 0, {'name': 'bonk', 'sequence': 6})]})
|
|
|
|
with repo:
|
|
|
|
repo.make_commits(m, Commit('pr2', tree={'c': '1'}), ref='heads/change2')
|
|
|
|
pr = repo.make_pr(target='master', head='change2')
|
|
|
|
repo.post_status(pr.ref, 'success', 'ci')
|
|
|
|
pr.post_comment('hansen r+', config['role_reviewer']['token'])
|
|
|
|
env.run_crons() # should create staging
|
2024-12-02 20:17:28 +07:00
|
|
|
pr_id = to_pr(env, pr)
|
2021-03-01 22:18:14 +07:00
|
|
|
assert pr_id.state == 'ready', pr.comments
|
|
|
|
assert pr_id.staging_id
|
|
|
|
with repo:
|
|
|
|
repo.post_status('staging.master', 'success', 'ci')
|
|
|
|
env.run_crons() # should merge staging
|
|
|
|
assert pr_id.state == 'merged'
|
|
|
|
assert pr.labels >= {'post-bonk'}
|