From f0e83b5114d67e3ec4446a1fdb27c6b219a56d84 Mon Sep 17 00:00:00 2001
From: "sentry-junior[bot]"
<264270552+sentry-junior[bot]@users.noreply.github.com>
Date: Mon, 30 Nov 2026 12:11:25 +0000
Subject: [PATCH] fix(github): Send a failed merge queue suite to its pull
request
GitHub's merge queue runs a PR's checks on gh-readonly-queue//pr--
and attaches no PR to that check suite, so a failed queue run became a
repository event and pull_request.checks.failed never reached PR N. Map a
failed suite on that branch with no attached PR to PR N, so the existing
checks.failed path handles it. Passing queue suites stay repository events.
---
.../junior-github/src/webhooks/check-suite.ts | 53 ++++++++++++++-----
.../tests/webhook-outcomes.test.ts | 38 +++++++++++++
2 files changed, 77 insertions(+), 14 deletions(-)
diff --git a/packages/junior-github/src/webhooks/check-suite.ts b/packages/junior-github/src/webhooks/check-suite.ts
index dbae1cafe06..3e059e6a51e 100644
--- a/packages/junior-github/src/webhooks/check-suite.ts
+++ b/packages/junior-github/src/webhooks/check-suite.ts
@@ -146,6 +146,37 @@ function isCheckSuiteRepositoryPullRequest(
return pullRequest.base.repo.id === repositoryId;
}
+/**
+ * GitHub's merge queue runs a PR's checks on
+ * `gh-readonly-queue//pr--` and attaches no PR to that suite.
+ * A failed queue run blocks PR N, so it goes to PR N like a failed PR suite.
+ * A passing one needs nothing, so it stays a repository event.
+ */
+const MERGE_QUEUE_BRANCH = /^gh-readonly-queue\/.+\/pr-(\d+)-[0-9a-f]{40}$/;
+
+/** Same-repository PRs of a check suite, or the PR of a failed queue run. */
+function checkSuiteTargetPullRequests(
+ data: z.infer,
+): Array<{ headRef?: string | undefined; number: number }> {
+ const suite = data.check_suite;
+ const attached = suite.pull_requests
+ .filter((pullRequest) =>
+ isCheckSuiteRepositoryPullRequest(pullRequest, data.repository.id),
+ )
+ .map((pullRequest) => ({
+ headRef: pullRequest.head?.ref,
+ number: pullRequest.number,
+ }));
+ if (
+ attached.length > 0 ||
+ checkSuiteEventType(suite.conclusion) !== "pull_request.checks.failed"
+ ) {
+ return attached;
+ }
+ const queued = MERGE_QUEUE_BRANCH.exec(suite.head_branch ?? "")?.[1];
+ return queued ? [{ number: Number(queued) }] : [];
+}
+
type CheckSuiteEventType =
| "pull_request.checks.failed"
| "pull_request.checks.passed"
@@ -527,11 +558,9 @@ export function normalizeCheckSuiteEvents(
repo,
suiteConclusion: conclusion,
} as const;
- const sameRepoPullRequests = suite.pull_requests.filter((pullRequest) =>
- isCheckSuiteRepositoryPullRequest(pullRequest, repository.id),
- );
+ const targetPullRequests = checkSuiteTargetPullRequests(parsed.data);
// No same-repo PR (common on main): one repository event with headBranch.
- if (sameRepoPullRequests.length === 0) {
+ if (targetPullRequests.length === 0) {
return eventTypes.map((type) =>
buildCheckSuiteEvent({
...shared,
@@ -541,10 +570,10 @@ export function normalizeCheckSuiteEvents(
);
}
return eventTypes.flatMap((type) =>
- sameRepoPullRequests.flatMap((pullRequest) => {
+ targetPullRequests.flatMap((pullRequest) => {
const facts = options?.pullRequestFactsByNumber?.[pullRequest.number];
const pullRequestHeadBranch =
- checkSuiteHeadBranch(pullRequest.head?.ref) ?? headBranch;
+ checkSuiteHeadBranch(pullRequest.headRef) ?? headBranch;
return pullRequestTargets(
buildCheckSuiteEvent({
...shared,
@@ -603,9 +632,7 @@ export function parseCheckSuitePublishTargets(body: unknown):
const identifiers = new Set([
gitHubRepositoryResource({ repo }).identifier,
]);
- for (const pullRequest of parsed.data.check_suite.pull_requests) {
- if (!isCheckSuiteRepositoryPullRequest(pullRequest, repository.id))
- continue;
+ for (const pullRequest of checkSuiteTargetPullRequests(parsed.data)) {
identifiers.add(
gitHubPullRequestResource({ number: pullRequest.number, repo })
.identifier,
@@ -680,11 +707,9 @@ export function parseCheckSuiteFactsTarget(
const repository = parsed.data.repository;
const pullRequestNumbers = [
...new Set(
- parsed.data.check_suite.pull_requests
- .filter((pullRequest) =>
- isCheckSuiteRepositoryPullRequest(pullRequest, repository.id),
- )
- .map((pullRequest) => pullRequest.number),
+ checkSuiteTargetPullRequests(parsed.data).map(
+ (pullRequest) => pullRequest.number,
+ ),
),
];
const loadFailingChecks =
diff --git a/packages/junior-github/tests/webhook-outcomes.test.ts b/packages/junior-github/tests/webhook-outcomes.test.ts
index 8b8f8aa05d0..1750bfb31b9 100644
--- a/packages/junior-github/tests/webhook-outcomes.test.ts
+++ b/packages/junior-github/tests/webhook-outcomes.test.ts
@@ -935,6 +935,44 @@ describe("GitHub webhook events", () => {
]);
});
+ it("sends a failed merge queue suite to the queued pull request", () => {
+ const queueSuite = (conclusion: string) => ({
+ action: "completed",
+ repository: checkSuiteRepository("getsentry/junior"),
+ check_suite: {
+ app: { name: "GitHub Actions" },
+ conclusion,
+ head_branch:
+ "gh-readonly-queue/main/pr-4703-9cc58e1d1f2a3b4c5d6e7f8091a2b3c4d5e6f708",
+ head_sha: "abcdef1234567890",
+ id: 77,
+ pull_requests: [],
+ },
+ });
+ const failed = queueSuite("failure");
+ expect(parseCheckSuitePublishTargets(failed)?.identifiers).toContain(
+ "getsentry/junior#4703",
+ );
+ expect(
+ normalizeGitHubEvents({
+ body: failed,
+ deliveryId: "delivery-queue",
+ eventName: "check_suite",
+ }).map((event) => [event.identifier, event.eventType]),
+ ).toEqual([
+ ["getsentry/junior#4703", "pull_request.checks.failed"],
+ ["getsentry/junior", "pull_request.checks.failed"],
+ ]);
+ // A passing queue run needs no fix, so it stays a repository event.
+ expect(
+ normalizeGitHubEvents({
+ body: queueSuite("success"),
+ deliveryId: "delivery-queue-green",
+ eventName: "check_suite",
+ }).map((event) => event.identifier),
+ ).toEqual(["getsentry/junior"]);
+ });
+
it("attaches headBranch from the check suite webhook without a pull request API load", () => {
expect(needsCheckSuitePullRequestFacts(["headBranch"])).toBe(false);
expect(