diff --git a/bert_e/tests/unit/test_handle_pull_request.py b/bert_e/tests/unit/test_handle_pull_request.py new file mode 100644 index 00000000..fd6b8d32 --- /dev/null +++ b/bert_e/tests/unit/test_handle_pull_request.py @@ -0,0 +1,57 @@ +"""Unit tests for gitwaterflow.handle_pull_request routing.""" +from types import SimpleNamespace +from unittest.mock import patch + +from bert_e.workflow.gitwaterflow import handle_pull_request + + +class _FakeRepo: + def __init__(self): + self._url = '' + self._remote_branches = {} + + +def _make_job(author, src_branch): + """Return a minimal PullRequestJob stub.""" + pull_request = SimpleNamespace( + author=author, + src_branch=src_branch, + id=5171, + ) + settings = SimpleNamespace(robot=author) + bert_e = SimpleNamespace(settings=settings) + git = SimpleNamespace(cascade=None, repo=_FakeRepo()) + return SimpleNamespace( + pull_request=pull_request, + settings=settings, + bert_e=bert_e, + git=git, + ) + + +def test_robot_authored_integration_branch_routes_to_parent(): + """Robot PR on w/... branch routes to handle_parent_pull_request.""" + job = _make_job(author='bert-e', + src_branch='w/4.2/improvement/ARTESCA-17563-something') + + parent_path = 'bert_e.workflow.gitwaterflow.handle_parent_pull_request' + handle_path = 'bert_e.workflow.gitwaterflow._handle_pull_request' + with patch(parent_path) as mock_parent, patch(handle_path) as mock_handle: + handle_pull_request(job) + mock_parent.assert_called_once_with(job, job.pull_request) + mock_handle.assert_not_called() + + +def test_robot_authored_feature_branch_does_not_route_to_parent(): + """Robot PR on feature/... branch (CID bump) is not an integration PR.""" + job = _make_job( + author='bert-e', + src_branch='feature/ARTESCA-17576-bump-identity-ui-0.41.0', + ) + + parent_path = 'bert_e.workflow.gitwaterflow.handle_parent_pull_request' + handle_path = 'bert_e.workflow.gitwaterflow._handle_pull_request' + with patch(parent_path) as mock_parent, patch(handle_path) as mock_handle: + handle_pull_request(job) + mock_parent.assert_not_called() + mock_handle.assert_called_once_with(job) diff --git a/bert_e/workflow/gitwaterflow/__init__.py b/bert_e/workflow/gitwaterflow/__init__.py index 33fcf69b..f875c379 100644 --- a/bert_e/workflow/gitwaterflow/__init__.py +++ b/bert_e/workflow/gitwaterflow/__init__.py @@ -50,7 +50,8 @@ @handler(PullRequestJob) def handle_pull_request(job: PullRequestJob): """Analyse and handle a pull request that has just been updated.""" - if job.pull_request.author == job.settings.robot: + if job.pull_request.author == job.settings.robot and re.match( + IntegrationBranch.pattern, job.pull_request.src_branch): return handle_parent_pull_request(job, job.pull_request) try: _handle_pull_request(job)