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 <lokeshkaki1@gmail.com>
This commit is contained in:
@@ -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<AnalyzeWebhookEventResult>;
|
||||
|
||||
// @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;
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -146,4 +146,4 @@ export class GitLabScmEventsBridge {
|
||||
this.#pendingPublish = current;
|
||||
await current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,4 +255,4 @@ describe('analyzeGitLabWebhookEvent', () => {
|
||||
}),
|
||||
).rejects.toBeInstanceOf(InputError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,11 +21,13 @@ import { WebhookPushEventSchema } from '@gitbeaker/rest';
|
||||
|
||||
type StringRecord = Record<string, unknown>;
|
||||
|
||||
/** @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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user