diff --git a/src/api/routes.ts b/src/api/routes.ts index c2273965cf..03cef90de1 100644 --- a/src/api/routes.ts +++ b/src/api/routes.ts @@ -715,7 +715,7 @@ const repositoryAiReviewSchema = z.object({ provider: z.enum(["anthropic", "openai"]).nullable().optional(), model: z.string().trim().min(1).max(120).nullable().optional(), allAuthors: z.boolean().default(false), - closeOwnerAuthors: z.boolean().default(false), + closeOwnerAuthors: z.boolean().optional(), }); const contributorIssueDraftGenerateSchema = z.object({ @@ -2253,7 +2253,7 @@ export function createApp() { aiReviewProvider: parsed.data.provider, aiReviewModel: parsed.data.model, aiReviewAllAuthors: parsed.data.allAuthors, - closeOwnerAuthors: parsed.data.closeOwnerAuthors, + closeOwnerAuthors: parsed.data.closeOwnerAuthors ?? current.closeOwnerAuthors, }); // getRepositorySettings normalizes these to a concrete value or null (never undefined). return c.json({ diff --git a/test/unit/routes-ai-byok.test.ts b/test/unit/routes-ai-byok.test.ts index 5fe0dcde82..bd144f8325 100644 --- a/test/unit/routes-ai-byok.test.ts +++ b/test/unit/routes-ai-byok.test.ts @@ -62,6 +62,22 @@ describe("maintainer AI-review config route", () => { expect((await getRepositorySettings(env, REPO)).closeOwnerAuthors).toBe(false); }); + it("preserves closeOwnerAuthors when an AI-review update omits it", async () => { + const app = createApp(); + const env = createTestEnv({ TOKEN_ENCRYPTION_SECRET: SECRET }); + await upsertRepositorySettings(env, { repoFullName: REPO, closeOwnerAuthors: true }); + + const res = await app.request( + `/v1/repos/${REPO}/ai-review`, + { method: "PUT", headers: apiHeaders(env), body: JSON.stringify({ mode: "advisory", byok: false }) }, + env, + ); + + expect(res.status).toBe(200); + expect(await res.json()).toMatchObject({ aiReviewMode: "advisory", closeOwnerAuthors: true }); + expect((await getRepositorySettings(env, REPO)).closeOwnerAuthors).toBe(true); + }); + it("accepts a config without provider/model (stored as null)", async () => { const app = createApp(); const env = createTestEnv({ TOKEN_ENCRYPTION_SECRET: SECRET });