@backstage/plugin-catalog-backend-module-github 0.6.1 → 0.6.2-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/alpha/package.json +1 -1
- package/dist/alpha.cjs.js +1 -1
- package/dist/cjs/{GithubEntityProvider-CiEweAnD.cjs.js → GithubEntityProvider-C-D2ftt3.cjs.js} +54 -94
- package/dist/cjs/{GithubEntityProvider-CiEweAnD.cjs.js.map → GithubEntityProvider-C-D2ftt3.cjs.js.map} +1 -1
- package/dist/index.cjs.js +74 -134
- package/dist/index.cjs.js.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @backstage/plugin-catalog-backend-module-github
|
|
2
2
|
|
|
3
|
+
## 0.6.2-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/backend-tasks@0.5.24-next.1
|
|
9
|
+
- @backstage/backend-plugin-api@0.6.19-next.1
|
|
10
|
+
- @backstage/backend-common@0.23.0-next.1
|
|
11
|
+
- @backstage/plugin-catalog-backend@1.23.0-next.1
|
|
12
|
+
- @backstage/plugin-catalog-node@1.12.1-next.0
|
|
13
|
+
- @backstage/plugin-events-node@0.3.5-next.0
|
|
14
|
+
|
|
15
|
+
## 0.6.2-next.0
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
- @backstage/backend-tasks@0.5.24-next.0
|
|
21
|
+
- @backstage/backend-common@0.22.1-next.0
|
|
22
|
+
- @backstage/plugin-catalog-backend@1.23.0-next.0
|
|
23
|
+
- @backstage/plugin-events-node@0.3.5-next.0
|
|
24
|
+
- @backstage/backend-plugin-api@0.6.19-next.0
|
|
25
|
+
- @backstage/plugin-catalog-node@1.12.1-next.0
|
|
26
|
+
- @backstage/catalog-client@1.6.5
|
|
27
|
+
- @backstage/catalog-model@1.5.0
|
|
28
|
+
- @backstage/config@1.2.0
|
|
29
|
+
- @backstage/integration@1.11.0
|
|
30
|
+
- @backstage/plugin-catalog-common@1.0.23
|
|
31
|
+
|
|
3
32
|
## 0.6.1
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
package/alpha/package.json
CHANGED
package/dist/alpha.cjs.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
6
6
|
var alpha = require('@backstage/plugin-catalog-node/alpha');
|
|
7
7
|
var pluginEventsNode = require('@backstage/plugin-events-node');
|
|
8
|
-
var GithubEntityProvider = require('./cjs/GithubEntityProvider-
|
|
8
|
+
var GithubEntityProvider = require('./cjs/GithubEntityProvider-C-D2ftt3.cjs.js');
|
|
9
9
|
require('@backstage/catalog-client');
|
|
10
10
|
require('@backstage/integration');
|
|
11
11
|
require('@octokit/rest');
|
package/dist/cjs/{GithubEntityProvider-CiEweAnD.cjs.js → GithubEntityProvider-C-D2ftt3.cjs.js}
RENAMED
|
@@ -36,18 +36,12 @@ function _interopNamespaceCompat(e) {
|
|
|
36
36
|
var parseGitUrl__default = /*#__PURE__*/_interopDefaultCompat(parseGitUrl);
|
|
37
37
|
var uuid__namespace = /*#__PURE__*/_interopNamespaceCompat(uuid);
|
|
38
38
|
|
|
39
|
-
var __defProp$1 = Object.defineProperty;
|
|
40
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
41
|
-
var __publicField$1 = (obj, key, value) => {
|
|
42
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
43
|
-
return value;
|
|
44
|
-
};
|
|
45
39
|
class GithubLocationAnalyzer {
|
|
40
|
+
catalogClient;
|
|
41
|
+
githubCredentialsProvider;
|
|
42
|
+
integrations;
|
|
43
|
+
auth;
|
|
46
44
|
constructor(options) {
|
|
47
|
-
__publicField$1(this, "catalogClient");
|
|
48
|
-
__publicField$1(this, "githubCredentialsProvider");
|
|
49
|
-
__publicField$1(this, "integrations");
|
|
50
|
-
__publicField$1(this, "auth");
|
|
51
45
|
this.catalogClient = new catalogClient.CatalogClient({ discoveryApi: options.discovery });
|
|
52
46
|
this.integrations = integration.ScmIntegrations.fromConfig(options.config);
|
|
53
47
|
this.githubCredentialsProvider = options.githubCredentialsProvider || integration.DefaultGithubCredentialsProvider.fromIntegrations(this.integrations);
|
|
@@ -59,7 +53,7 @@ class GithubLocationAnalyzer {
|
|
|
59
53
|
}
|
|
60
54
|
supports(url) {
|
|
61
55
|
const integration = this.integrations.byUrl(url);
|
|
62
|
-
return
|
|
56
|
+
return integration?.type === "github";
|
|
63
57
|
}
|
|
64
58
|
async analyze(options) {
|
|
65
59
|
const { url, catalogFilename } = options;
|
|
@@ -185,21 +179,20 @@ function parseGithubOrgUrl(urlString) {
|
|
|
185
179
|
throw new Error(`Expected a URL pointing to /<org>`);
|
|
186
180
|
}
|
|
187
181
|
function satisfiesTopicFilter(topics, topicFilter) {
|
|
188
|
-
var _a, _b, _c, _d;
|
|
189
182
|
if (!topicFilter)
|
|
190
183
|
return true;
|
|
191
184
|
if (!topicFilter.include && !topicFilter.exclude)
|
|
192
185
|
return true;
|
|
193
|
-
if (!
|
|
186
|
+
if (!topicFilter.include?.length && !topicFilter.exclude?.length)
|
|
194
187
|
return true;
|
|
195
|
-
if (
|
|
188
|
+
if (topicFilter.include?.length && !topicFilter.exclude) {
|
|
196
189
|
for (const topic of topics) {
|
|
197
190
|
if (topicFilter.include.includes(topic))
|
|
198
191
|
return true;
|
|
199
192
|
}
|
|
200
193
|
return false;
|
|
201
194
|
}
|
|
202
|
-
if (!topicFilter.include &&
|
|
195
|
+
if (!topicFilter.include && topicFilter.exclude?.length) {
|
|
203
196
|
if (!topics.length)
|
|
204
197
|
return true;
|
|
205
198
|
for (const topic of topics) {
|
|
@@ -247,10 +240,9 @@ function satisfiesVisibilityFilter(visibilities, visibility) {
|
|
|
247
240
|
}
|
|
248
241
|
|
|
249
242
|
function withLocations(baseUrl, org, entity) {
|
|
250
|
-
|
|
251
|
-
const login = ((_a = entity.metadata.annotations) == null ? void 0 : _a[ANNOTATION_GITHUB_USER_LOGIN]) || entity.metadata.name;
|
|
243
|
+
const login = entity.metadata.annotations?.[ANNOTATION_GITHUB_USER_LOGIN] || entity.metadata.name;
|
|
252
244
|
let team = entity.metadata.name;
|
|
253
|
-
const slug =
|
|
245
|
+
const slug = entity.metadata.annotations?.[ANNOTATION_GITHUB_TEAM_SLUG];
|
|
254
246
|
if (slug) {
|
|
255
247
|
const [_, slugTeam] = splitTeamSlug(slug);
|
|
256
248
|
team = slugTeam;
|
|
@@ -290,10 +282,7 @@ async function getOrganizationUsers(client, org, tokenType, userTransformer = de
|
|
|
290
282
|
client,
|
|
291
283
|
query,
|
|
292
284
|
org,
|
|
293
|
-
(r) =>
|
|
294
|
-
var _a;
|
|
295
|
-
return (_a = r.organization) == null ? void 0 : _a.membersWithRole;
|
|
296
|
-
},
|
|
285
|
+
(r) => r.organization?.membersWithRole,
|
|
297
286
|
userTransformer,
|
|
298
287
|
{
|
|
299
288
|
org,
|
|
@@ -353,10 +342,7 @@ async function getOrganizationTeams(client, org, teamTransformer = defaultOrgani
|
|
|
353
342
|
client,
|
|
354
343
|
query,
|
|
355
344
|
org,
|
|
356
|
-
(r) =>
|
|
357
|
-
var _a;
|
|
358
|
-
return (_a = r.organization) == null ? void 0 : _a.teams;
|
|
359
|
-
},
|
|
345
|
+
(r) => r.organization?.teams,
|
|
360
346
|
materialisedTeams,
|
|
361
347
|
{ org }
|
|
362
348
|
);
|
|
@@ -420,10 +406,7 @@ async function getOrganizationTeamsFromUsers(client, org, userLogins, teamTransf
|
|
|
420
406
|
client,
|
|
421
407
|
query,
|
|
422
408
|
org,
|
|
423
|
-
(r) =>
|
|
424
|
-
var _a;
|
|
425
|
-
return (_a = r.organization) == null ? void 0 : _a.teams;
|
|
426
|
-
},
|
|
409
|
+
(r) => r.organization?.teams,
|
|
427
410
|
materialisedTeams,
|
|
428
411
|
{ org, userLogins }
|
|
429
412
|
);
|
|
@@ -443,17 +426,13 @@ async function getOrganizationsFromUser(client, user) {
|
|
|
443
426
|
client,
|
|
444
427
|
query,
|
|
445
428
|
"",
|
|
446
|
-
(r) =>
|
|
447
|
-
var _a;
|
|
448
|
-
return (_a = r.user) == null ? void 0 : _a.organizations;
|
|
449
|
-
},
|
|
429
|
+
(r) => r.user?.organizations,
|
|
450
430
|
async (o) => o.login,
|
|
451
431
|
{ user }
|
|
452
432
|
);
|
|
453
433
|
return { orgs };
|
|
454
434
|
}
|
|
455
435
|
async function getOrganizationTeam(client, org, teamSlug, teamTransformer = defaultOrganizationTeamTransformer) {
|
|
456
|
-
var _a, _b;
|
|
457
436
|
const query = `
|
|
458
437
|
query teams($org: String!, $teamSlug: String!) {
|
|
459
438
|
organization(login: $org) {
|
|
@@ -494,9 +473,9 @@ async function getOrganizationTeam(client, org, teamSlug, teamTransformer = defa
|
|
|
494
473
|
org,
|
|
495
474
|
teamSlug
|
|
496
475
|
});
|
|
497
|
-
if (!
|
|
476
|
+
if (!response.organization?.team)
|
|
498
477
|
throw new Error(`Found no match for team ${teamSlug}`);
|
|
499
|
-
const team = await materialisedTeam(
|
|
478
|
+
const team = await materialisedTeam(response.organization?.team, {
|
|
500
479
|
query,
|
|
501
480
|
client,
|
|
502
481
|
org
|
|
@@ -555,10 +534,7 @@ async function getOrganizationRepositories(client, org, catalogPath) {
|
|
|
555
534
|
client,
|
|
556
535
|
query,
|
|
557
536
|
org,
|
|
558
|
-
(r) =>
|
|
559
|
-
var _a;
|
|
560
|
-
return (_a = r.repositoryOwner) == null ? void 0 : _a.repositories;
|
|
561
|
-
},
|
|
537
|
+
(r) => r.repositoryOwner?.repositories,
|
|
562
538
|
async (x) => x,
|
|
563
539
|
{ org, catalogPathRef }
|
|
564
540
|
);
|
|
@@ -580,10 +556,7 @@ async function getTeamMembers(client, org, teamSlug) {
|
|
|
580
556
|
client,
|
|
581
557
|
query,
|
|
582
558
|
org,
|
|
583
|
-
(r) =>
|
|
584
|
-
var _a, _b;
|
|
585
|
-
return (_b = (_a = r.organization) == null ? void 0 : _a.team) == null ? void 0 : _b.members;
|
|
586
|
-
},
|
|
559
|
+
(r) => r.organization?.team?.members,
|
|
587
560
|
async (user) => user,
|
|
588
561
|
{ org, teamSlug }
|
|
589
562
|
);
|
|
@@ -662,22 +635,21 @@ function readProviderConfigs(config) {
|
|
|
662
635
|
});
|
|
663
636
|
}
|
|
664
637
|
function readProviderConfig(id, config) {
|
|
665
|
-
var _a, _b, _c, _d;
|
|
666
638
|
const organization = config.getString("organization");
|
|
667
|
-
const catalogPath =
|
|
668
|
-
const host =
|
|
639
|
+
const catalogPath = config.getOptionalString("catalogPath") ?? DEFAULT_CATALOG_PATH;
|
|
640
|
+
const host = config.getOptionalString("host") ?? "github.com";
|
|
669
641
|
const repositoryPattern = config.getOptionalString("filters.repository");
|
|
670
642
|
const branchPattern = config.getOptionalString("filters.branch");
|
|
671
|
-
const allowForks =
|
|
672
|
-
const topicFilterInclude = config
|
|
643
|
+
const allowForks = config.getOptionalBoolean("filters.allowForks") ?? true;
|
|
644
|
+
const topicFilterInclude = config?.getOptionalStringArray(
|
|
673
645
|
"filters.topic.include"
|
|
674
646
|
);
|
|
675
|
-
const topicFilterExclude = config
|
|
647
|
+
const topicFilterExclude = config?.getOptionalStringArray(
|
|
676
648
|
"filters.topic.exclude"
|
|
677
649
|
);
|
|
678
|
-
const validateLocationsExist =
|
|
650
|
+
const validateLocationsExist = config?.getOptionalBoolean("validateLocationsExist") ?? false;
|
|
679
651
|
const catalogPathContainsWildcard = catalogPath.includes("*");
|
|
680
|
-
const visibilityFilterInclude = config
|
|
652
|
+
const visibilityFilterInclude = config?.getOptionalStringArray("filters.visibility");
|
|
681
653
|
if (validateLocationsExist && catalogPathContainsWildcard) {
|
|
682
654
|
throw Error(
|
|
683
655
|
`Error while processing GitHub provider config. The catalog path ${catalogPath} contains a wildcard, which is incompatible with validation of locations existing before emitting them. Ensure that validateLocationsExist is set to false.`
|
|
@@ -714,38 +686,21 @@ function compileRegExp(pattern) {
|
|
|
714
686
|
return new RegExp(fullLinePattern);
|
|
715
687
|
}
|
|
716
688
|
|
|
717
|
-
var __defProp = Object.defineProperty;
|
|
718
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
719
|
-
var __publicField = (obj, key, value) => {
|
|
720
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
721
|
-
return value;
|
|
722
|
-
};
|
|
723
689
|
const TOPIC_REPO_PUSH = "github.push";
|
|
724
690
|
class GithubEntityProvider {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
__publicField(this, "githubCredentialsProvider");
|
|
733
|
-
this.config = config;
|
|
734
|
-
this.events = events;
|
|
735
|
-
this.integration = integration$1.config;
|
|
736
|
-
this.logger = logger.child({
|
|
737
|
-
target: this.getProviderName()
|
|
738
|
-
});
|
|
739
|
-
this.scheduleFn = this.createScheduleFn(taskRunner);
|
|
740
|
-
this.githubCredentialsProvider = integration.SingleInstanceGithubCredentialsProvider.create(integration$1.config);
|
|
741
|
-
}
|
|
691
|
+
config;
|
|
692
|
+
events;
|
|
693
|
+
logger;
|
|
694
|
+
integration;
|
|
695
|
+
scheduleFn;
|
|
696
|
+
connection;
|
|
697
|
+
githubCredentialsProvider;
|
|
742
698
|
static fromConfig(config, options) {
|
|
743
699
|
if (!options.schedule && !options.scheduler) {
|
|
744
700
|
throw new Error("Either schedule or scheduler must be provided.");
|
|
745
701
|
}
|
|
746
702
|
const integrations = integration.ScmIntegrations.fromConfig(config);
|
|
747
703
|
return readProviderConfigs(config).map((providerConfig) => {
|
|
748
|
-
var _a;
|
|
749
704
|
const integrationHost = providerConfig.host;
|
|
750
705
|
const integration = integrations.github.byHost(integrationHost);
|
|
751
706
|
if (!integration) {
|
|
@@ -758,7 +713,7 @@ class GithubEntityProvider {
|
|
|
758
713
|
`No schedule provided neither via code nor config for github-provider:${providerConfig.id}.`
|
|
759
714
|
);
|
|
760
715
|
}
|
|
761
|
-
const taskRunner =
|
|
716
|
+
const taskRunner = options.schedule ?? options.scheduler.createScheduledTaskRunner(providerConfig.schedule);
|
|
762
717
|
return new GithubEntityProvider(
|
|
763
718
|
providerConfig,
|
|
764
719
|
integration,
|
|
@@ -768,19 +723,28 @@ class GithubEntityProvider {
|
|
|
768
723
|
);
|
|
769
724
|
});
|
|
770
725
|
}
|
|
726
|
+
constructor(config, integration$1, logger, taskRunner, events) {
|
|
727
|
+
this.config = config;
|
|
728
|
+
this.events = events;
|
|
729
|
+
this.integration = integration$1.config;
|
|
730
|
+
this.logger = logger.child({
|
|
731
|
+
target: this.getProviderName()
|
|
732
|
+
});
|
|
733
|
+
this.scheduleFn = this.createScheduleFn(taskRunner);
|
|
734
|
+
this.githubCredentialsProvider = integration.SingleInstanceGithubCredentialsProvider.create(integration$1.config);
|
|
735
|
+
}
|
|
771
736
|
/** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */
|
|
772
737
|
getProviderName() {
|
|
773
738
|
return `github-provider:${this.config.id}`;
|
|
774
739
|
}
|
|
775
740
|
/** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */
|
|
776
741
|
async connect(connection) {
|
|
777
|
-
var _a;
|
|
778
742
|
this.connection = connection;
|
|
779
|
-
await
|
|
743
|
+
await this.events?.subscribe({
|
|
780
744
|
id: this.getProviderName(),
|
|
781
745
|
topics: [TOPIC_REPO_PUSH],
|
|
782
746
|
onEvent: (params) => this.onEvent(params)
|
|
783
|
-
})
|
|
747
|
+
});
|
|
784
748
|
return await this.scheduleFn();
|
|
785
749
|
}
|
|
786
750
|
createScheduleFn(taskRunner) {
|
|
@@ -841,15 +805,14 @@ class GithubEntityProvider {
|
|
|
841
805
|
});
|
|
842
806
|
const { repositories: repositoriesFromGithub } = await getOrganizationRepositories(client, organization, catalogPath);
|
|
843
807
|
const repositories = repositoriesFromGithub.map((r) => {
|
|
844
|
-
var _a, _b;
|
|
845
808
|
return {
|
|
846
809
|
url: r.url,
|
|
847
810
|
name: r.name,
|
|
848
|
-
defaultBranchRef:
|
|
811
|
+
defaultBranchRef: r.defaultBranchRef?.name,
|
|
849
812
|
repositoryTopics: r.repositoryTopics.nodes.map((t) => t.topic.name),
|
|
850
813
|
isArchived: r.isArchived,
|
|
851
814
|
isFork: r.isFork,
|
|
852
|
-
isCatalogInfoFilePresent:
|
|
815
|
+
isCatalogInfoFilePresent: r.catalogInfoFile?.__typename === "Blob" && r.catalogInfoFile.text !== "",
|
|
853
816
|
visibility: r.visibility
|
|
854
817
|
};
|
|
855
818
|
});
|
|
@@ -861,11 +824,10 @@ class GithubEntityProvider {
|
|
|
861
824
|
return repositories;
|
|
862
825
|
}
|
|
863
826
|
matchesFilters(repositories) {
|
|
864
|
-
|
|
865
|
-
const
|
|
866
|
-
const
|
|
867
|
-
const
|
|
868
|
-
const visibilities = (_f = (_e = this.config.filters) == null ? void 0 : _e.visibility) != null ? _f : [];
|
|
827
|
+
const repositoryFilter = this.config.filters?.repository;
|
|
828
|
+
const topicFilters = this.config.filters?.topic;
|
|
829
|
+
const allowForks = this.config.filters?.allowForks ?? true;
|
|
830
|
+
const visibilities = this.config.filters?.visibility ?? [];
|
|
869
831
|
const matchingRepositories = repositories.filter((r) => {
|
|
870
832
|
const repoTopics = r.repositoryTopics;
|
|
871
833
|
return !r.isArchived && (!repositoryFilter || repositoryFilter.test(r.name)) && satisfiesTopicFilter(repoTopics, topicFilters) && satisfiesForkFilter(allowForks, r.isFork) && satisfiesVisibilityFilter(visibilities, r.visibility) && r.defaultBranchRef;
|
|
@@ -873,8 +835,7 @@ class GithubEntityProvider {
|
|
|
873
835
|
return matchingRepositories;
|
|
874
836
|
}
|
|
875
837
|
createLocationUrl(repository) {
|
|
876
|
-
|
|
877
|
-
const branch = ((_a = this.config.filters) == null ? void 0 : _a.branch) || repository.defaultBranchRef || "-";
|
|
838
|
+
const branch = this.config.filters?.branch || repository.defaultBranchRef || "-";
|
|
878
839
|
const catalogFile = this.config.catalogPath.startsWith("/") ? this.config.catalogPath.substring(1) : this.config.catalogPath;
|
|
879
840
|
return `${repository.url}/blob/${branch}/${catalogFile}`;
|
|
880
841
|
}
|
|
@@ -898,7 +859,6 @@ class GithubEntityProvider {
|
|
|
898
859
|
return [TOPIC_REPO_PUSH];
|
|
899
860
|
}
|
|
900
861
|
async onRepoPush(event) {
|
|
901
|
-
var _a;
|
|
902
862
|
if (!this.connection) {
|
|
903
863
|
throw new Error("Not initialized");
|
|
904
864
|
}
|
|
@@ -911,7 +871,7 @@ class GithubEntityProvider {
|
|
|
911
871
|
const repoName = event.repository.name;
|
|
912
872
|
const repoUrl = event.repository.url;
|
|
913
873
|
this.logger.debug(`handle github:push event for ${repoName} - ${repoUrl}`);
|
|
914
|
-
const branch =
|
|
874
|
+
const branch = this.config.filters?.branch || event.repository.default_branch;
|
|
915
875
|
if (!event.ref.includes(branch)) {
|
|
916
876
|
this.logger.debug(`skipping push event from ref ${event.ref}`);
|
|
917
877
|
return;
|
|
@@ -1025,4 +985,4 @@ exports.getOrganizationsFromUser = getOrganizationsFromUser;
|
|
|
1025
985
|
exports.parseGithubOrgUrl = parseGithubOrgUrl;
|
|
1026
986
|
exports.splitTeamSlug = splitTeamSlug;
|
|
1027
987
|
exports.withLocations = withLocations;
|
|
1028
|
-
//# sourceMappingURL=GithubEntityProvider-
|
|
988
|
+
//# sourceMappingURL=GithubEntityProvider-C-D2ftt3.cjs.js.map
|