From 8cf1a5f1810f113f3f67b908ba9f2e32e7bad64b Mon Sep 17 00:00:00 2001 From: Nalla Prakash <81852531+prakashNalla@users.noreply.github.com> Date: Thu, 29 Oct 2026 22:38:44 +0530 Subject: [PATCH] fix: post prereleases once they're promoted to a full release --- src/webhook.ts | 2 +- test/index.test.ts | 2 +- test/webhook.test.ts | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/webhook.ts b/src/webhook.ts index 019f412..e32f604 100644 --- a/src/webhook.ts +++ b/src/webhook.ts @@ -62,7 +62,7 @@ export async function handleGithubEvent(event: string, payload: unknown, env: En } async function onRelease(e: ReleaseEvent, env: Env, cfg: Config): Promise { - if (e.action !== "published" || e.release.draft || e.release.prerelease || !ours(cfg, e.repository)) { + if (e.action !== "released" || e.release.draft || e.release.prerelease || !ours(cfg, e.repository)) { return "ignored release"; } await sendMessage(env, env.CHANNEL_RELEASES, releaseMessage(e.repository.name, e.release)); diff --git a/test/index.test.ts b/test/index.test.ts index c4da0ae..964a12a 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -250,7 +250,7 @@ describe("POST /github", () => { globalThis.fetch = (async () => new Response("nope", { status: 500 })) as typeof fetch; const { ctx } = makeCtx(); const body = { - action: "published", + action: "released", repository: { name: "toolbelt", owner: { login: "codercops" } }, release: { name: "v1", tag_name: "v1", body: "", html_url: "https://github.com/codercops/toolbelt/releases/tag/v1", draft: false, prerelease: false }, }; diff --git a/test/webhook.test.ts b/test/webhook.test.ts index e2e9b97..1db29d5 100644 --- a/test/webhook.test.ts +++ b/test/webhook.test.ts @@ -301,9 +301,9 @@ describe("starter issue feed", () => { describe("releases", () => { const release = { name: "v0.6.2", tag_name: "v0.6.2", body: "Fixes", html_url: "https://github.com/codercops/toolbelt/releases/tag/v0.6.2", draft: false, prerelease: false }; - it("posts published releases to the releases channel", async () => { + it("posts releases to the releases channel", async () => { const fetched = mockFetch(); - expect(await handleGithubEvent("release", { action: "published", repository, release }, env, cfg)).toBe("posted release"); + expect(await handleGithubEvent("release", { action: "released", repository, release }, env, cfg)).toBe("posted release"); expect(fetched.discord()[0]?.url).toBe("https://discord.com/api/v10/channels/chan-releases/messages"); expect(fetched.discord()[0]?.body.embeds[0].title).toBe("toolbelt v0.6.2"); }); @@ -311,10 +311,19 @@ describe("releases", () => { it("ignores drafts, prereleases and other actions", async () => { const fetched = mockFetch(); await handleGithubEvent("release", { action: "created", repository, release }, env, cfg); - await handleGithubEvent("release", { action: "published", repository, release: { ...release, draft: true } }, env, cfg); - await handleGithubEvent("release", { action: "published", repository, release: { ...release, prerelease: true } }, env, cfg); + await handleGithubEvent("release", { action: "published", repository, release }, env, cfg); + await handleGithubEvent("release", { action: "released", repository, release: { ...release, draft: true } }, env, cfg); + await handleGithubEvent("release", { action: "released", repository, release: { ...release, prerelease: true } }, env, cfg); expect(fetched.discord()).toHaveLength(0); }); + + it("posts a prerelease once it's promoted to a full release", async () => { + const fetched = mockFetch(); + await handleGithubEvent("release", { action: "published", repository, release: { ...release, prerelease: true } }, env, cfg); + await handleGithubEvent("release", { action: "edited", repository, release }, env, cfg); + expect(await handleGithubEvent("release", { action: "released", repository, release }, env, cfg)).toBe("posted release"); + expect(fetched.discord()).toHaveLength(1); + }); }); describe("merged pull requests", () => {