* Best-effort cleanup that deletes any project hook pointing at `url`. Used to * avoid orphaning a hook when the create response can't be parsed for its id.
( projectId: string, accessToken: string, url: string, host: unknown )
| 31 | * avoid orphaning a hook when the create response can't be parsed for its id. |
| 32 | */ |
| 33 | async function cleanupGitLabHookByUrl( |
| 34 | projectId: string, |
| 35 | accessToken: string, |
| 36 | url: string, |
| 37 | host: unknown |
| 38 | ): Promise<void> { |
| 39 | const res = await secureFetchWithValidation(gitlabProjectHooksUrl(projectId, host), { |
| 40 | headers: { 'PRIVATE-TOKEN': accessToken }, |
| 41 | }).catch(() => null) |
| 42 | if (!res || !res.ok) return |
| 43 | |
| 44 | const hooks = (await res.json().catch(() => null)) as Array<{ id?: number; url?: string }> | null |
| 45 | if (!Array.isArray(hooks)) return |
| 46 | |
| 47 | await Promise.all( |
| 48 | hooks |
| 49 | .filter((hook) => hook.url === url && hook.id != null) |
| 50 | .map((hook) => |
| 51 | secureFetchWithValidation(`${gitlabProjectHooksUrl(projectId, host)}/${hook.id}`, { |
| 52 | method: 'DELETE', |
| 53 | headers: { 'PRIVATE-TOKEN': accessToken }, |
| 54 | }).catch(() => null) |
| 55 | ) |
| 56 | ) |
| 57 | } |
| 58 | |
| 59 | export const gitlabHandler: WebhookProviderHandler = { |
| 60 | /** |
no test coverage detected