Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bedevere/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion bedevere/backport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_backport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 …',
Expand All @@ -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'})
Expand Down
20 changes: 11 additions & 9 deletions tests/test_bpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ 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!",
},
}
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")
Expand All @@ -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",
Expand All @@ -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"
Expand All @@ -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")


Expand All @@ -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")


Expand All @@ -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

Expand All @@ -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")
Expand All @@ -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")


Expand All @@ -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")
Expand All @@ -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")