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
2 changes: 0 additions & 2 deletions src/github/webhook-coalesce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const COALESCABLE_PULL_REQUEST_ACTIONS = new Set([
"synchronize",
"edited",
"ready_for_review",
"labeled",
"unlabeled",
]);

export function githubWebhookCoalesceKey(
Expand Down
38 changes: 38 additions & 0 deletions test/integration/orb-relay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,44 @@ describe("enqueueRelayPending", () => {
expect(JSON.parse(rows.results[0]?.raw_body ?? "{}")).toMatchObject({ marker: "new" });
});

it("does not let label-only PR events coalesce away pending gate-triggering PR events", async () => {
const e = brokeredEnv();
const prBody = (action: string, marker: string) =>
JSON.stringify({
action,
repository: { full_name: "JSONbored/Gittensory" },
pull_request: { number: 1629, head: { sha: "a".repeat(40) } },
marker,
});

await enqueueRelayPending(e, {
deliveryId: "pr-opened-actionable",
installationId: 9608,
eventName: "pull_request",
rawBody: prBody("opened", "actionable"),
});
await enqueueRelayPending(e, {
deliveryId: "pr-labeled-not-actionable",
installationId: 9608,
eventName: "pull_request",
rawBody: prBody("labeled", "label-only"),
});

const events = await pullRelayPending(e, 9608);
expect(events.map((event) => event.deliveryId).sort()).toEqual([
"pr-labeled-not-actionable",
"pr-opened-actionable",
]);
expect(
Object.fromEntries(
events.map((event) => [event.deliveryId, JSON.parse(event.rawBody).action]),
),
).toEqual({
"pr-labeled-not-actionable": "labeled",
"pr-opened-actionable": "opened",
});
});

it("keeps exact duplicate coalescible delivery IDs idempotent", async () => {
const e = brokeredEnv();
const body = (marker: string) =>
Expand Down
18 changes: 10 additions & 8 deletions test/unit/github-webhook-coalesce.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("githubWebhookCoalesceKey", () => {
).toBe("github-webhook:ci-completed:jsonbored/gittensory@def5678");
});

it("coalesces refresh-like pull request events and ignores terminal actions", () => {
it("coalesces gate-triggering pull request events and ignores non-actionable or terminal actions", () => {
expect(
githubWebhookCoalesceKey("pull_request", {
action: "synchronize",
Expand All @@ -40,13 +40,15 @@ describe("githubWebhookCoalesceKey", () => {
pull_request: { number: 100, head: { sha: "BEEF123" } },
} as GitHubWebhookPayload),
).toBe("github-webhook:pr-refresh:jsonbored/gittensory#100@beef123");
expect(
githubWebhookCoalesceKey("pull_request", {
action: "closed",
repository: { full_name: "JSONbored/Gittensory" },
pull_request: { number: 100, head: { sha: "BEEF123" } },
} as GitHubWebhookPayload),
).toBeNull();
for (const action of ["labeled", "unlabeled", "closed"]) {
expect(
githubWebhookCoalesceKey("pull_request", {
action,
repository: { full_name: "JSONbored/Gittensory" },
pull_request: { number: 100, head: { sha: "BEEF123" } },
} as GitHubWebhookPayload),
).toBeNull();
}
});

it("returns null for malformed or non-coalescible webhook shapes", () => {
Expand Down
Loading