diff --git a/bedevere/close_pr.py b/bedevere/close_pr.py index 3e929b5a..501ba8dd 100644 --- a/bedevere/close_pr.py +++ b/bedevere/close_pr.py @@ -4,7 +4,7 @@ import gidgethub.routing -PYTHON_MAINT_BRANCH_RE = re.compile(r'^python:\d+.\d+$') +PYTHON_MAINT_BRANCH_RE = re.compile(r'^\w+:\d+.\d+$') router = gidgethub.routing.Router() @@ -15,7 +15,7 @@ async def close_invalid_pr(event, gh, *args, **kwargs): PR is considered invalid if: * base_label is 'python:master' - * head_label is 'python:' + * head_label is ':' """ head_label = event.data["pull_request"]["head"]["label"] base_label = event.data["pull_request"]["base"]["label"] @@ -25,4 +25,3 @@ async def close_invalid_pr(event, gh, *args, **kwargs): data = {'state': 'closed', 'maintainer_can_modify': True} await gh.patch(event.data["pull_request"]["url"], data=data) - diff --git a/tests/test_close_pr.py b/tests/test_close_pr.py index 466ab8f2..67157d4a 100644 --- a/tests/test_close_pr.py +++ b/tests/test_close_pr.py @@ -103,3 +103,32 @@ async def test_valid_pr_not_closed(): await close_pr.router.dispatch(event, gh) patch_data = gh.patch_data assert patch_data is None + + +@pytest.mark.asyncio +async def test_close_invalid_pr_on_open_not_python_as_head(): + data = { + "action": "opened", + "pull_request": { + "statuses_url": "https://api.github.com/blah/blah/git-sha", + "title": "No issue in title", + "issue_url": "issue URL", + "url": "https://api.github.com/org/repo/pulls/123", + "head": { + "label": "username123:3.6" + }, + "base": { + "label": "python:master" + } + }, + } + pr_data = { + "labels": [ + {"name": "non-trivial"}, + ] + } + event = sansio.Event(data, event="pull_request", delivery_id="12345") + gh = FakeGH(getitem=pr_data) + await close_pr.router.dispatch(event, gh) + patch_data = gh.patch_data + assert patch_data["state"] == "closed"