Skip to content

Commit dc67f1e

Browse files
authored
Fix Automerge functionality (#382)
* Fix Automerge functionality Look up conclusions from check runs in addition to status checks. Ensure all check runs have completed. Ensure there is no "failure" or "timed_out" result from the check runs Fixes python/miss-islington#375 * 🐍🌚🤖 Formatted using `black`.
1 parent 9efdd5d commit dc67f1e

File tree

3 files changed

+381
-71
lines changed

3 files changed

+381
-71
lines changed

miss_islington/status_change.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import re
22

33
import gidgethub
4-
54
from gidgethub import routing
65

76
from . import util
@@ -94,12 +93,22 @@ async def check_ci_status_and_approval(
9493

9594
result = await gh.getitem(f"/repos/python/cpython/commits/{sha}/status")
9695
all_ci_status = [status["state"] for status in result["statuses"]]
97-
all_ci_context = [status["context"] for status in result["statuses"]]
96+
97+
check_runs = await util.get_check_runs_for_sha(gh, sha)
98+
99+
all_check_run_status = [
100+
check_run["status"] for check_run in check_runs["check_runs"]
101+
]
102+
all_check_run_conclusions = [
103+
check_run["conclusion"] for check_run in check_runs["check_runs"]
104+
]
98105

99106
if (
100107
"pending" not in all_ci_status
101-
and "continuous-integration/travis-ci/pr" in all_ci_context
102-
):
108+
and "in_progress" not in all_check_run_status
109+
and "queued" not in all_check_run_status
110+
): # wait until all status and check runs are completed
111+
103112
if not pr_for_commit:
104113
pr_for_commit = await util.get_pr_for_commit(gh, sha)
105114
if pr_for_commit:
@@ -110,6 +119,10 @@ async def check_ci_status_and_approval(
110119

111120
title_match = TITLE_RE.match(normalized_pr_title)
112121
if title_match or is_automerge:
122+
success = result["state"] == "success" and not any(
123+
elem in [None, "failure", "timed_out"]
124+
for elem in all_check_run_conclusions
125+
)
113126
if leave_comment:
114127
if is_automerge:
115128
participants = await util.get_gh_participants(gh, pr_number)
@@ -118,16 +131,16 @@ async def check_ci_status_and_approval(
118131
participants = await util.get_gh_participants(
119132
gh, original_pr_number
120133
)
121-
122-
emoji = "✅" if result["state"] == "success" else "❌"
123-
134+
if success:
135+
emoji = "✅"
136+
else:
137+
emoji = "❌"
124138
await util.leave_comment(
125139
gh,
126140
pr_number=pr_number,
127141
message=f"{participants}: Status check is done, and it's a {result['state']} {emoji} .",
128142
)
129-
if result["state"] == "success":
130-
143+
if success:
131144
if util.pr_is_awaiting_merge(pr_for_commit["labels"]):
132145
await merge_pr(
133146
gh, pr_for_commit, sha, is_automerge=is_automerge

miss_islington/util.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from .status_change import AUTOMERGE_TRAILER
77

8-
98
AUTOMERGE_LABEL = ":robot: automerge"
109

1110

@@ -163,3 +162,10 @@ async def remove_automerge(gh, pr_data):
163162
f"{pr_data['issue_url']}/labels/{AUTOMERGE_LABEL}",
164163
accept="application/vnd.github.symmetra-preview+json",
165164
)
165+
166+
167+
async def get_check_runs_for_sha(gh, sha):
168+
return await gh.getitem(
169+
f"/repos/python/cpython/commits/{sha}/check-runs",
170+
accept="application/vnd.github.antiope-preview+json",
171+
)

0 commit comments

Comments
 (0)