Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions .github/workflows/merge-bot-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ jobs:
passing_since=0
while :; do
read_pr
read_api "the head's check runs" "checks: read" gh api --paginate "repos/$REPO/commits/$HEAD_SHA/check-runs?per_page=100" --jq '.check_runs[] | {id, name, status, conclusion}'
# A re-run leaves its earlier attempt on the head, so only the newest run of each name counts.
runs=$(jq -sc 'group_by(.name) | map(max_by(.id))[]' <<<"$out")
read_api "the head's check runs" "checks: read" gh api --paginate "repos/$REPO/commits/$HEAD_SHA/check-runs?per_page=100" --jq '.check_runs[] | {id, name, status, conclusion, app: .app.id}'
# A re-run leaves its earlier attempt on the head, so only the newest run counts.
# A run is keyed by App and name, so another App's passing run never hides a failure.
runs=$(jq -sc 'group_by([.app, .name]) | map(max_by(.id))[]' <<<"$out")
read_api "the head's commit statuses" "statuses: read" gh api --paginate "repos/$REPO/commits/$HEAD_SHA/status?per_page=100" --jq '.statuses[] | {name: .context, status: (if .state == "pending" then "pending" else "completed" end), conclusion: .state}'
# This workflow's own jobs post on the head too, as a caller job name, a slash, and the job name, so the wait leaves them out.
checks=$(jq -sc --argjson own "$OWN_JOBS" '
Expand Down
23 changes: 21 additions & 2 deletions tests/test_merge_bot_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,19 @@


def check_run(
name: str, status: str = "completed", conclusion: str | None = "success", run_id: int = 1
name: str,
status: str = "completed",
conclusion: str | None = "success",
run_id: int = 1,
app_id: int = 1,
) -> dict[str, Any]:
return {"id": run_id, "name": name, "status": status, "conclusion": conclusion}
return {
"id": run_id,
"name": name,
"status": status,
"conclusion": conclusion,
"app": {"id": app_id},
}


def runs(*checks: dict[str, Any]) -> dict[str, Any]:
Expand Down Expand Up @@ -328,6 +338,15 @@ def test_only_the_newest_run_of_a_re_run_check_counts(self) -> None:
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
self.assertEqual(1, len(self.merges(calls)))

def test_a_passing_run_of_another_app_does_not_hide_a_failed_one(self) -> None:
failed = check_run("Lint job", conclusion="failure", run_id=1, app_id=1)
result, calls = self.merge(
UNREQUIRED, [runs(check_run("Lint job", run_id=2, app_id=2), failed)]
)
self.assertEqual(1, result.returncode, result.stdout + result.stderr)
self.assertIn("Lint job (failure)", result.stdout + result.stderr)
self.assertEqual(0, len(self.merges(calls)))

def test_a_pull_request_closed_during_the_merge_retry_ends_without_failing(self) -> None:
refused = {"error": "GraphQL: Pull request is closed"}
closed = {"json": {**OPEN, "state": "closed"}}
Expand Down
Loading