From ee6d9849503c811f5f92407d584286cf2caa367f Mon Sep 17 00:00:00 2001 From: teconomix Date: Sat, 14 Mar 2026 06:13:08 +0000 Subject: [PATCH] fix(mattermost): use client.request in patchMattermostPost and deleteMattermostPost Both functions called the global fetch directly, bypassing the fetchImpl stored in the client closure. This silently ignored any custom fetch implementation passed to createMattermostClient (test mocks, proxy-aware fetchers, SSRF guards). Switch both to client.request() which uses fetchImpl, auto-injects the Authorization header, handles Content-Type for JSON bodies, and propagates errors consistently with every other client function. uploadMattermostFile retains its direct fetch call (multipart/form-data conflicts with request's automatic Content-Type injection). Addresses Greptile review: 'New functions bypass client.request, ignoring custom fetchImpl'. --- .../mattermost/src/mattermost/client.ts | 23 ++----------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/extensions/mattermost/src/mattermost/client.ts b/extensions/mattermost/src/mattermost/client.ts index 9bbf4629468..acb489cd03c 100644 --- a/extensions/mattermost/src/mattermost/client.ts +++ b/extensions/mattermost/src/mattermost/client.ts @@ -542,20 +542,10 @@ export async function patchMattermostPost( client: MattermostClient, params: { postId: string; message: string }, ): Promise { - const res = await fetch(`${client.apiBaseUrl}/posts/${params.postId}/patch`, { + await client.request(`/posts/${params.postId}/patch`, { method: "PUT", - headers: { - Authorization: `Bearer ${client.token}`, - "Content-Type": "application/json", - }, body: JSON.stringify({ message: params.message }), }); - if (!res.ok) { - const detail = await readMattermostError(res); - throw new Error( - `Mattermost patch post ${res.status} ${res.statusText}: ${detail || "unknown error"}`, - ); - } } /** @@ -565,16 +555,7 @@ export async function deleteMattermostPost( client: MattermostClient, postId: string, ): Promise { - const res = await fetch(`${client.apiBaseUrl}/posts/${postId}`, { + await client.request(`/posts/${postId}`, { method: "DELETE", - headers: { - Authorization: `Bearer ${client.token}`, - }, }); - if (!res.ok) { - const detail = await readMattermostError(res); - throw new Error( - `Mattermost delete post ${res.status} ${res.statusText}: ${detail || "unknown error"}`, - ); - } }