refactor(GithubMultiOrgEntityProvider): remove EventSubscriber interface declaration
Signed-off-by: Phil Kuang <pkuang@factset.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend-module-github': patch
|
||||
'@backstage/plugin-catalog-backend-module-github': minor
|
||||
---
|
||||
|
||||
Implement events support for `GithubMultiOrgEntityProvider`
|
||||
|
||||
**BREAKING:** Passing in a custom `teamTransformer` will now correctly completely override the default transformer behavior
|
||||
|
||||
@@ -134,9 +134,7 @@ export type GithubMultiOrgConfig = Array<{
|
||||
}>;
|
||||
|
||||
// @public
|
||||
export class GithubMultiOrgEntityProvider
|
||||
implements EntityProvider, EventSubscriber
|
||||
{
|
||||
export class GithubMultiOrgEntityProvider implements EntityProvider {
|
||||
constructor(options: {
|
||||
id: string;
|
||||
gitHubConfig: GithubIntegrationConfig;
|
||||
@@ -156,11 +154,7 @@ export class GithubMultiOrgEntityProvider
|
||||
): GithubMultiOrgEntityProvider;
|
||||
// (undocumented)
|
||||
getProviderName(): string;
|
||||
// (undocumented)
|
||||
onEvent(params: EventParams): Promise<void>;
|
||||
read(options?: { logger?: Logger }): Promise<void>;
|
||||
// (undocumented)
|
||||
supportsEventTopics(): string[];
|
||||
}
|
||||
|
||||
// @public
|
||||
|
||||
+33
-17
@@ -16,11 +16,13 @@
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { GroupEntity, UserEntity } from '@backstage/catalog-model';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
GithubCredentialsProvider,
|
||||
GithubIntegrationConfig,
|
||||
} from '@backstage/integration';
|
||||
import { EntityProviderConnection } from '@backstage/plugin-catalog-node';
|
||||
import { EventSubscriber } from '@backstage/plugin-events-node';
|
||||
import { graphql } from '@octokit/graphql';
|
||||
import {
|
||||
GithubMultiOrgEntityProvider,
|
||||
@@ -715,7 +717,8 @@ describe('GithubMultiOrgEntityProvider', () => {
|
||||
});
|
||||
|
||||
describe('events', () => {
|
||||
let entityProvider: GithubMultiOrgEntityProvider;
|
||||
let onEvent: Function;
|
||||
|
||||
const entityProviderConnection: EntityProviderConnection = {
|
||||
applyMutation: jest.fn(),
|
||||
refresh: jest.fn(),
|
||||
@@ -723,9 +726,15 @@ describe('GithubMultiOrgEntityProvider', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
const logger = getVoidLogger();
|
||||
const gitHubConfig: GithubIntegrationConfig = {
|
||||
host: 'github.com',
|
||||
};
|
||||
const config = new ConfigReader({
|
||||
integrations: {
|
||||
github: [
|
||||
{
|
||||
host: 'github.com',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const mockGetCredentials = jest.fn().mockReturnValue({
|
||||
headers: { token: 'blah' },
|
||||
@@ -736,13 +745,20 @@ describe('GithubMultiOrgEntityProvider', () => {
|
||||
getCredentials: mockGetCredentials,
|
||||
};
|
||||
|
||||
entityProvider = new GithubMultiOrgEntityProvider({
|
||||
const mockEventBroker = {
|
||||
publish: async () => {},
|
||||
subscribe: (subscriber: EventSubscriber) => {
|
||||
onEvent = subscriber.onEvent;
|
||||
},
|
||||
};
|
||||
|
||||
const entityProvider = GithubMultiOrgEntityProvider.fromConfig(config, {
|
||||
id: 'my-id',
|
||||
gitHubConfig,
|
||||
githubCredentialsProvider,
|
||||
githubUrl: 'https://github.com',
|
||||
logger,
|
||||
orgs: ['orgA', 'orgB'],
|
||||
eventBroker: mockEventBroker,
|
||||
});
|
||||
|
||||
entityProvider.connect(entityProviderConnection);
|
||||
@@ -751,7 +767,7 @@ describe('GithubMultiOrgEntityProvider', () => {
|
||||
afterEach(() => jest.resetAllMocks());
|
||||
|
||||
it('should ignore events from non-applicable orgs', async () => {
|
||||
await entityProvider.onEvent({
|
||||
await onEvent({
|
||||
topic: 'github.organization',
|
||||
eventPayload: {
|
||||
action: 'member_added',
|
||||
@@ -771,7 +787,7 @@ describe('GithubMultiOrgEntityProvider', () => {
|
||||
|
||||
expect(entityProviderConnection.applyMutation).not.toHaveBeenCalled();
|
||||
|
||||
await entityProvider.onEvent({
|
||||
await onEvent({
|
||||
topic: 'github.installation',
|
||||
eventPayload: {
|
||||
action: 'created',
|
||||
@@ -885,7 +901,7 @@ describe('GithubMultiOrgEntityProvider', () => {
|
||||
|
||||
(graphql.defaults as jest.Mock).mockReturnValue(mockClient);
|
||||
|
||||
await entityProvider.onEvent({
|
||||
await onEvent({
|
||||
topic: 'github.installation',
|
||||
eventPayload: {
|
||||
action: 'created',
|
||||
@@ -1017,7 +1033,7 @@ describe('GithubMultiOrgEntityProvider', () => {
|
||||
|
||||
(graphql.defaults as jest.Mock).mockReturnValue(mockClient);
|
||||
|
||||
await entityProvider.onEvent({
|
||||
await onEvent({
|
||||
topic: 'github.organization',
|
||||
eventPayload: {
|
||||
action: 'member_added',
|
||||
@@ -1087,7 +1103,7 @@ describe('GithubMultiOrgEntityProvider', () => {
|
||||
|
||||
(graphql.defaults as jest.Mock).mockReturnValue(mockClient);
|
||||
|
||||
await entityProvider.onEvent({
|
||||
await onEvent({
|
||||
topic: 'github.organization',
|
||||
eventPayload: {
|
||||
action: 'member_removed',
|
||||
@@ -1182,7 +1198,7 @@ describe('GithubMultiOrgEntityProvider', () => {
|
||||
|
||||
(graphql.defaults as jest.Mock).mockReturnValue(mockClient);
|
||||
|
||||
await entityProvider.onEvent({
|
||||
await onEvent({
|
||||
topic: 'github.organization',
|
||||
eventPayload: {
|
||||
action: 'member_removed',
|
||||
@@ -1237,7 +1253,7 @@ describe('GithubMultiOrgEntityProvider', () => {
|
||||
|
||||
describe('team', () => {
|
||||
it('should create a new group from a new team', async () => {
|
||||
await entityProvider.onEvent({
|
||||
await onEvent({
|
||||
topic: 'github.team',
|
||||
eventPayload: {
|
||||
action: 'created',
|
||||
@@ -1296,7 +1312,7 @@ describe('GithubMultiOrgEntityProvider', () => {
|
||||
});
|
||||
|
||||
it('should remove a group from a deleted team', async () => {
|
||||
await entityProvider.onEvent({
|
||||
await onEvent({
|
||||
topic: 'github.team',
|
||||
eventPayload: {
|
||||
action: 'deleted',
|
||||
@@ -1451,7 +1467,7 @@ describe('GithubMultiOrgEntityProvider', () => {
|
||||
|
||||
(graphql.defaults as jest.Mock).mockReturnValue(mockClient);
|
||||
|
||||
await entityProvider.onEvent({
|
||||
await onEvent({
|
||||
topic: 'github.team',
|
||||
eventPayload: {
|
||||
action: 'edited',
|
||||
@@ -1660,7 +1676,7 @@ describe('GithubMultiOrgEntityProvider', () => {
|
||||
|
||||
(graphql.defaults as jest.Mock).mockReturnValue(mockClient);
|
||||
|
||||
await entityProvider.onEvent({
|
||||
await onEvent({
|
||||
topic: 'github.membership',
|
||||
eventPayload: {
|
||||
action: 'added',
|
||||
@@ -1833,7 +1849,7 @@ describe('GithubMultiOrgEntityProvider', () => {
|
||||
|
||||
(graphql.defaults as jest.Mock).mockReturnValue(mockClient);
|
||||
|
||||
await entityProvider.onEvent({
|
||||
await onEvent({
|
||||
topic: 'github.membership',
|
||||
eventPayload: {
|
||||
action: 'removed',
|
||||
|
||||
+8
-13
@@ -38,11 +38,7 @@ import {
|
||||
EntityProvider,
|
||||
EntityProviderConnection,
|
||||
} from '@backstage/plugin-catalog-node';
|
||||
import {
|
||||
EventBroker,
|
||||
EventParams,
|
||||
EventSubscriber,
|
||||
} from '@backstage/plugin-events-node';
|
||||
import { EventBroker, EventParams } from '@backstage/plugin-events-node';
|
||||
import { graphql } from '@octokit/graphql';
|
||||
import {
|
||||
InstallationCreatedEvent,
|
||||
@@ -161,9 +157,7 @@ type CreateDeltaOperation = (entities: Entity[]) => {
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class GithubMultiOrgEntityProvider
|
||||
implements EntityProvider, EventSubscriber
|
||||
{
|
||||
export class GithubMultiOrgEntityProvider implements EntityProvider {
|
||||
private connection?: EntityProviderConnection;
|
||||
private scheduleFn?: () => Promise<void>;
|
||||
|
||||
@@ -200,7 +194,10 @@ export class GithubMultiOrgEntityProvider
|
||||
provider.schedule(options.schedule);
|
||||
|
||||
if (options.eventBroker) {
|
||||
options.eventBroker.subscribe(provider);
|
||||
options.eventBroker.subscribe({
|
||||
supportsEventTopics: provider.supportsEventTopics.bind(provider),
|
||||
onEvent: provider.onEvent.bind(provider),
|
||||
});
|
||||
}
|
||||
|
||||
return provider;
|
||||
@@ -313,8 +310,7 @@ export class GithubMultiOrgEntityProvider
|
||||
markCommitComplete();
|
||||
}
|
||||
|
||||
/** {@inheritdoc @backstage/plugin-events-node#EventSubscriber.supportsEventTopics} */
|
||||
supportsEventTopics(): string[] {
|
||||
private supportsEventTopics(): string[] {
|
||||
return [
|
||||
'github.installation',
|
||||
'github.organization',
|
||||
@@ -323,8 +319,7 @@ export class GithubMultiOrgEntityProvider
|
||||
];
|
||||
}
|
||||
|
||||
/** {@inheritdoc @backstage/plugin-events-node#EventSubscriber.onEvent} */
|
||||
async onEvent(params: EventParams): Promise<void> {
|
||||
private async onEvent(params: EventParams): Promise<void> {
|
||||
const { logger } = this.options;
|
||||
logger.debug(`Received event from ${params.topic}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user