diff --git a/miss_islington/status_change.py b/miss_islington/status_change.py index 29515b60..84282232 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( + 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: 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) 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..b9277eab 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,22 @@ 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 + 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