(ctx: DeleteSubscriptionContext)
| 174 | }, |
| 175 | |
| 176 | async deleteSubscription(ctx: DeleteSubscriptionContext): Promise<void> { |
| 177 | const config = getProviderConfig(ctx.webhook) |
| 178 | const accessToken = config.accessToken as string | undefined |
| 179 | const projectId = config.projectId as string | undefined |
| 180 | const externalId = config.externalId as string | undefined |
| 181 | const host = config.host as string | undefined |
| 182 | |
| 183 | if (!accessToken || !projectId || !externalId) { |
| 184 | if (ctx.strict) throw new Error('Missing GitLab credentials or hook ID for webhook deletion.') |
| 185 | logger.warn( |
| 186 | `[${ctx.requestId}] Skipping GitLab webhook cleanup — missing token, project, or hook ID` |
| 187 | ) |
| 188 | return |
| 189 | } |
| 190 | |
| 191 | // A structurally unsafe host must not abort cleanup in non-strict mode — mirror |
| 192 | // the graceful skip used for missing credentials above. |
| 193 | try { |
| 194 | getGitLabApiBase(host) |
| 195 | } catch (error) { |
| 196 | if (error instanceof UnsafeGitLabHostError) { |
| 197 | if (ctx.strict) { |
| 198 | throw new Error('Cannot delete GitLab webhook: the configured host is invalid.') |
| 199 | } |
| 200 | logger.warn( |
| 201 | `[${ctx.requestId}] Skipping GitLab webhook cleanup — configured host is invalid` |
| 202 | ) |
| 203 | return |
| 204 | } |
| 205 | throw error |
| 206 | } |
| 207 | |
| 208 | const res = await secureFetchWithValidation( |
| 209 | `${gitlabProjectHooksUrl(projectId, host)}/${externalId}`, |
| 210 | { |
| 211 | method: 'DELETE', |
| 212 | headers: { 'PRIVATE-TOKEN': accessToken }, |
| 213 | } |
| 214 | ) |
| 215 | |
| 216 | if (!res.ok && res.status !== 404) { |
| 217 | if (ctx.strict) throw new Error(`Failed to delete GitLab webhook: ${res.status}`) |
| 218 | logger.warn( |
| 219 | `[${ctx.requestId}] Failed to delete GitLab webhook ${externalId} (non-fatal): ${res.status}` |
| 220 | ) |
| 221 | return |
| 222 | } |
| 223 | logger.info(`[${ctx.requestId}] Deleted GitLab webhook ${externalId}`) |
| 224 | }, |
| 225 | } |
nothing calls this directly
no test coverage detected