fix(catalog-backend-module-gitlab): fix bridge race condition, remove unused logger and dead PathState variant
Signed-off-by: Lokesh Kaki <lokeshkaki1@gmail.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user