From 5df231978b7575dfbdba39c54e2471996a86d635 Mon Sep 17 00:00:00 2001 From: Mariatta Wijaya Date: Fri, 3 Nov 2017 20:28:05 -0700 Subject: [PATCH 1/3] Close invalid PR. Close PR that tries to merge the user's maintenance branch into CPython's master. --- bedevere/close_pr.py | 7 +++---- tests/test_close_pr.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/bedevere/close_pr.py b/bedevere/close_pr.py index 3e929b5a..41d6cc08 100644 --- a/bedevere/close_pr.py +++ b/bedevere/close_pr.py @@ -4,18 +4,18 @@ 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() @router.register("pull_request", action="opened") @router.register("pull_request", action="synchronize") async def close_invalid_pr(event, gh, *args, **kwargs): - """Close the invalid PR. + """Close the invalid PR and dismiss any requested reviews. 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..4ae89799 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" \ No newline at end of file From 811c378088081512dc34318b7423f4e199d83b0c Mon Sep 17 00:00:00 2001 From: Mariatta Wijaya Date: Fri, 3 Nov 2017 20:29:41 -0700 Subject: [PATCH 2/3] bah... trailing space.. --- tests/test_close_pr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_close_pr.py b/tests/test_close_pr.py index 4ae89799..67157d4a 100644 --- a/tests/test_close_pr.py +++ b/tests/test_close_pr.py @@ -131,4 +131,4 @@ async def test_close_invalid_pr_on_open_not_python_as_head(): gh = FakeGH(getitem=pr_data) await close_pr.router.dispatch(event, gh) patch_data = gh.patch_data - assert patch_data["state"] == "closed" \ No newline at end of file + assert patch_data["state"] == "closed" From 59cbc3641abf8dd0c2edd6bc68270701b9e76a74 Mon Sep 17 00:00:00 2001 From: Mariatta Wijaya Date: Fri, 3 Nov 2017 20:31:17 -0700 Subject: [PATCH 3/3] Correct the docstring. Reviews aren't dismissed (yet). --- bedevere/close_pr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bedevere/close_pr.py b/bedevere/close_pr.py index 41d6cc08..501ba8dd 100644 --- a/bedevere/close_pr.py +++ b/bedevere/close_pr.py @@ -11,7 +11,7 @@ @router.register("pull_request", action="opened") @router.register("pull_request", action="synchronize") async def close_invalid_pr(event, gh, *args, **kwargs): - """Close the invalid PR and dismiss any requested reviews. + """Close the invalid PR. PR is considered invalid if: * base_label is 'python:master'