fix(catalog-backend-module-bitbucket-cloud): remove unused isRelevantPath options parameter from analyzer

Signed-off-by: Lokesh Kaki <lokeshkaki1@gmail.com>
This commit is contained in:
Lokesh Kaki
2026-03-17 22:31:07 -05:00
parent f215863743
commit deb9a83746
5 changed files with 94 additions and 152 deletions
@@ -10,14 +10,8 @@ import { CatalogScmEvent } from '@backstage/plugin-catalog-node/alpha';
export function analyzeBitbucketCloudWebhookEvent(
eventType: string,
eventPayload: unknown,
_options: AnalyzeBitbucketCloudWebhookEventOptions,
): Promise<AnalyzeBitbucketCloudWebhookEventResult>;
// @alpha
export interface AnalyzeBitbucketCloudWebhookEventOptions {
isRelevantPath: (path: string) => boolean;
}
// @alpha
export type AnalyzeBitbucketCloudWebhookEventResult =
| {
@@ -22,6 +22,5 @@ export default _feature;
export {
analyzeBitbucketCloudWebhookEvent,
type AnalyzeBitbucketCloudWebhookEventOptions,
type AnalyzeBitbucketCloudWebhookEventResult,
} from './events/analyzeBitbucketCloudWebhookEvent';
@@ -78,10 +78,6 @@ export class BitbucketCloudScmEventsBridge {
const output = await analyzeBitbucketCloudWebhookEvent(
eventType,
params.eventPayload,
{
isRelevantPath: path =>
path.endsWith('.yaml') || path.endsWith('.yml'),
},
);
if (output.result === 'ok') {
@@ -16,9 +16,6 @@
import { analyzeBitbucketCloudWebhookEvent } from './analyzeBitbucketCloudWebhookEvent';
const isRelevantPath = (path: string): boolean =>
path.endsWith('.yaml') || path.endsWith('.yml');
const baseRepository = {
type: 'repository',
full_name: 'test-ws/test-repo',
@@ -37,15 +34,11 @@ describe('analyzeBitbucketCloudWebhookEvent', () => {
describe('repo:push', () => {
it('emits repository.updated for a push event', async () => {
await expect(
analyzeBitbucketCloudWebhookEvent(
'repo:push',
{
actor: { type: 'user' },
repository: baseRepository,
push: { changes: [] },
},
{ isRelevantPath },
),
analyzeBitbucketCloudWebhookEvent('repo:push', {
actor: { type: 'user' },
repository: baseRepository,
push: { changes: [] },
}),
).resolves.toEqual({
result: 'ok',
events: [
@@ -59,15 +52,11 @@ describe('analyzeBitbucketCloudWebhookEvent', () => {
it('aborts when repository URL is missing', async () => {
await expect(
analyzeBitbucketCloudWebhookEvent(
'repo:push',
{
actor: { type: 'user' },
repository: { type: 'repository' },
push: { changes: [] },
},
{ isRelevantPath },
),
analyzeBitbucketCloudWebhookEvent('repo:push', {
actor: { type: 'user' },
repository: { type: 'repository' },
push: { changes: [] },
}),
).resolves.toEqual({
result: 'aborted',
reason:
@@ -79,41 +68,37 @@ describe('analyzeBitbucketCloudWebhookEvent', () => {
describe('repo:updated', () => {
it('emits repository.moved when the URL changes', async () => {
await expect(
analyzeBitbucketCloudWebhookEvent(
'repo:updated',
{
actor: { type: 'user' },
repository: {
...baseRepository,
full_name: 'test-ws/test-repo-new',
links: {
analyzeBitbucketCloudWebhookEvent('repo:updated', {
actor: { type: 'user' },
repository: {
...baseRepository,
full_name: 'test-ws/test-repo-new',
links: {
html: {
href: 'https://bitbucket.org/test-ws/test-repo-new',
},
},
},
changes: {
name: { new: 'test-repo-new', old: 'test-repo-old' },
full_name: {
new: 'test-ws/test-repo-new',
old: 'test-ws/test-repo-old',
},
links: {
new: {
html: {
href: 'https://bitbucket.org/test-ws/test-repo-new',
},
},
},
changes: {
name: { new: 'test-repo-new', old: 'test-repo-old' },
full_name: {
new: 'test-ws/test-repo-new',
old: 'test-ws/test-repo-old',
},
links: {
new: {
html: {
href: 'https://bitbucket.org/test-ws/test-repo-new',
},
},
old: {
html: {
href: 'https://bitbucket.org/test-ws/test-repo-old',
},
old: {
html: {
href: 'https://bitbucket.org/test-ws/test-repo-old',
},
},
},
},
{ isRelevantPath },
),
}),
).resolves.toEqual({
result: 'ok',
events: [
@@ -128,28 +113,24 @@ describe('analyzeBitbucketCloudWebhookEvent', () => {
it('falls back to full_name for old URL when links.old is missing', async () => {
await expect(
analyzeBitbucketCloudWebhookEvent(
'repo:updated',
{
actor: { type: 'user' },
repository: {
...baseRepository,
full_name: 'test-ws/test-repo-new',
links: {
html: {
href: 'https://bitbucket.org/test-ws/test-repo-new',
},
},
},
changes: {
full_name: {
new: 'test-ws/test-repo-new',
old: 'test-ws/test-repo-old',
analyzeBitbucketCloudWebhookEvent('repo:updated', {
actor: { type: 'user' },
repository: {
...baseRepository,
full_name: 'test-ws/test-repo-new',
links: {
html: {
href: 'https://bitbucket.org/test-ws/test-repo-new',
},
},
},
{ isRelevantPath },
),
changes: {
full_name: {
new: 'test-ws/test-repo-new',
old: 'test-ws/test-repo-old',
},
},
}),
).resolves.toEqual({
result: 'ok',
events: [
@@ -164,17 +145,13 @@ describe('analyzeBitbucketCloudWebhookEvent', () => {
it('emits repository.updated when no URL change is detected', async () => {
await expect(
analyzeBitbucketCloudWebhookEvent(
'repo:updated',
{
actor: { type: 'user' },
repository: baseRepository,
changes: {
description: { new: 'new desc', old: 'old desc' },
},
analyzeBitbucketCloudWebhookEvent('repo:updated', {
actor: { type: 'user' },
repository: baseRepository,
changes: {
description: { new: 'new desc', old: 'old desc' },
},
{ isRelevantPath },
),
}),
).resolves.toEqual({
result: 'ok',
events: [
@@ -190,44 +167,40 @@ describe('analyzeBitbucketCloudWebhookEvent', () => {
describe('repo:transfer', () => {
it('emits repository.moved when transferred to a new workspace', async () => {
await expect(
analyzeBitbucketCloudWebhookEvent(
'repo:transfer',
{
actor: { type: 'user' },
repository: {
...baseRepository,
full_name: 'new-ws/test-repo',
links: {
analyzeBitbucketCloudWebhookEvent('repo:transfer', {
actor: { type: 'user' },
repository: {
...baseRepository,
full_name: 'new-ws/test-repo',
links: {
html: {
href: 'https://bitbucket.org/new-ws/test-repo',
},
},
workspace: {
type: 'workspace',
slug: 'new-ws',
},
},
changes: {
full_name: {
new: 'new-ws/test-repo',
old: 'test-ws/test-repo',
},
links: {
new: {
html: {
href: 'https://bitbucket.org/new-ws/test-repo',
},
},
workspace: {
type: 'workspace',
slug: 'new-ws',
},
},
changes: {
full_name: {
new: 'new-ws/test-repo',
old: 'test-ws/test-repo',
},
links: {
new: {
html: {
href: 'https://bitbucket.org/new-ws/test-repo',
},
},
old: {
html: {
href: 'https://bitbucket.org/test-ws/test-repo',
},
old: {
html: {
href: 'https://bitbucket.org/test-ws/test-repo',
},
},
},
},
{ isRelevantPath },
),
}),
).resolves.toEqual({
result: 'ok',
events: [
@@ -244,14 +217,10 @@ describe('analyzeBitbucketCloudWebhookEvent', () => {
describe('repo:deleted', () => {
it('emits repository.deleted', async () => {
await expect(
analyzeBitbucketCloudWebhookEvent(
'repo:deleted',
{
actor: { type: 'user' },
repository: baseRepository,
},
{ isRelevantPath },
),
analyzeBitbucketCloudWebhookEvent('repo:deleted', {
actor: { type: 'user' },
repository: baseRepository,
}),
).resolves.toEqual({
result: 'ok',
events: [
@@ -267,17 +236,13 @@ describe('analyzeBitbucketCloudWebhookEvent', () => {
describe('general behavior', () => {
it('throws on non-object payloads', async () => {
await expect(
analyzeBitbucketCloudWebhookEvent('repo:push', undefined, {
isRelevantPath,
}),
analyzeBitbucketCloudWebhookEvent('repo:push', undefined),
).rejects.toThrow(
'Bitbucket Cloud webhook event payload is not an object',
);
await expect(
analyzeBitbucketCloudWebhookEvent('repo:push', [], {
isRelevantPath,
}),
analyzeBitbucketCloudWebhookEvent('repo:push', []),
).rejects.toThrow(
'Bitbucket Cloud webhook event payload is not an object',
);
@@ -285,11 +250,9 @@ describe('analyzeBitbucketCloudWebhookEvent', () => {
it('returns unsupported-event for unknown event types', async () => {
await expect(
analyzeBitbucketCloudWebhookEvent(
'pullrequest:created',
{ actor: { type: 'user' } },
{ isRelevantPath },
),
analyzeBitbucketCloudWebhookEvent('pullrequest:created', {
actor: { type: 'user' },
}),
).resolves.toEqual({
result: 'unsupported-event',
event: 'pullrequest:created',
@@ -17,18 +17,6 @@
import { InputError } from '@backstage/errors';
import { CatalogScmEvent } from '@backstage/plugin-catalog-node/alpha';
/**
* Options for {@link analyzeBitbucketCloudWebhookEvent}.
* @alpha
*/
export interface AnalyzeBitbucketCloudWebhookEventOptions {
/**
* Predicate that returns true for file paths that are relevant to the
* catalog (e.g. paths ending in `.yaml` or `.yml`).
*/
isRelevantPath: (path: string) => boolean;
}
/**
* The result of analyzing a Bitbucket Cloud webhook event.
*
@@ -213,10 +201,13 @@ async function onRepoDeletedEvent(
* Analyzes a Bitbucket Cloud webhook event and translates it into zero or more
* catalog SCM events that entity providers can act on.
*
* Bitbucket Cloud push payloads do not include file-level change data, so only
* repository-level events are produced (unlike GitLab and Azure DevOps
* analyzers which can emit fine-grained `location.*` events).
*
* Supported event types:
* - `repo:push` — emits a `repository.updated` event to trigger catalog
* refresh for the repository. Bitbucket Cloud push payloads do not include
* file-level change data, so only repository-level events are produced.
* refresh for the repository.
* - `repo:updated` — translates repository renames into `repository.moved`
* events, or emits `repository.updated` for other metadata changes.
* - `repo:transfer` — translates repository transfers into `repository.moved`
@@ -228,7 +219,6 @@ async function onRepoDeletedEvent(
export async function analyzeBitbucketCloudWebhookEvent(
eventType: string,
eventPayload: unknown,
_options: AnalyzeBitbucketCloudWebhookEventOptions,
): Promise<AnalyzeBitbucketCloudWebhookEventResult> {
const payload = asObject(eventPayload);
if (!payload) {