@@ -38,7 +38,11 @@ import {
38
38
EntityProvider ,
39
39
EntityProviderConnection ,
40
40
} from '@backstage/plugin-catalog-node' ;
41
- import { EventBroker , EventParams } from '@backstage/plugin-events-node' ;
41
+ import {
42
+ EventBroker ,
43
+ EventParams ,
44
+ EventsService ,
45
+ } from '@backstage/plugin-events-node' ;
42
46
import { graphql } from '@octokit/graphql' ;
43
47
import {
44
48
InstallationCreatedEvent ,
@@ -80,6 +84,13 @@ import {
80
84
import { splitTeamSlug } from '../lib/util' ;
81
85
import { areGroupEntities , areUserEntities } from '../lib/guards' ;
82
86
87
+ const EVENT_TOPICS = [
88
+ 'github.installation' ,
89
+ 'github.membership' ,
90
+ 'github.organization' ,
91
+ 'github.team' ,
92
+ ] ;
93
+
83
94
/**
84
95
* Options for {@link GithubMultiOrgEntityProvider}.
85
96
*
@@ -101,11 +112,16 @@ export interface GithubMultiOrgEntityProviderOptions {
101
112
githubUrl : string ;
102
113
103
114
/**
104
- * The list of the GitHub orgs to consume. By default will consume all accessible
115
+ * The list of the GitHub orgs to consume. By default, it will consume all accessible
105
116
* orgs on the given GitHub instance (support for GitHub App integration only).
106
117
*/
107
118
orgs ?: string [ ] ;
108
119
120
+ /**
121
+ * Passing the optional EventsService enables event-based delta updates.
122
+ */
123
+ events ?: EventsService ;
124
+
109
125
/**
110
126
* The refresh schedule to use.
111
127
*
@@ -138,12 +154,14 @@ export interface GithubMultiOrgEntityProviderOptions {
138
154
139
155
/**
140
156
* Optionally include a team transformer for transforming from GitHub teams to Group Entities.
141
- * By default groups will be namespaced according to their GitHub org.
157
+ * By default, groups will be namespaced according to their GitHub org.
142
158
*/
143
159
teamTransformer ?: TeamTransformer ;
144
160
145
161
/**
146
162
* An EventBroker to subscribe this provider to GitHub events to trigger delta mutations
163
+ *
164
+ * @deprecated Use `events` instead.
147
165
*/
148
166
eventBroker ?: EventBroker ;
149
167
}
@@ -206,6 +224,7 @@ export class GithubMultiOrgEntityProvider implements EntityProvider {
206
224
207
225
constructor (
208
226
private readonly options : {
227
+ events ?: EventsService ;
209
228
id : string ;
210
229
gitHubConfig : GithubIntegrationConfig ;
211
230
githubCredentialsProvider : GithubCredentialsProvider ;
@@ -225,6 +244,11 @@ export class GithubMultiOrgEntityProvider implements EntityProvider {
225
244
/** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect } */
226
245
async connect ( connection : EntityProviderConnection ) {
227
246
this . connection = connection ;
247
+ await this . options . events ?. subscribe ( {
248
+ id : this . getProviderName ( ) ,
249
+ topics : EVENT_TOPICS ,
250
+ onEvent : params => this . onEvent ( params ) ,
251
+ } ) ;
228
252
await this . scheduleFn ?.( ) ;
229
253
}
230
254
@@ -312,12 +336,7 @@ export class GithubMultiOrgEntityProvider implements EntityProvider {
312
336
}
313
337
314
338
private supportsEventTopics ( ) : string [ ] {
315
- return [
316
- 'github.installation' ,
317
- 'github.organization' ,
318
- 'github.team' ,
319
- 'github.membership' ,
320
- ] ;
339
+ return EVENT_TOPICS ;
321
340
}
322
341
323
342
private async onEvent ( params : EventParams ) : Promise < void > {
0 commit comments