feat(events,catalog/bitbucketCloud): handle repo:push events

Relates-to: #10866
Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
This commit is contained in:
Patrick Jungermann
2022-09-17 02:01:00 +02:00
parent b8f913096c
commit d089fbe7dc
15 changed files with 571 additions and 31 deletions
@@ -24,6 +24,57 @@ export class BitbucketCloudClient {
): WithPagination<Models.SearchResultPage, Models.SearchCodeSearchResult>;
}
// @public (undocumented)
export namespace Events {
// (undocumented)
export interface Change {
// (undocumented)
closed: boolean;
// (undocumented)
commits: Models.Commit[];
// (undocumented)
created: boolean;
// (undocumented)
forced: boolean;
// (undocumented)
links: ChangeLinks;
// (undocumented)
new: Models.Branch;
// (undocumented)
old: Models.Branch;
// (undocumented)
truncated: boolean;
}
// (undocumented)
export interface ChangeLinks {
// (undocumented)
commits: Models.Link;
// (undocumented)
diff: Models.Link;
// (undocumented)
html: Models.Link;
}
// (undocumented)
export interface RepoEvent {
// (undocumented)
actor: Models.Account;
// (undocumented)
repository: Models.Repository & {
workspace: Models.Workspace;
};
}
// (undocumented)
export interface RepoPush {
// (undocumented)
changes: Change[];
}
// (undocumented)
export interface RepoPushEvent extends RepoEvent {
// (undocumented)
push: RepoPush;
}
}
// @public (undocumented)
export type FilterAndSortOptions = {
q?: string;
@@ -340,6 +391,37 @@ export namespace Models {
// (undocumented)
self?: Link;
}
export interface Workspace extends ModelObject {
// (undocumented)
created_on?: string;
is_private?: boolean;
// (undocumented)
links?: WorkspaceLinks;
name?: string;
slug?: string;
// (undocumented)
updated_on?: string;
uuid?: string;
}
// (undocumented)
export interface WorkspaceLinks {
// (undocumented)
avatar?: Link;
// (undocumented)
html?: Link;
// (undocumented)
members?: Link;
// (undocumented)
owners?: Link;
// (undocumented)
projects?: Link;
// (undocumented)
repositories?: Link;
// (undocumented)
self?: Link;
// (undocumented)
snippets?: Link;
}
}
// @public (undocumented)
@@ -30,6 +30,14 @@ const modelsModule = modelsFile.getModuleOrThrow('Models');
const clientFile = project.getSourceFile('src/BitbucketCloudClient.ts');
const clientClass = clientFile.getClassOrThrow('BitbucketCloudClient');
const eventsFile = project.getSourceFile('src/events/index.ts');
const eventsModule = eventsFile.getModuleOrThrow('Events');
const eventsStmts = [
...eventsModule.getClasses(),
...eventsModule.getInterfaces(),
...eventsModule.getTypeAliases(),
];
/**
* Returns an array of the unique items of the provided array.
*
@@ -79,7 +87,11 @@ function referencedModelsIdentifiers(stmt, processed) {
}
// all directly or transitively referenced/used `Models.[...]` are allowed to stay
const allowed = referencedModelsIdentifiers(clientClass);
const processed = [];
const allowed = referencedModelsIdentifiers(clientClass, processed);
allowed.push(
...eventsStmts.flatMap(stmt => referencedModelsIdentifiers(stmt, processed)),
);
// remove everything not part of the "allow list"
modelsModule
@@ -0,0 +1,56 @@
/*
* Copyright 2022 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Models } from '../models';
// source: https://support.atlassian.com/bitbucket-cloud/docs/event-payloads
/** @public */
export namespace Events {
/** @public */
export interface RepoEvent {
repository: Models.Repository & { workspace: Models.Workspace };
actor: Models.Account;
}
/** @public */
export interface RepoPushEvent extends RepoEvent {
push: RepoPush;
}
/** @public */
export interface RepoPush {
changes: Change[];
}
/** @public */
export interface Change {
old: Models.Branch;
new: Models.Branch;
truncated: boolean;
created: boolean;
forced: boolean;
closed: boolean;
links: ChangeLinks;
commits: Models.Commit[];
}
/** @public */
export interface ChangeLinks {
commits: Models.Link;
diff: Models.Link;
html: Models.Link;
}
}
@@ -21,6 +21,7 @@
*/
export * from './BitbucketCloudClient';
export * from './events';
export * from './models';
export * from './pagination';
export * from './types';
@@ -518,4 +518,46 @@ export namespace Models {
repositories?: Link;
self?: Link;
}
/**
* A Bitbucket workspace.
* Workspaces are used to organize repositories.
* @public
*/
export interface Workspace extends ModelObject {
created_on?: string;
/**
* Indicates whether the workspace is publicly accessible, or whether it is
* private to the members and consequently only visible to members.
*/
is_private?: boolean;
links?: WorkspaceLinks;
/**
* The name of the workspace.
*/
name?: string;
/**
* The short label that identifies this workspace.
*/
slug?: string;
updated_on?: string;
/**
* The workspace's immutable id.
*/
uuid?: string;
}
/**
* @public
*/
export interface WorkspaceLinks {
avatar?: Link;
html?: Link;
members?: Link;
owners?: Link;
projects?: Link;
repositories?: Link;
self?: Link;
snippets?: Link;
}
}