8000 Fix the pull_request_review webhook. (#52) · python/cpython@aec8995 · GitHub
[go: up one dir, main page]

Skip to content

Commit aec8995

Browse files
authored
Fix the pull_request_review webhook. (#52)
1 parent 69f93c6 commit aec8995

File tree

2 files changed

+84
-9
lines changed

2 files changed

+84
-9
lines changed

backport/status_change.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ async def check_ci_status_and_approval(gh, sha, leave_comment=False):
6565
pr_number=pr_number,
6666
message=f"{participants}: Backport status check is done, and it's a {result['state']} {emoji} .")
6767

68-
if result['state'] == "success":
69-
async for review in gh.getiter(f"/repos/python/cpython/pulls/{pr_number}/reviews"):
70-
reviewer = review["user"]["login"]
71-
approved = review["state"].lower() == "approved"
72-
if approved \
73-
and await util.is_core_dev(gh, reviewer):
74-
await merge_pr(gh, pr_number, sha)
75-
break
68+
if result['state'] == "success":
69+
async for review in gh.getiter(f"/repos/python/cpython/pulls/{pr_number}/reviews"):
70+
reviewer = review["user"]["login"]
71+
approved = review["state"].lower() == "approved"
72+
if approved \
73+
and await util.is_core_dev(gh, reviewer):
74+
await merge_pr(gh, pr_number, sha)
75+
break
7676

7777

7878
async def merge_pr(gh, pr_number, sha):

tests/test_status_change.py

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,82 @@ async def test_ci_not_passed_with_core_dev_review_pr_is_not_merged():
245245
assert not hasattr(gh, 'put_data') # is not merged
246246

247247

248-
async def test_pr_reviewed_webhook_ci_passed_pr_is_not_merged():
248+
async def test_pr_reviewed_webhook_ci_passed_pr_is_merged():
249+
sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9"
250+
data = {
251+
"action": "submitted",
252+
"pull_request": {
253+
"user": {"login": "miss-islington"}},
254+
"review": {"commit_id": sha,
255+
"user": {"login": "Mariatta"},
256+
"state": "approved"
257+
}
258+
}
259+
260+
event = sansio.Event(data, event='pull_request_review',
261+
delivery_id='1')
262+
263+
getitem = {
264+
f'/repos/python/cpython/commits/{sha}/status':
265+
{
266+
"state": "success",
267+
"statuses": [
268+
{
269+
"state": "success",
270+
"description": "Issue report skipped",
271+
"context": "bedevere/issue-number",
272+
},
273+
{
274+
"state": "success",
275+
"description": "The Travis CI build passed",
276+
"target_url": "https://travis-ci.org/python/cpython/builds/340259685?utm_source=github_status&utm_medium=notification",
277+
"context": "continuous-integration/travis-ci/pr",
278+
}
279+
]
280+
},
281+
"/teams/42/memberships/Mariatta": True
282+
}
283+
284+
getiter = {
285+
'/repos/miss-islington/cpython/git/refs/heads/': [
286+
{
287+
"ref": f"refs/heads/backport-{sha[0:7]}-3.6",
288+
"object": {"sha": sha,}
289+
},
290+
{
291+
"ref": f"refs/heads/backport-{sha[0:7]}-3.6",
292+
"object": {
293+
"sha": sha,
294+
"type": "commit",
295+
"url": f"https://api.github.com/repos/miss-islington/cpython/git/commits/{sha}"
296+
}
297+
}],
298+
f'/repos/python/cpython/pulls?state=open&head=miss-islington:backport-{sha[0:7]}-3.6': [
299+
{"number": 5547,
300+
"title": "[3.6] bpo-32720: Fixed the replacement field grammar documentation. (GH-5544)",
301+
"body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.\n(cherry picked from commit 7a561afd2c79f63a6008843b83733911d07f0119)\n\nCo-authored-by: Mariatta <Mariatta@users.noreply.github.com>"},
302+
],
303+
"/orgs/python/teams": [{"name": "Python core", "id": 42}],
304+
'/repos/python/cpython/pulls/5547/reviews': [
305+
{"user": {"login": "Mariatta"},
306+
"state": "APPROVED"
307+
}],
308+
'/repos/python/cpython/pulls/5547/commits': [
309+
{"sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9",
310+
"commit": {
311+
"message": "bpo-32720: Fixed the replacement field grammar documentation. (GH-5544)\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.\n(cherry picked from commit 7a561afd2c79f63a6008843b83733911d07f0119)\n\nCo-authored-by: Mariatta <Mariatta@users.noreply.github.com>"
312+
}}],
313+
}
314+
315+
gh = FakeGH(getitem=getitem,
316+
getiter=getiter)
317+
await status_change.router.dispatch(event, gh)
318+
assert not hasattr(gh, 'post_data') # does not leave a comment
319+
assert gh.put_data["sha"] == sha # is merged
320+
assert gh.put_data["merge_method"] == "squash"
321+
322+
323+
async def test_pr_reviewed_webhook_ci_failure_pr_is_not_merged():
249324
sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9"
250325
data = {
251326
"action": "submitted",

0 commit comments

Comments
 (0)
0