From 98316359294e02d7258ef8f454733813ee0a500c Mon Sep 17 00:00:00 2001 From: Lokesh Kaki Date: Sun, 15 Mar 2026 21:19:59 -0500 Subject: [PATCH] fix(catalog-backend-module-gitlab): fix bridge race condition, remove unused logger and dead PathState variant Signed-off-by: Lokesh Kaki --- .../src/events/GitLabScmEventsBridge.ts | 13 +++----- .../src/events/analyzeGitLabWebhookEvent.ts | 31 +++++++++---------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/plugins/catalog-backend-module-gitlab/src/events/GitLabScmEventsBridge.ts b/plugins/catalog-backend-module-gitlab/src/events/GitLabScmEventsBridge.ts index 34b9b5c9c2..1809b31156 100644 --- a/plugins/catalog-backend-module-gitlab/src/events/GitLabScmEventsBridge.ts +++ b/plugins/catalog-backend-module-gitlab/src/events/GitLabScmEventsBridge.ts @@ -99,10 +99,6 @@ export class GitLabScmEventsBridge { return; } - while (this.#pendingPublish) { - await this.#pendingPublish; - } - if (this.#shuttingDown) { this.#logger.warn( `Skipping GitLab webhook event of type "${eventType}" on topic "${params.topic}" because the bridge is shutting down`, @@ -110,7 +106,8 @@ export class GitLabScmEventsBridge { return; } - this.#pendingPublish = Promise.resolve().then(async () => { + const previous = this.#pendingPublish ?? Promise.resolve(); + const current = previous.then(async () => { try { const output = await analyzeGitLabWebhookEvent( eventType, @@ -143,10 +140,10 @@ export class GitLabScmEventsBridge { error, ); } finally { - this.#pendingPublish = undefined; + // no-op; chain handles ordering } }); - - await this.#pendingPublish; + this.#pendingPublish = current; + await current; } } \ No newline at end of file diff --git a/plugins/catalog-backend-module-gitlab/src/events/analyzeGitLabWebhookEvent.ts b/plugins/catalog-backend-module-gitlab/src/events/analyzeGitLabWebhookEvent.ts index 6b2d44ddd6..77f11f6432 100644 --- a/plugins/catalog-backend-module-gitlab/src/events/analyzeGitLabWebhookEvent.ts +++ b/plugins/catalog-backend-module-gitlab/src/events/analyzeGitLabWebhookEvent.ts @@ -53,10 +53,6 @@ type PathState = type: 'removed'; commitUrl?: string; } - | { - type: 'modified'; - commitUrl?: string; - } | { type: 'renamed'; fromPath: string; @@ -173,12 +169,6 @@ function pathStateToCatalogScmEvent( url: toBlobUrl(path), context, }; - case 'modified': - return { - type: 'location.updated', - url: toBlobUrl(path), - context, - }; case 'renamed': return { type: 'location.moved', @@ -520,16 +510,23 @@ export async function analyzeGitLabWebhookEvent( throw new InputError('GitLab webhook event payload is not an object'); } + let result: AnalyzeWebhookEventResult; + if (eventType === 'push') { - return onPushEvent(eventPayload as unknown as WebhookPushEventSchema, options); + result = await onPushEvent(eventPayload as unknown as WebhookPushEventSchema, options); + } else if (eventType === 'repository_update') { + result = await onRepositoryUpdateEvent(eventPayload as GitLabRepositoryUpdateEvent); + } else { + result = { result: 'unsupported-event', event: eventType }; } - if (eventType === 'repository_update') { - return onRepositoryUpdateEvent(eventPayload as GitLabRepositoryUpdateEvent); + if (result.result === 'ignored') { + options.logger?.debug(`GitLab webhook event ignored: ${result.reason}`); + } else if (result.result === 'aborted') { + options.logger?.debug(`GitLab webhook event aborted: ${result.reason}`); + } else if (result.result === 'unsupported-event') { + options.logger?.debug(`GitLab webhook event unsupported: ${result.event}`); } - return { - result: 'unsupported-event', - event: eventType, - }; + return result; } \ No newline at end of file