From 1759bfefc817bd7ac0e95a7dcf535b774d63b03a Mon Sep 17 00:00:00 2001 From: Lokesh Kaki Date: Tue, 17 Mar 2026 19:35:43 -0500 Subject: [PATCH] fix(catalog-backend-module-gitlab): fix prettier formatting, export alpha types, and add API reports - Run prettier on changed files (GitLabScmEventsBridge, analyzeGitLabWebhookEvent, test files) - Export AnalyzeWebhookEventOptions and AnalyzeWebhookEventResult from alpha entry point - Add @alpha JSDoc tags to exported types and function - Regenerate report-alpha.api.md with updated API surface Signed-off-by: Lokesh Kaki --- .../report-alpha.api.md | 36 +++++++++++++++++++ .../src/alpha.ts | 6 +++- .../src/events/GitLabScmEventsBridge.ts | 2 +- .../events/analyzeGitLabWebhookEvent.test.ts | 2 +- .../src/events/analyzeGitLabWebhookEvent.ts | 31 ++++++++++------ 5 files changed, 64 insertions(+), 13 deletions(-) diff --git a/plugins/catalog-backend-module-gitlab/report-alpha.api.md b/plugins/catalog-backend-module-gitlab/report-alpha.api.md index e8ef479d82..00e452642e 100644 --- a/plugins/catalog-backend-module-gitlab/report-alpha.api.md +++ b/plugins/catalog-backend-module-gitlab/report-alpha.api.md @@ -4,6 +4,42 @@ ```ts import { BackendFeature } from '@backstage/backend-plugin-api'; +import { CatalogScmEvent } from '@backstage/plugin-catalog-node/alpha'; +import { LoggerService } from '@backstage/backend-plugin-api'; + +// @alpha (undocumented) +export function analyzeGitLabWebhookEvent( + eventType: string, + eventPayload: unknown, + options: AnalyzeWebhookEventOptions, +): Promise; + +// @alpha (undocumented) +export interface AnalyzeWebhookEventOptions { + // (undocumented) + isRelevantPath: (path: string) => boolean; + // (undocumented) + logger?: LoggerService; +} + +// @alpha (undocumented) +export type AnalyzeWebhookEventResult = + | { + result: 'unsupported-event'; + event: string; + } + | { + result: 'ignored'; + reason: string; + } + | { + result: 'aborted'; + reason: string; + } + | { + result: 'ok'; + events: CatalogScmEvent[]; + }; // @alpha (undocumented) const _feature: BackendFeature; diff --git a/plugins/catalog-backend-module-gitlab/src/alpha.ts b/plugins/catalog-backend-module-gitlab/src/alpha.ts index 0b29a09ba9..aaf5096742 100644 --- a/plugins/catalog-backend-module-gitlab/src/alpha.ts +++ b/plugins/catalog-backend-module-gitlab/src/alpha.ts @@ -20,4 +20,8 @@ import { catalogModuleGitlabDiscoveryEntityProvider } from './module/catalogModu const _feature = catalogModuleGitlabDiscoveryEntityProvider; export default _feature; -export { analyzeGitLabWebhookEvent } from './events/analyzeGitLabWebhookEvent'; +export { + analyzeGitLabWebhookEvent, + type AnalyzeWebhookEventOptions, + type AnalyzeWebhookEventResult, +} from './events/analyzeGitLabWebhookEvent'; diff --git a/plugins/catalog-backend-module-gitlab/src/events/GitLabScmEventsBridge.ts b/plugins/catalog-backend-module-gitlab/src/events/GitLabScmEventsBridge.ts index 1809b31156..1e44ffcf72 100644 --- a/plugins/catalog-backend-module-gitlab/src/events/GitLabScmEventsBridge.ts +++ b/plugins/catalog-backend-module-gitlab/src/events/GitLabScmEventsBridge.ts @@ -146,4 +146,4 @@ export class GitLabScmEventsBridge { this.#pendingPublish = current; await current; } -} \ No newline at end of file +} diff --git a/plugins/catalog-backend-module-gitlab/src/events/analyzeGitLabWebhookEvent.test.ts b/plugins/catalog-backend-module-gitlab/src/events/analyzeGitLabWebhookEvent.test.ts index bda802d67a..8e792f1822 100644 --- a/plugins/catalog-backend-module-gitlab/src/events/analyzeGitLabWebhookEvent.test.ts +++ b/plugins/catalog-backend-module-gitlab/src/events/analyzeGitLabWebhookEvent.test.ts @@ -255,4 +255,4 @@ describe('analyzeGitLabWebhookEvent', () => { }), ).rejects.toBeInstanceOf(InputError); }); -}); \ 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 77f11f6432..2ca7a14a6a 100644 --- a/plugins/catalog-backend-module-gitlab/src/events/analyzeGitLabWebhookEvent.ts +++ b/plugins/catalog-backend-module-gitlab/src/events/analyzeGitLabWebhookEvent.ts @@ -21,11 +21,13 @@ import { WebhookPushEventSchema } from '@gitbeaker/rest'; type StringRecord = Record; +/** @alpha */ export interface AnalyzeWebhookEventOptions { logger?: LoggerService; isRelevantPath: (path: string) => boolean; } +/** @alpha */ export type AnalyzeWebhookEventResult = | { result: 'unsupported-event'; @@ -135,9 +137,10 @@ function extractBranchName(ref?: string): string | undefined { return ref.slice('refs/heads/'.length); } -function getCommitUrl(commit: GitLabPushCommit, repositoryUrl?: string): - | string - | undefined { +function getCommitUrl( + commit: GitLabPushCommit, + repositoryUrl?: string, +): string | undefined { if (commit.url) { return commit.url; } @@ -297,9 +300,9 @@ async function onPushEvent( } } - const commits = (Array.isArray(event.commits) - ? event.commits - : []) as GitLabPushCommit[]; + const commits = ( + Array.isArray(event.commits) ? event.commits : [] + ) as GitLabPushCommit[]; if (!commits.length) { return { @@ -427,7 +430,9 @@ function getPreviousRepositoryUrl( return toRepositoryUrl(baseUrl, oldPathWithNamespace); } -function isRepositoryDeletionEvent(event: GitLabRepositoryUpdateEvent): boolean { +function isRepositoryDeletionEvent( + event: GitLabRepositoryUpdateEvent, +): boolean { const eventName = asString(event.event_name)?.toLowerCase() ?? ''; const action = asString(event.action)?.toLowerCase() ?? ''; @@ -501,6 +506,7 @@ async function onRepositoryUpdateEvent( }; } +/** @alpha */ export async function analyzeGitLabWebhookEvent( eventType: string, eventPayload: unknown, @@ -513,9 +519,14 @@ export async function analyzeGitLabWebhookEvent( let result: AnalyzeWebhookEventResult; if (eventType === 'push') { - result = await 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); + result = await onRepositoryUpdateEvent( + eventPayload as GitLabRepositoryUpdateEvent, + ); } else { result = { result: 'unsupported-event', event: eventType }; } @@ -529,4 +540,4 @@ export async function analyzeGitLabWebhookEvent( } return result; -} \ No newline at end of file +}