From 934fbefeaa18437d139a820b40cbca999c03d5da Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Sat, 17 Jun 2017 10:47:22 -0700 Subject: [PATCH 1/4] Log which event webhook made a request --- bedevere/__main__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bedevere/__main__.py b/bedevere/__main__.py index ba9a9650..ed87b55d 100644 --- a/bedevere/__main__.py +++ b/bedevere/__main__.py @@ -23,6 +23,7 @@ async def main(request): body = await request.read() secret = os.environ.get("GH_SECRET") event = sansio.Event.from_http(request.headers, body, secret=secret) + print('GH delivery ID', event.delivery_id, file=sys.stderr) if event.event == "ping": return web.Response(status=200) oauth_token = os.environ.get("GH_AUTH") From 92709d8a13c9409ecae8bc014c734d13595d7080 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Sat, 17 Jun 2017 10:47:46 -0700 Subject: [PATCH 2/4] Actually apply the decorator --- bedevere/backport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bedevere/backport.py b/bedevere/backport.py index 60370aca..8a472524 100644 --- a/bedevere/backport.py +++ b/bedevere/backport.py @@ -21,7 +21,7 @@ def normalize_title(title, body): return title[:-1] + body[1:].partition('\r\n')[0] -router.register('pull_request', action='opened') +@router.register("pull_request", action="opened") async def remove_backport_label(event, gh, *args, **kwargs): title = normalize_title(event.data['pull_request']['title'], event.data['pull_request']['body']) title_match = TITLE_RE.match(title) From 633dfbd25ce8be2d03a450bb9a25b1156244c7ef Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Sat, 17 Jun 2017 10:49:32 -0700 Subject: [PATCH 3/4] Test the router --- tests/test_backport.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_backport.py b/tests/test_backport.py index 38cf4a33..75db2b80 100644 --- a/tests/test_backport.py +++ b/tests/test_backport.py @@ -86,6 +86,7 @@ async def test_missing_label(): async def test_success(): event_data = { + 'action': 'opened', 'number': 2248, 'pull_request': { 'title': '[3.6] Backport this …', @@ -103,7 +104,7 @@ async def test_success(): 'comments_url': 'https://api.github.com/repos/python/cpython/issues/1234/comments', } gh = FakeGH(getitem=issue_data) - await backport.remove_backport_label(event, gh) + await backport.router.dispatch(event, gh) assert gh.getitem_url == sansio.format_url(event_data['repository']['issues_url'], {'number': '1234'}) assert gh.delete_url == sansio.format_url(issue_data['labels_url'], {'name': 'needs backport to 3.6'}) From 73f98e4d2c7129baeb56e1abf129c7b05976e981 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Sat, 17 Jun 2017 10:52:39 -0700 Subject: [PATCH 4/4] Test the bpo router --- tests/test_bpo.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/test_bpo.py b/tests/test_bpo.py index cd850582..0de26cac 100644 --- a/tests/test_bpo.py +++ b/tests/test_bpo.py @@ -45,6 +45,7 @@ async def test_set_status_failure(): @pytest.mark.asyncio async def test_set_status_success(): data = { + "action": "opened", "pull_request": { "statuses_url": "https://api.github.com/blah/blah/git-sha", "title": "[3.6] bpo-1234: an issue!", @@ -52,7 +53,7 @@ async def test_set_status_success(): } event = sansio.Event(data, event="pull_request", delivery_id="12345") gh = FakeGH() - await bpo.set_status(event, gh) + await bpo.router.dispatch(event, gh) status = gh.data assert status["state"] == "success" assert status["target_url"].endswith("issue1234") @@ -64,6 +65,7 @@ async def test_set_status_success(): @pytest.mark.asyncio async def test_set_status_success_via_trivial_label(): data = { + "action": "opened", "pull_request": { "statuses_url": "https://api.github.com/blah/blah/git-sha", "title": "No issue in title", @@ -77,7 +79,7 @@ async def test_set_status_success_via_trivial_label(): } event = sansio.Event(data, event="pull_request", delivery_id="12345") gh = FakeGH(getitem=issue_data) - await bpo.set_status(event, gh) + await bpo.router.dispatch(event, gh) status = gh.data assert status["state"] == "success" assert status["context"] == "bedevere/issue-number" @@ -96,7 +98,7 @@ async def test_edit_title(): } event = sansio.Event(data, event="pull_request", delivery_id="12345") gh = FakeGH() - await bpo.title_edited(event, gh) + await bpo.router.dispatch(event, gh) assert hasattr(gh, "data") @@ -112,7 +114,7 @@ async def test_edit_other_than_title(): } event = sansio.Event(data, event="pull_request", delivery_id="12345") gh = FakeGH() - await bpo.title_edited(event, gh) + await bpo.router.dispatch(event, gh) assert not hasattr(gh, "data") @@ -128,7 +130,7 @@ async def test_new_label_trivial_no_issue(): } event = sansio.Event(data, event="pull_request", delivery_id="12345") gh = FakeGH() - await bpo.new_label(event, gh) + await bpo.router.dispatch(event, gh) assert gh.data["state"] == "success" assert "git-sha" in gh.url @@ -145,7 +147,7 @@ async def test_new_label_trivial_with_issue_number(): } event = sansio.Event(data, event="pull_request", delivery_id="12345") gh = FakeGH() - await bpo.new_label(event, gh) + await bpo.router.dispatch(event, gh) status = gh.data assert status["state"] == "success" assert status["target_url"].endswith("issue1234") @@ -165,7 +167,7 @@ async def test_new_label_not_trivial(): } event = sansio.Event(data, event="pull_request", delivery_id="12345") gh = FakeGH() - await bpo.new_label(event, gh) + await bpo.router.dispatch(event, gh) assert not hasattr(gh, "data") @@ -181,7 +183,7 @@ async def test_removed_label_trivial(): } event = sansio.Event(data, event="pull_request", delivery_id="12345") gh = FakeGH() - await bpo.removed_label(event, gh) + await bpo.router.dispatch(event, gh) status = gh.data assert status["state"] == "success" assert status["target_url"].endswith("issue1234") @@ -201,5 +203,5 @@ async def test_removed_label_non_trivial(): } event = sansio.Event(data, event="pull_request", delivery_id="12345") gh = FakeGH() - await bpo.removed_label(event, gh) + await bpo.router.dispatch(event, gh) assert not hasattr(gh, "data")