Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions pr_review_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,21 @@ def get_check_runs(github_api, repo, head):
"""
check_runs = github_api.checks.list_for_ref(repo=repo,ref=head, per_page=100)
runs = check_runs["check_runs"]
total_count = check_runs["total_count"]
successful_runs = 0

for run in runs:
if run['status'] == "completed" and run['conclusion'] == "success":
successful_runs += 1

if successful_runs == len(runs):
status = f"success ({successful_runs}/{len(runs)})"
if successful_runs == total_count:
status = "success"
state = "🟢"
elif successful_runs < len(runs):
status = f"failure ({successful_runs}/{len(runs)})"
elif successful_runs < total_count:
status = "failure"
state = "🔴"
else:
print(f"Warning: something is terribly wrong: successful runs ({successful_runs}) should never be more than total runs ({len(runs)}).")
print(f"Warning: something is terribly wrong: successful runs ({successful_runs}) should never be more than total runs ({total_count}).")
sys.exit(1)

return status, state
Expand All @@ -76,22 +77,37 @@ def get_commit_status(github_api, repo, pull_request_details):
Check whether the HEAD commit has passed the CI tests
"""
head = pull_request_details["head"]
combined_status = "failure" # failure by default

# Check GitHub run status
check_run_status, state = get_check_runs(github_api, repo, head["sha"])
# Exit early if there are failed check runs
if check_run_status == "failure":
return combined_status, state

# Check external CI status
status = github_api.repos.get_combined_status_for_ref(repo=repo,ref=head["sha"])
if status.state == "success":

if (status.state == "success" and
check_run_status == "success"):
state = "🟢"
combined_status = "success"
elif status.state == "failure":
state = "🔴"
# For simplicity, we consider "pending" as "failure" unless there are check runs
elif status.state == "pending":
state = "🟠"
# Check if the state is not really 'pending' but if there is none
# Check if the state is not really 'pending' but if there is actually none
single_status = github_api.repos.list_commit_statuses_for_ref(repo=repo,ref=head["sha"])
if single_status == []:
status.state, state = get_check_runs(github_api, repo, head["sha"])
# The combined_status should still be a success if all check runs have passed
if check_run_status == "success":
state = "🟢"
combined_status = "success"
else:
state = status.state

return status.state, state
return combined_status, state


def get_archived_repos(github_api, org):
Expand Down