Skip to content

Commit f89f450

Browse files
authored
Fix faulty logic for success/failure comment (#576)
1 parent 38b814f commit f89f450

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

miss_islington/status_change.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ async def check_ci_status_and_approval(
106106
)
107107
success = result["state"] == "success" and not failure
108108
if leave_comment:
109-
if success:
110-
emoji = "✅"
111-
status = "it's a success"
112109
if failure:
113110
emoji = "❌"
114111
status = "it's a failure or timed out"
115-
else:
112+
elif not success:
116113
emoji = "❌"
117114
status = "it's a failure"
115+
else:
116+
emoji = "✅"
117+
status = "it's a success"
118118
message = f"Status check is done, and {status} {emoji}."
119119
if not success:
120120
if is_automerge:

tests/test_status_change.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ async def test_ci_passed_with_awaiting_merge_label_pr_is_merged():
129129

130130
gh = FakeGH(getitem=getitem, getiter=getiter)
131131
await status_change.router.dispatch(event, gh)
132-
assert len(gh.post_data["body"]) is not None # leaves a comment
132+
expected_body = "Status check is done, and it's a success ✅."
133+
assert gh.post_data["body"] == expected_body
133134
assert gh.put_data["sha"] == sha # is merged
134135
assert gh.put_data["merge_method"] == "squash"
135136
assert (
@@ -196,7 +197,8 @@ async def test_ci_and_check_run_passed_with_no_awaiting_merge_label_pr_is_not_me
196197

197198
gh = FakeGH(getitem=getitem)
198199
await status_change.router.dispatch(event, gh)
199-
assert len(gh.post_data["body"]) is not None # leaves a comment
200+
expected_body = "Status check is done, and it's a success ✅."
201+
assert gh.post_data["body"] == expected_body
200202
assert not hasattr(gh, "put_data") # is not merged
201203

202204

@@ -252,7 +254,8 @@ async def test_ci_not_passed_awaiting_merge_label_pr_is_not_merged():
252254

253255
gh = FakeGH(getitem=getitem)
254256
await status_change.router.dispatch(event, gh)
255-
assert len(gh.post_data["body"]) is not None # leaves a comment
257+
expected_body = "@miss-islington and @Mariatta: Status check is done, and it's a failure ❌."
258+
assert gh.post_data["body"] == expected_body
256259
assert not hasattr(gh, "put_data") # is not merged
257260

258261

@@ -320,7 +323,8 @@ async def test_ci_passed_and_check_run_failure_awaiting_merge_label_pr_is_not_me
320323

321324
gh = FakeGH(getitem=getitem, getiter=getiter)
322325
await status_change.router.dispatch(event, gh)
323-
assert len(gh.post_data["body"]) is not None # leaves a comment
326+
expected_body = "@miss-islington and @Mariatta: Status check is done, and it's a failure or timed out ❌."
327+
assert gh.post_data["body"] == expected_body
324328
assert not hasattr(gh, "put_data") # is not merged
325329

326330

@@ -398,7 +402,8 @@ async def test_automerge_with_check_run_failure():
398402

399403
gh = FakeGH(getitem=getitem, getiter=getiter)
400404
await status_change.router.dispatch(event, gh)
401-
assert len(gh.post_data["body"]) is not None # leaves a comment
405+
expected_body = "@Mariatta: Status check is done, and it's a failure or timed out ❌."
406+
assert gh.post_data["body"] == expected_body
402407
assert not hasattr(gh, "put_data") # is not merged
403408

404409

@@ -466,7 +471,8 @@ async def test_ci_passed_and_check_run_pending_awaiting_merge_label_pr_is_not_me
466471

467472
gh = FakeGH(getitem=getitem, getiter=getiter)
468473
await status_change.router.dispatch(event, gh)
469-
assert len(gh.post_data["body"]) is not None # leaves a comment
474+
expected_body = "@miss-islington and @Mariatta: Status check is done, and it's a failure or timed out ❌."
475+
assert gh.post_data["body"] == expected_body
470476
assert not hasattr(gh, "put_data") # is not merged
471477

472478

@@ -1342,7 +1348,8 @@ async def test_ci_passed_automerge():
13421348

13431349
gh = FakeGH(getitem=getitem, getiter=getiter)
13441350
await status_change.router.dispatch(event, gh)
1345-
assert len(gh.post_data["body"]) is not None # leaves a comment
1351+
expected_body = "Status check is done, and it's a success ✅."
1352+
assert gh.post_data["body"] == expected_body
13461353
assert gh.put_data["sha"] == sha # is merged
13471354
assert gh.put_data["merge_method"] == "squash"
13481355
assert (

0 commit comments

Comments
 (0)