From 61d5ace5713b71a5ebda8d10e9d0373ef5301a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Mon, 11 Jul 2022 10:48:20 +0200 Subject: [PATCH 1/5] Fix status check comment for timed out or failed checks --- miss_islington/status_change.py | 14 +++++--- tests/test_check_run.py | 26 +++++++++++++-- tests/test_status_change.py | 57 ++++++++++++++++++++++++++++++--- 3 files changed, 86 insertions(+), 11 deletions(-) diff --git a/miss_islington/status_change.py b/miss_islington/status_change.py index 29515b60..334c5a06 100644 --- a/miss_islington/status_change.py +++ b/miss_islington/status_change.py @@ -100,16 +100,22 @@ async def check_ci_status_and_approval( title_match = TITLE_RE.match(normalized_pr_title) if title_match or is_automerge: - success = result["state"] == "success" and not any( + success = result["state"] == "success" + failure = any( elem in [None, "failure", "timed_out"] for elem in all_check_run_conclusions ) if leave_comment: - if success: + if success and not failure: emoji = "✅" + status = "it's a success" + if failure: + emoji = "❌" + status = "it's a failure or timed out" else: emoji = "❌" - message = f"Status check is done, and it's a {result['state']} {emoji} ." + status = "it's a failure" + message = f"Status check is done, and {status} {emoji}." if not success: if is_automerge: participants = await util.get_gh_participants(gh, pr_number) @@ -124,7 +130,7 @@ async def check_ci_status_and_approval( pr_number=pr_number, message=message, ) - if success: + if success and not failure: if util.pr_is_awaiting_merge(pr_for_commit["labels"]): await merge_pr( gh, pr_for_commit, sha, is_automerge=is_automerge diff --git a/tests/test_check_run.py b/tests/test_check_run.py index 3deae2da..f72a56bb 100644 --- a/tests/test_check_run.py +++ b/tests/test_check_run.py @@ -143,7 +143,18 @@ async def test_check_run_completed_other_check_run_pending_with_awaiting_merge_l }, } - gh = FakeGH(getitem=getitem) + getiter = { + "/repos/python/cpython/pulls/5547/commits": [ + { + "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", + "commit": { + "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 " + }, + } + ] + } + + gh = FakeGH(getitem=getitem, getiter=getiter) await check_run.router.dispatch(event, gh) assert not hasattr(gh, "post_data") # does not leave a comment assert not hasattr(gh, "put_data") # is not merged @@ -326,7 +337,18 @@ async def test_check_run_completed_timed_out_with_awaiting_merge_label_pr_is_not }, } - gh = FakeGH(getitem=getitem) + getiter = { + "/repos/python/cpython/pulls/5547/commits": [ + { + "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", + "commit": { + "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 " + }, + } + ] + } + + gh = FakeGH(getitem=getitem, getiter=getiter) await check_run.router.dispatch(event, gh) assert len(gh.post_data["body"]) is not None # leaves a comment assert not hasattr(gh, "put_data") # is not merged diff --git a/tests/test_status_change.py b/tests/test_status_change.py index 3a89afa7..28b00065 100644 --- a/tests/test_status_change.py +++ b/tests/test_status_change.py @@ -307,7 +307,18 @@ async def test_ci_passed_and_check_run_failure_awaiting_merge_label_pr_is_not_me }, } - gh = FakeGH(getitem=getitem) + getiter = { + "/repos/python/cpython/pulls/5547/commits": [ + { + "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", + "commit": { + "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 " + }, + } + ] + } + + gh = FakeGH(getitem=getitem, getiter=getiter) await status_change.router.dispatch(event, gh) assert len(gh.post_data["body"]) is not None # leaves a comment assert not hasattr(gh, "put_data") # is not merged @@ -374,7 +385,18 @@ async def test_automerge_with_check_run_failure(): }, } - gh = FakeGH(getitem=getitem) + getiter = { + "/repos/python/cpython/pulls/5547/commits": [ + { + "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", + "commit": { + "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 " + }, + } + ] + } + + gh = FakeGH(getitem=getitem, getiter=getiter) await status_change.router.dispatch(event, gh) assert len(gh.post_data["body"]) is not None # leaves a comment assert not hasattr(gh, "put_data") # is not merged @@ -431,7 +453,18 @@ async def test_ci_passed_and_check_run_pending_awaiting_merge_label_pr_is_not_me }, } - gh = FakeGH(getitem=getitem) + getiter = { + "/repos/python/cpython/pulls/5547/commits": [ + { + "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", + "commit": { + "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 " + }, + } + ] + } + + gh = FakeGH(getitem=getitem, getiter=getiter) await status_change.router.dispatch(event, gh) assert len(gh.post_data["body"]) is not None # leaves a comment assert not hasattr(gh, "put_data") # is not merged @@ -488,9 +521,23 @@ async def test_ci_passed_and_check_run_timed_out_awaiting_merge_label_pr_is_not_ }, } - gh = FakeGH(getitem=getitem) + getiter = { + "/repos/python/cpython/pulls/5547/commits": [ + { + "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", + "commit": { + "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 " + }, + } + ] + } + + gh = FakeGH(getitem=getitem, getiter=getiter) await status_change.router.dispatch(event, gh) - assert len(gh.post_data["body"]) is not None # leaves a comment + assert ( + gh.post_data["body"] + == "Status check is done, and it's a failure or timed out ❌." + ) assert not hasattr(gh, "put_data") # is not merged From b536399cb23de8b9caae837c05aa15215b077d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Mon, 11 Jul 2022 22:12:30 +0200 Subject: [PATCH 2/5] Fix coverage issue --- miss_islington/status_change.py | 10 ++++++---- tests/test_status_change.py | 3 +-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/miss_islington/status_change.py b/miss_islington/status_change.py index 334c5a06..7fd9ba64 100644 --- a/miss_islington/status_change.py +++ b/miss_islington/status_change.py @@ -100,13 +100,13 @@ async def check_ci_status_and_approval( title_match = TITLE_RE.match(normalized_pr_title) if title_match or is_automerge: - success = result["state"] == "success" failure = any( elem in [None, "failure", "timed_out"] for elem in all_check_run_conclusions ) + success = result["state"] == "success" and not failure if leave_comment: - if success and not failure: + if success: emoji = "✅" status = "it's a success" if failure: @@ -130,7 +130,7 @@ async def check_ci_status_and_approval( pr_number=pr_number, message=message, ) - if success and not failure: + if success: if util.pr_is_awaiting_merge(pr_for_commit["labels"]): await merge_pr( gh, pr_for_commit, sha, is_automerge=is_automerge @@ -139,7 +139,9 @@ async def check_ci_status_and_approval( async def merge_pr(gh, pr, sha, is_automerge=False): pr_number = pr["number"] - async for commit in gh.getiter(f"/repos/python/cpython/pulls/{pr_number}/commits"): # pragma: no branch + async for commit in gh.getiter( + f"/repos/python/cpython/pulls/{pr_number}/commits" + ): # pragma: no branch if commit["sha"] == sha: # pragma: no branch if is_automerge: pr_commit_msg = util.normalize_message(pr["body"]) diff --git a/tests/test_status_change.py b/tests/test_status_change.py index 28b00065..9184d6cc 100644 --- a/tests/test_status_change.py +++ b/tests/test_status_change.py @@ -2,7 +2,6 @@ import gidgethub from gidgethub import sansio - from miss_islington import status_change from miss_islington.util import AUTOMERGE_LABEL @@ -536,7 +535,7 @@ async def test_ci_passed_and_check_run_timed_out_awaiting_merge_label_pr_is_not_ await status_change.router.dispatch(event, gh) assert ( gh.post_data["body"] - == "Status check is done, and it's a failure or timed out ❌." + == "@miss-islington and @Mariatta: Status check is done, and it's a failure or timed out ❌." ) assert not hasattr(gh, "put_data") # is not merged From 1ffbfb0867d1b0a567ec3cbcdc5bcac8e3128abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Mon, 11 Jul 2022 22:13:22 +0200 Subject: [PATCH 3/5] Remove unrelated change --- miss_islington/status_change.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/miss_islington/status_change.py b/miss_islington/status_change.py index 7fd9ba64..84282232 100644 --- a/miss_islington/status_change.py +++ b/miss_islington/status_change.py @@ -139,9 +139,7 @@ async def check_ci_status_and_approval( async def merge_pr(gh, pr, sha, is_automerge=False): pr_number = pr["number"] - async for commit in gh.getiter( - f"/repos/python/cpython/pulls/{pr_number}/commits" - ): # pragma: no branch + async for commit in gh.getiter(f"/repos/python/cpython/pulls/{pr_number}/commits"): # pragma: no branch if commit["sha"] == sha: # pragma: no branch if is_automerge: pr_commit_msg = util.normalize_message(pr["body"]) From e7af1b0fee25c457ff189645025b5ae2849b726b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Mon, 11 Jul 2022 22:13:58 +0200 Subject: [PATCH 4/5] Last unrelated change --- tests/test_status_change.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_status_change.py b/tests/test_status_change.py index 9184d6cc..c62452b3 100644 --- a/tests/test_status_change.py +++ b/tests/test_status_change.py @@ -2,6 +2,7 @@ import gidgethub from gidgethub import sansio + from miss_islington import status_change from miss_islington.util import AUTOMERGE_LABEL From f358e2f4262d2289d9dc5b0bd4048b7b7bf7e5ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Mon, 8 Aug 2022 14:45:04 +0200 Subject: [PATCH 5/5] Update tests/test_status_change.py Co-authored-by: Ezio Melotti --- tests/test_status_change.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_status_change.py b/tests/test_status_change.py index c62452b3..b9277eab 100644 --- a/tests/test_status_change.py +++ b/tests/test_status_change.py @@ -534,10 +534,9 @@ async def test_ci_passed_and_check_run_timed_out_awaiting_merge_label_pr_is_not_ gh = FakeGH(getitem=getitem, getiter=getiter) await status_change.router.dispatch(event, gh) - assert ( - gh.post_data["body"] - == "@miss-islington and @Mariatta: Status check is done, and it's a failure or timed out ❌." - ) + expected_body = ("@miss-islington and @Mariatta: Status check is done, " + "and it's a failure or timed out ❌.") + assert gh.post_data["body"] == expected_body assert not hasattr(gh, "put_data") # is not merged