@backstage/plugin-catalog-backend-module-github 0.6.1-next.2 → 0.6.2-next.0

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 CHANGED
@@ -1,5 +1,45 @@
1
1
  # @backstage/plugin-catalog-backend-module-github
2
2
 
3
+ ## 0.6.2-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @backstage/backend-tasks@0.5.24-next.0
9
+ - @backstage/backend-common@0.22.1-next.0
10
+ - @backstage/plugin-catalog-backend@1.23.0-next.0
11
+ - @backstage/plugin-events-node@0.3.5-next.0
12
+ - @backstage/backend-plugin-api@0.6.19-next.0
13
+ - @backstage/plugin-catalog-node@1.12.1-next.0
14
+ - @backstage/catalog-client@1.6.5
15
+ - @backstage/catalog-model@1.5.0
16
+ - @backstage/config@1.2.0
17
+ - @backstage/integration@1.11.0
18
+ - @backstage/plugin-catalog-common@1.0.23
19
+
20
+ ## 0.6.1
21
+
22
+ ### Patch Changes
23
+
24
+ - 0b50143: GitHub push events now schedule a refresh on entities that have a `refresh_key` matching the `catalogPath` config itself.
25
+ This allows to support a `catalogPath` configuration that uses glob patterns.
26
+ - f2a2a83: Updated to use the new `catalogAnalysisExtensionPoint` API.
27
+ - 5bdeaa7: Added `alwaysUseDefaultNamespace` option to `GithubMultiOrgEntityProvider`.
28
+
29
+ If set to true, the provider will use `default` as the namespace for all group entities. Groups with the same name across different orgs will be considered the same group.
30
+
31
+ - Updated dependencies
32
+ - @backstage/plugin-catalog-node@1.12.0
33
+ - @backstage/plugin-catalog-backend@1.22.0
34
+ - @backstage/catalog-model@1.5.0
35
+ - @backstage/backend-common@0.22.0
36
+ - @backstage/backend-plugin-api@0.6.18
37
+ - @backstage/backend-tasks@0.5.23
38
+ - @backstage/plugin-events-node@0.3.4
39
+ - @backstage/integration@1.11.0
40
+ - @backstage/catalog-client@1.6.5
41
+ - @backstage/plugin-catalog-common@1.0.23
42
+
3
43
  ## 0.6.1-next.2
4
44
 
5
45
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-backend-module-github",
3
- "version": "0.6.1-next.2",
3
+ "version": "0.6.2-next.0",
4
4
  "main": "../dist/alpha.cjs.js",
5
5
  "types": "../dist/alpha.d.ts"
6
6
  }
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-CiEweAnD.cjs.js');
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');
@@ -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 (integration == null ? void 0 : integration.type) === "github";
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 (!((_a = topicFilter.include) == null ? void 0 : _a.length) && !((_b = topicFilter.exclude) == null ? void 0 : _b.length))
186
+ if (!topicFilter.include?.length && !topicFilter.exclude?.length)
194
187
  return true;
195
- if (((_c = topicFilter.include) == null ? void 0 : _c.length) && !topicFilter.exclude) {
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 && ((_d = topicFilter.exclude) == null ? void 0 : _d.length)) {
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
- var _a, _b;
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 = (_b = entity.metadata.annotations) == null ? void 0 : _b[ANNOTATION_GITHUB_TEAM_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 (!((_a = response.organization) == null ? void 0 : _a.team))
476
+ if (!response.organization?.team)
498
477
  throw new Error(`Found no match for team ${teamSlug}`);
499
- const team = await materialisedTeam((_b = response.organization) == null ? void 0 : _b.team, {
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 = (_a = config.getOptionalString("catalogPath")) != null ? _a : DEFAULT_CATALOG_PATH;
668
- const host = (_b = config.getOptionalString("host")) != null ? _b : "github.com";
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 = (_c = config.getOptionalBoolean("filters.allowForks")) != null ? _c : true;
672
- const topicFilterInclude = config == null ? void 0 : config.getOptionalStringArray(
643
+ const allowForks = config.getOptionalBoolean("filters.allowForks") ?? true;
644
+ const topicFilterInclude = config?.getOptionalStringArray(
673
645
  "filters.topic.include"
674
646
  );
675
- const topicFilterExclude = config == null ? void 0 : config.getOptionalStringArray(
647
+ const topicFilterExclude = config?.getOptionalStringArray(
676
648
  "filters.topic.exclude"
677
649
  );
678
- const validateLocationsExist = (_d = config == null ? void 0 : config.getOptionalBoolean("validateLocationsExist")) != null ? _d : false;
650
+ const validateLocationsExist = config?.getOptionalBoolean("validateLocationsExist") ?? false;
679
651
  const catalogPathContainsWildcard = catalogPath.includes("*");
680
- const visibilityFilterInclude = config == null ? void 0 : config.getOptionalStringArray("filters.visibility");
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
- constructor(config, integration$1, logger, taskRunner, events) {
726
- __publicField(this, "config");
727
- __publicField(this, "events");
728
- __publicField(this, "logger");
729
- __publicField(this, "integration");
730
- __publicField(this, "scheduleFn");
731
- __publicField(this, "connection");
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 = (_a = options.schedule) != null ? _a : options.scheduler.createScheduledTaskRunner(providerConfig.schedule);
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 ((_a = this.events) == null ? void 0 : _a.subscribe({
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: (_a = r.defaultBranchRef) == null ? void 0 : _a.name,
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: ((_b = r.catalogInfoFile) == null ? void 0 : _b.__typename) === "Blob" && r.catalogInfoFile.text !== "",
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
- var _a, _b, _c, _d, _e, _f;
865
- const repositoryFilter = (_a = this.config.filters) == null ? void 0 : _a.repository;
866
- const topicFilters = (_b = this.config.filters) == null ? void 0 : _b.topic;
867
- const allowForks = (_d = (_c = this.config.filters) == null ? void 0 : _c.allowForks) != null ? _d : true;
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
- var _a;
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 = ((_a = this.config.filters) == null ? void 0 : _a.branch) || event.repository.default_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-CiEweAnD.cjs.js.map
988
+ //# sourceMappingURL=GithubEntityProvider-C-D2ftt3.cjs.js.map