Skip to content
Open
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: 1 addition & 1 deletion src/lib/adapters/definitions/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const TeamsSchema = z.object({

export const GenericWebhookSchema = z.object({
webhookUrl: z.string().url("Valid URL is required"),
method: z.enum(["POST", "PUT", "PATCH"]).default("POST").describe("HTTP method"),
method: z.enum(["POST", "PUT", "PATCH", "GET", "HEAD"]).default("POST").describe("HTTP method"),
contentType: z.string().default("application/json").describe("Content-Type header"),
authHeader: z.string().optional().describe("Authorization header value (e.g. Bearer token)"),
customHeaders: z.string().optional().describe("Additional headers (one per line, Key: Value)"),
Expand Down
22 changes: 12 additions & 10 deletions src/lib/adapters/notification/generic-webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ export const GenericWebhookAdapter: NotificationAdapter = {
fields: [],
});

const response = await fetch(config.webhookUrl, {
method: config.method || "POST",
headers,
body,
});
const method = (config.method || "POST").toUpperCase();
const fetchOpts: RequestInit = { method, headers };
if (method !== "GET" && method !== "HEAD") {
fetchOpts.body = body;
}
const response = await fetch(config.webhookUrl, fetchOpts);

if (response.ok) {
return { success: true, message: `Webhook returned ${response.status}` };
Expand Down Expand Up @@ -114,11 +115,12 @@ export const GenericWebhookAdapter: NotificationAdapter = {
});
}

const response = await fetch(config.webhookUrl, {
method: config.method || "POST",
headers,
body,
});
const method = (config.method || "POST").toUpperCase();
const fetchOpts: RequestInit = { method, headers };
if (method !== "GET" && method !== "HEAD") {
fetchOpts.body = body;
}
const response = await fetch(config.webhookUrl, fetchOpts);

if (!response.ok) {
const responseBody = await response.text().catch(() => "");
Expand Down
5 changes: 4 additions & 1 deletion src/lib/runner/steps/04-completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,17 @@ export async function stepFinalize(ctx: RunnerContext) {
});
}

await notifyWithTimeout(() => notifyAdapter.send(channelConfig, payload.message, {
const sent = await notifyWithTimeout(() => notifyAdapter.send(channelConfig, payload.message, {
success: payload.success,
eventType,
title: payload.title,
fields: payload.fields,
color: payload.color,
badge: payload.badge,
}));
if (sent === false) {
throw new Error("Notification delivery failed (adapter returned false)");
}

await recordNotificationLog({
eventType,
Expand Down
5 changes: 4 additions & 1 deletion src/services/notifications/system-notification-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,17 @@ async function sendThroughChannel(
}

try {
await notifyWithTimeout(() => adapter.send(channelConfig, payload.message, {
const sent = await notifyWithTimeout(() => adapter.send(channelConfig, payload.message, {
success: payload.success,
eventType,
title: payload.title,
fields: payload.fields,
color: payload.color,
badge: payload.badge,
}));
if (sent === false) {
throw new Error("Notification delivery failed (adapter returned false)");
}

// Record successful send
await recordNotificationLog({
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/adapters/notification/generic-webhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,28 @@ describe("Generic Webhook Adapter", () => {

expect(result).toBe(false);
});

it("should omit body when method is GET or HEAD", async () => {
mockFetch.mockResolvedValue({ ok: true });

await GenericWebhookAdapter.send({ ...baseConfig, method: "GET" as any }, "Test message");
expect(mockFetch.mock.calls[0][1].method).toBe("GET");
expect(mockFetch.mock.calls[0][1].body).toBeUndefined();

await GenericWebhookAdapter.send({ ...baseConfig, method: "HEAD" as any }, "Test message");
expect(mockFetch.mock.calls[1][1].method).toBe("HEAD");
expect(mockFetch.mock.calls[1][1].body).toBeUndefined();
});
});

describe("test() with GET/HEAD", () => {
it("should omit body when method is GET in test()", async () => {
mockFetch.mockResolvedValue({ ok: true, status: 200 });

const result = await GenericWebhookAdapter.test!({ ...baseConfig, method: "GET" as any });
expect(result.success).toBe(true);
expect(mockFetch.mock.calls[0][1].method).toBe("GET");
expect(mockFetch.mock.calls[0][1].body).toBeUndefined();
});
});
});
Loading