@red-hat-developer-hub/backstage-plugin-bulk-import-backend 6.3.0 → 6.4.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +28 -0
  3. package/config.d.ts +9 -1
  4. package/dist/catalog/catalogHttpClient.cjs.js +2 -0
  5. package/dist/catalog/catalogHttpClient.cjs.js.map +1 -1
  6. package/dist/catalog/catalogInfoGenerator.cjs.js +1 -0
  7. package/dist/catalog/catalogInfoGenerator.cjs.js.map +1 -1
  8. package/dist/database/migration.cjs.js +20 -0
  9. package/dist/database/migration.cjs.js.map +1 -0
  10. package/dist/database/repositoryDao.cjs.js +117 -0
  11. package/dist/database/repositoryDao.cjs.js.map +1 -0
  12. package/dist/generated/openapidocument.cjs.js +321 -72
  13. package/dist/generated/openapidocument.cjs.js.map +1 -1
  14. package/dist/github/githubApiService.cjs.js +217 -91
  15. package/dist/github/githubApiService.cjs.js.map +1 -1
  16. package/dist/github/utils/orgUtils.cjs.js +1 -0
  17. package/dist/github/utils/orgUtils.cjs.js.map +1 -1
  18. package/dist/github/utils/prUtils.cjs.js +2 -0
  19. package/dist/github/utils/prUtils.cjs.js.map +1 -1
  20. package/dist/github/utils/repoUtils.cjs.js +1 -38
  21. package/dist/github/utils/repoUtils.cjs.js.map +1 -1
  22. package/dist/github/utils/utils.cjs.js +39 -1
  23. package/dist/github/utils/utils.cjs.js.map +1 -1
  24. package/dist/gitlab/gitlabApiService.cjs.js +102 -0
  25. package/dist/gitlab/gitlabApiService.cjs.js.map +1 -1
  26. package/dist/gitlab/utils/prUtils.cjs.js +1 -0
  27. package/dist/gitlab/utils/prUtils.cjs.js.map +1 -1
  28. package/dist/gitlab/utils/utils.cjs.js +1 -0
  29. package/dist/gitlab/utils/utils.cjs.js.map +1 -1
  30. package/dist/helpers/utils.cjs.js +21 -0
  31. package/dist/helpers/utils.cjs.js.map +1 -1
  32. package/dist/index.d.ts +2 -1
  33. package/dist/plugin.cjs.js +6 -3
  34. package/dist/plugin.cjs.js.map +1 -1
  35. package/dist/service/handlers/import/bulkImports.cjs.js +155 -2
  36. package/dist/service/handlers/import/bulkImports.cjs.js.map +1 -1
  37. package/dist/service/handlers/import/execute-template.cjs.js +264 -0
  38. package/dist/service/handlers/import/execute-template.cjs.js.map +1 -0
  39. package/dist/service/handlers/import/importStatus.cjs.js +1 -1
  40. package/dist/service/handlers/import/importStatus.cjs.js.map +1 -1
  41. package/dist/service/handlers/repository/repositories.cjs.js +1 -0
  42. package/dist/service/handlers/repository/repositories.cjs.js.map +1 -1
  43. package/dist/service/router.cjs.js +179 -24
  44. package/dist/service/router.cjs.js.map +1 -1
  45. package/migrations/20250808122501_migrations.js +53 -0
  46. package/package.json +8 -3
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var integration = require('@backstage/integration');
4
- var gitUrlParse = require('git-url-parse');
5
4
  var catalogUtils = require('../catalog/catalogUtils.cjs.js');
6
5
  require('@backstage/errors');
7
6
  require('@backstage/plugin-permission-common');
@@ -18,10 +17,6 @@ var prUtils = require('./utils/prUtils.cjs.js');
18
17
  var repoUtils = require('./utils/repoUtils.cjs.js');
19
18
  var utils = require('./utils/utils.cjs.js');
20
19
 
21
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
22
-
23
- var gitUrlParse__default = /*#__PURE__*/_interopDefaultCompat(gitUrlParse);
24
-
25
20
  class GithubApiService {
26
21
  logger;
27
22
  integrations;
@@ -37,52 +32,36 @@ class GithubApiService {
37
32
  this.cache = cacheService;
38
33
  }
39
34
  async getRepositoryFromIntegrations(repoUrl) {
40
- const gitUrl = gitUrlParse__default.default(repoUrl);
41
- const ghConfig = this.integrations.github.byUrl(repoUrl)?.config;
42
- if (!ghConfig) {
43
- throw new Error(
44
- `No GitHub integration config found for repo ${repoUrl}. Please add a configuration entry under 'integrations.github`
45
- );
46
- }
47
- const credentials = await utils.getCredentialsForConfig(
48
- this.githubCredentialsProvider,
49
- ghConfig
50
- );
51
- const errors = /* @__PURE__ */ new Map();
52
- let repository = undefined;
53
- for (const credential of credentials) {
54
- const octokit = ghUtils.buildOcto(
55
- {
56
- logger: this.logger,
57
- cache: this.cache
58
- },
59
- { credential, errors, owner: gitUrl.owner },
60
- ghConfig.apiBaseUrl
61
- );
62
- if (!octokit) {
63
- continue;
64
- }
65
- const resp = await octokit.rest.repos.get({
66
- owner: gitUrl.owner,
67
- repo: gitUrl.name
68
- });
69
- const repo = resp?.data;
70
- if (!repo) {
71
- continue;
35
+ const { data, errors } = await utils.fetchFromMatchedIntegration(
36
+ {
37
+ logger: this.logger,
38
+ cache: this.cache,
39
+ githubCredentialsProvider: this.githubCredentialsProvider
40
+ },
41
+ this.integrations,
42
+ repoUrl,
43
+ async (octokit, gitUrl) => {
44
+ const resp = await octokit.rest.repos.get({
45
+ owner: gitUrl.owner,
46
+ repo: gitUrl.name
47
+ });
48
+ const repo = resp?.data;
49
+ if (!repo) {
50
+ return undefined;
51
+ }
52
+ return {
53
+ name: repo.name,
54
+ full_name: repo.full_name,
55
+ url: repo.url,
56
+ html_url: repo.html_url,
57
+ default_branch: repo.default_branch,
58
+ updated_at: repo.updated_at
59
+ };
72
60
  }
73
- repository = {
74
- name: repo.name,
75
- full_name: repo.full_name,
76
- url: repo.url,
77
- html_url: repo.html_url,
78
- default_branch: repo.default_branch,
79
- updated_at: repo.updated_at
80
- };
81
- break;
82
- }
61
+ );
83
62
  return {
84
- repository,
85
- errors: Array.from(errors.values())
63
+ repository: data,
64
+ errors
86
65
  };
87
66
  }
88
67
  async getOrganizationsFromIntegrations(search, pageNumber = handlers.DefaultPageNumber, pageSize = handlers.DefaultPageSize) {
@@ -317,48 +296,197 @@ class GithubApiService {
317
296
  return allAccessibleAppOrgs.has(owner) || allAccessibleTokenOrgs.has(owner) || allAccessibleUsernames.has(owner);
318
297
  });
319
298
  }
320
- async findImportOpenPr(logger, input) {
321
- const ghConfig = this.integrations.github.byUrl(input.repoUrl)?.config;
322
- if (!ghConfig) {
323
- throw new Error(`Could not find GH integration from ${input.repoUrl}`);
324
- }
325
- const gitUrl = gitUrlParse__default.default(input.repoUrl);
326
- const owner = gitUrl.organization;
327
- const repo = gitUrl.name;
328
- const credentials = await this.githubCredentialsProvider.getAllCredentials({
329
- host: ghConfig.host
330
- });
331
- if (credentials.length === 0) {
332
- throw new Error(`No credentials for GH integration`);
333
- }
334
- const branchName = catalogUtils.getBranchName(this.config);
335
- for (const credential of credentials) {
336
- const octo = ghUtils.buildOcto(
337
- {
338
- logger: this.logger,
339
- cache: this.cache
340
- },
341
- { credential, owner },
342
- ghConfig.apiBaseUrl
343
- );
344
- if (!octo) {
345
- continue;
299
+ async getPullRequest(repoUrl, pullRequestNumber) {
300
+ const { data } = await utils.fetchFromMatchedIntegration(
301
+ {
302
+ logger: this.logger,
303
+ cache: this.cache,
304
+ githubCredentialsProvider: this.githubCredentialsProvider
305
+ },
306
+ this.integrations,
307
+ repoUrl,
308
+ async (octokit, gitUrl) => {
309
+ try {
310
+ const resp = await octokit.rest.pulls.get({
311
+ owner: gitUrl.owner,
312
+ repo: gitUrl.name,
313
+ pull_number: pullRequestNumber
314
+ });
315
+ const pr = resp.data;
316
+ return {
317
+ title: pr.title,
318
+ body: pr.body ?? void 0,
319
+ merged: pr.merged,
320
+ lastUpdated: pr.updated_at,
321
+ prSha: pr.head.sha,
322
+ prBranch: pr.head.ref
323
+ };
324
+ } catch (error) {
325
+ loggingUtils.logErrorIfNeeded(this.logger, "Error fetching pull requests", error);
326
+ return undefined;
327
+ }
328
+ }
329
+ );
330
+ return data ?? {};
331
+ }
332
+ async updatePullRequest(repoUrl, pullRequestNumber, title, body) {
333
+ await utils.fetchFromMatchedIntegration(
334
+ {
335
+ logger: this.logger,
336
+ cache: this.cache,
337
+ githubCredentialsProvider: this.githubCredentialsProvider
338
+ },
339
+ this.integrations,
340
+ repoUrl,
341
+ async (octokit, gitUrl) => {
342
+ try {
343
+ await octokit.rest.pulls.update({
344
+ owner: gitUrl.owner,
345
+ repo: gitUrl.name,
346
+ pull_number: pullRequestNumber,
347
+ title,
348
+ body
349
+ });
350
+ return;
351
+ } catch (error) {
352
+ loggingUtils.logErrorIfNeeded(this.logger, "Error updating pull requests", error);
353
+ throw error;
354
+ }
355
+ }
356
+ );
357
+ }
358
+ async createOrUpdateFileInBranch(owner, repo, branchName, fileName, fileContent) {
359
+ try {
360
+ const ghConfig = this.integrations.github.byUrl(
361
+ `https://github.com/${owner}/${repo}`
362
+ )?.config;
363
+ if (!ghConfig) {
364
+ throw new Error(
365
+ `Could not find GH integration from https://github.com/${owner}/${repo}`
366
+ );
367
+ }
368
+ const credentials = await this.githubCredentialsProvider.getAllCredentials({
369
+ host: ghConfig.host
370
+ });
371
+ if (credentials.length === 0) {
372
+ throw new Error(`No credentials for GH integration`);
346
373
  }
347
- try {
348
- return await prUtils.findOpenPRForBranch(
349
- logger,
350
- this.config,
351
- octo,
352
- owner,
353
- repo,
354
- branchName,
355
- input.includeCatalogInfoContent
374
+ for (const credential of credentials) {
375
+ const octokit = ghUtils.buildOcto(
376
+ {
377
+ logger: this.logger,
378
+ cache: this.cache
379
+ },
380
+ { credential, owner },
381
+ ghConfig.apiBaseUrl
356
382
  );
357
- } catch (error) {
358
- loggingUtils.logErrorIfNeeded(this.logger, "Error fetching pull requests", error);
383
+ if (!octokit) {
384
+ continue;
385
+ }
386
+ try {
387
+ const { data: existingFile } = await octokit.rest.repos.getContent({
388
+ owner,
389
+ repo,
390
+ path: fileName,
391
+ ref: branchName
392
+ });
393
+ if (Array.isArray(existingFile) || !("sha" in existingFile)) {
394
+ throw new Error(
395
+ `The content at path ${fileName} is not a file or the response from GitHub does not contain the 'sha' property.`
396
+ );
397
+ }
398
+ await octokit.rest.repos.createOrUpdateFileContents({
399
+ owner,
400
+ repo,
401
+ path: fileName,
402
+ message: `Add ${fileName} config file`,
403
+ content: btoa(fileContent),
404
+ sha: existingFile.sha,
405
+ branch: branchName
406
+ });
407
+ } catch (error) {
408
+ if (error.status === 404) {
409
+ await octokit.rest.repos.createOrUpdateFileContents({
410
+ owner,
411
+ repo,
412
+ path: fileName,
413
+ message: `Add ${fileName} config file`,
414
+ content: btoa(fileContent),
415
+ branch: branchName
416
+ });
417
+ } else {
418
+ throw error;
419
+ }
420
+ }
359
421
  }
422
+ } catch (error) {
423
+ this.logger.error(
424
+ `Error creating or updating file in branch ${branchName}`,
425
+ error
426
+ );
427
+ throw error;
360
428
  }
361
- return {};
429
+ }
430
+ async findImportOpenPr(logger, input) {
431
+ const branchName = catalogUtils.getBranchName(this.config);
432
+ const { data } = await utils.fetchFromMatchedIntegration(
433
+ {
434
+ logger: this.logger,
435
+ cache: this.cache,
436
+ githubCredentialsProvider: this.githubCredentialsProvider
437
+ },
438
+ this.integrations,
439
+ input.repoUrl,
440
+ async (octokit, gitUrl) => {
441
+ try {
442
+ return await prUtils.findOpenPRForBranch(
443
+ logger,
444
+ this.config,
445
+ octokit,
446
+ gitUrl.organization,
447
+ gitUrl.name,
448
+ branchName,
449
+ input.includeCatalogInfoContent
450
+ );
451
+ } catch (error) {
452
+ loggingUtils.logErrorIfNeeded(this.logger, "Error fetching pull requests", error);
453
+ return undefined;
454
+ }
455
+ }
456
+ );
457
+ return data ?? {};
458
+ }
459
+ async getCatalogInfoFile(logger, input) {
460
+ const { data } = await utils.fetchFromMatchedIntegration(
461
+ {
462
+ logger: this.logger,
463
+ cache: this.cache,
464
+ githubCredentialsProvider: this.githubCredentialsProvider
465
+ },
466
+ this.integrations,
467
+ input.repoUrl,
468
+ async (octokit, gitUrl) => {
469
+ try {
470
+ return await prUtils.getCatalogInfoContentFromPR(
471
+ logger,
472
+ this.config,
473
+ octokit,
474
+ gitUrl.organization,
475
+ gitUrl.name,
476
+ input.prNumber,
477
+ input.prHeadSha
478
+ );
479
+ } catch (error) {
480
+ loggingUtils.logErrorIfNeeded(
481
+ this.logger,
482
+ "Error fetching catalog info file content requests",
483
+ error
484
+ );
485
+ return undefined;
486
+ }
487
+ }
488
+ );
489
+ return data;
362
490
  }
363
491
  async submitPrToRepo(logger, input) {
364
492
  const fileName = catalogUtils.getCatalogFilename(this.config);
@@ -410,8 +538,7 @@ class GithubApiService {
410
538
  ref: `heads/${repoData.data.default_branch}`
411
539
  });
412
540
  if (existingPrForBranch.prNum) {
413
- await repoUtils.createOrUpdateFileInBranch(
414
- octo,
541
+ await this.createOrUpdateFileInBranch(
415
542
  owner,
416
543
  repo,
417
544
  branchName,
@@ -472,8 +599,7 @@ class GithubApiService {
472
599
  );
473
600
  }
474
601
  }
475
- await repoUtils.createOrUpdateFileInBranch(
476
- octo,
602
+ await this.createOrUpdateFileInBranch(
477
603
  owner,
478
604
  repo,
479
605
  branchName,
@@ -1 +1 @@
1
- {"version":3,"file":"githubApiService.cjs.js","sources":["../../src/github/githubApiService.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n CacheService,\n LoggerService,\n} from '@backstage/backend-plugin-api';\nimport type { Config } from '@backstage/config';\nimport {\n GithubIntegrationConfig,\n ScmIntegrations,\n} from '@backstage/integration';\n\nimport { Octokit } from '@octokit/rest';\nimport gitUrlParse from 'git-url-parse';\n\nimport { getBranchName, getCatalogFilename } from '../catalog/catalogUtils';\nimport {\n computeTotalCount,\n extractLocationOwnerMap,\n logErrorIfNeeded,\n} from '../helpers';\nimport {\n DefaultPageNumber,\n DefaultPageSize,\n} from '../service/handlers/handlers';\nimport { CustomGithubCredentialsProvider } from './GithubAppManager';\nimport {\n isGithubAppCredential,\n type ExtendedGithubCredentials,\n type GithubFetchError,\n type GithubOrganization,\n type GithubOrganizationResponse,\n type GithubRepository,\n type GithubRepositoryResponse,\n} from './types';\nimport { buildOcto } from './utils/ghUtils';\nimport {\n addGithubAppOrgs,\n addGithubTokenOrgs,\n getAllAppOrgs,\n} from './utils/orgUtils';\nimport { closePRWithComment, findOpenPRForBranch } from './utils/prUtils';\nimport {\n addGithubAppRepositories,\n addGithubTokenOrgRepositories,\n addGithubTokenRepositories,\n createOrUpdateFileInBranch,\n fileExistsInDefaultBranch,\n type ValidatedRepo,\n} from './utils/repoUtils';\nimport {\n executeFunctionOnFirstSuccessfulIntegration,\n fetchFromAllIntegrations,\n getCredentialsForConfig,\n} from './utils/utils';\n\nexport class GithubApiService {\n private readonly logger: LoggerService;\n private readonly integrations: ScmIntegrations;\n private readonly githubCredentialsProvider: CustomGithubCredentialsProvider;\n private readonly config: Config;\n // Cache for storing ETags (used for efficient caching of unchanged data returned by GitHub)\n private readonly cache: CacheService;\n\n constructor(\n logger: LoggerService,\n config: Config,\n cacheService: CacheService,\n ) {\n this.logger = logger;\n this.config = config;\n this.integrations = ScmIntegrations.fromConfig(config);\n this.githubCredentialsProvider =\n CustomGithubCredentialsProvider.fromIntegrations(this.integrations);\n this.cache = cacheService;\n }\n\n async getRepositoryFromIntegrations(repoUrl: string): Promise<{\n repository?: GithubRepository;\n errors?: GithubFetchError[];\n }> {\n const gitUrl = gitUrlParse(repoUrl);\n\n const ghConfig = this.integrations.github.byUrl(repoUrl)?.config;\n if (!ghConfig) {\n throw new Error(\n `No GitHub integration config found for repo ${repoUrl}. Please add a configuration entry under 'integrations.github`,\n );\n }\n\n const credentials = await getCredentialsForConfig(\n this.githubCredentialsProvider,\n ghConfig,\n );\n const errors = new Map<number, GithubFetchError>();\n let repository: GithubRepository | undefined = undefined;\n for (const credential of credentials) {\n const octokit = buildOcto(\n {\n logger: this.logger,\n cache: this.cache,\n },\n { credential, errors, owner: gitUrl.owner },\n ghConfig.apiBaseUrl,\n );\n if (!octokit) {\n continue;\n }\n const resp = await octokit.rest.repos.get({\n owner: gitUrl.owner,\n repo: gitUrl.name,\n });\n const repo = resp?.data;\n if (!repo) {\n continue;\n }\n repository = {\n name: repo.name,\n full_name: repo.full_name,\n url: repo.url,\n html_url: repo.html_url,\n default_branch: repo.default_branch,\n updated_at: repo.updated_at,\n };\n break;\n }\n\n return {\n repository,\n errors: Array.from(errors.values()),\n };\n }\n\n async getOrganizationsFromIntegrations(\n search?: string,\n pageNumber: number = DefaultPageNumber,\n pageSize: number = DefaultPageSize,\n ): Promise<GithubOrganizationResponse> {\n const orgs = new Map<string, GithubOrganization>();\n const result = await fetchFromAllIntegrations(\n {\n logger: this.logger,\n cache: this.cache,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n dataFetcher: async (\n octokit: Octokit,\n credential: ExtendedGithubCredentials,\n ghConfig: GithubIntegrationConfig,\n ) => {\n const dataFetchErrors = new Map<number, GithubFetchError>();\n const resp = isGithubAppCredential(credential)\n ? await addGithubAppOrgs(\n {\n logger: this.logger,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n octokit,\n ghConfig,\n {\n credentialAccountLogin: credential.accountLogin,\n search,\n orgs,\n errors: dataFetchErrors,\n },\n )\n : await addGithubTokenOrgs(\n {\n logger: this.logger,\n },\n octokit,\n credential,\n {\n search,\n orgs,\n pageNumber,\n pageSize,\n errors: dataFetchErrors,\n },\n );\n\n this.logger.debug(\n `Got ${resp.totalCount} org(s) for ${ghConfig.host}`,\n );\n return {\n result: resp.totalCount ?? 0,\n errors: Array.from(dataFetchErrors.values()),\n };\n },\n },\n );\n\n const orgList = Array.from(orgs.values());\n const totalCount = computeTotalCount(orgList, result.data, pageSize);\n return {\n organizations: orgList,\n errors: Array.from(result.errors?.values() ?? []),\n totalCount,\n };\n }\n\n async getOrgRepositoriesFromIntegrations(\n orgName: string,\n search?: string,\n pageNumber: number = DefaultPageNumber,\n pageSize: number = DefaultPageSize,\n ): Promise<GithubRepositoryResponse> {\n const repositories = new Map<string, GithubRepository>();\n const result = await fetchFromAllIntegrations(\n {\n logger: this.logger,\n cache: this.cache,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n dataFetcher: async (\n octokit: Octokit,\n credential: ExtendedGithubCredentials,\n ghConfig: GithubIntegrationConfig,\n ) => {\n const dataFetchErrors = new Map<number, GithubFetchError>();\n let resp: { totalCount?: number };\n if (isGithubAppCredential(credential)) {\n if (credential.accountLogin !== orgName) {\n return {};\n }\n resp = await addGithubAppRepositories(\n {\n logger: this.logger,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n octokit,\n credential,\n ghConfig,\n repositories,\n dataFetchErrors,\n {\n search,\n pageNumber,\n pageSize,\n },\n );\n } else {\n resp = await addGithubTokenOrgRepositories(\n {\n logger: this.logger,\n },\n octokit,\n credential,\n orgName,\n repositories,\n dataFetchErrors,\n {\n search,\n pageNumber,\n pageSize,\n },\n );\n }\n this.logger.debug(\n `Got ${resp.totalCount} org repo(s) for ${ghConfig.host}`,\n );\n return {\n stopFetchingData: true,\n result: resp.totalCount ?? 0,\n errors: Array.from(dataFetchErrors.values()),\n };\n },\n },\n );\n\n const repoList = Array.from(repositories.values());\n const totalCount = computeTotalCount(repoList, result.data, pageSize);\n return {\n repositories: repoList,\n errors: Array.from(result.errors?.values() ?? []),\n totalCount,\n };\n }\n\n /**\n * Returns GithubRepositoryResponse containing:\n * - a list of unique repositories the github integrations have access to\n * - a list of errors encountered by each app and/or token (if any exist)\n */\n async getRepositoriesFromIntegrations(\n search?: string,\n pageNumber: number = DefaultPageNumber,\n pageSize: number = DefaultPageSize,\n ): Promise<GithubRepositoryResponse> {\n const repositories = new Map<string, GithubRepository>();\n const result = await fetchFromAllIntegrations(\n {\n logger: this.logger,\n cache: this.cache,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n dataFetcher: async (\n octokit: Octokit,\n credential: ExtendedGithubCredentials,\n ghConfig: GithubIntegrationConfig,\n ) => {\n const dataFetchErrors = new Map<number, GithubFetchError>();\n const resp = isGithubAppCredential(credential)\n ? await addGithubAppRepositories(\n {\n logger: this.logger,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n octokit,\n credential,\n ghConfig,\n repositories,\n dataFetchErrors,\n {\n search,\n pageNumber,\n pageSize,\n },\n )\n : await addGithubTokenRepositories(\n {\n logger: this.logger,\n },\n octokit,\n credential,\n repositories,\n dataFetchErrors,\n {\n search,\n pageNumber,\n pageSize,\n },\n );\n this.logger.debug(\n `Got ${resp.totalCount} repo(s) for ${ghConfig.host}`,\n );\n return {\n result: resp.totalCount ?? 0,\n errors: Array.from(dataFetchErrors.values()),\n };\n },\n },\n );\n\n const repoList = Array.from(repositories.values());\n const totalCount = computeTotalCount(repoList, result.data, pageSize);\n return {\n repositories: repoList,\n errors: Array.from(result.errors?.values() ?? []),\n totalCount,\n };\n }\n\n async filterLocationsAccessibleFromIntegrations(\n locationUrls: string[],\n ): Promise<string[]> {\n const locationGitOwnerMap = extractLocationOwnerMap(locationUrls);\n\n const allAccessibleAppOrgs = new Set<string>();\n const allAccessibleTokenOrgs = new Set<string>();\n const allAccessibleUsernames = new Set<string>();\n await fetchFromAllIntegrations(\n {\n logger: this.logger,\n cache: this.cache,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n dataFetcher: async (\n octokit: Octokit,\n credential: ExtendedGithubCredentials,\n ghConfig: GithubIntegrationConfig,\n ) => {\n if (isGithubAppCredential(credential)) {\n const appOrgMap = await getAllAppOrgs(\n this.githubCredentialsProvider,\n ghConfig,\n credential.accountLogin,\n );\n for (const [_, ghOrg] of appOrgMap) {\n allAccessibleAppOrgs.add(ghOrg.name);\n }\n } else {\n // find authenticated GitHub owner...\n const username = (await octokit.rest.users.getAuthenticated())?.data\n ?.login;\n if (username) {\n allAccessibleUsernames.add(username);\n }\n // ... along with orgs accessible from the token auth\n (await octokit.paginate(octokit.rest.orgs.listForAuthenticatedUser))\n ?.map(org => org.login)\n ?.forEach(orgName => allAccessibleTokenOrgs.add(orgName));\n }\n return {};\n },\n },\n );\n\n return locationUrls.filter(loc => {\n if (!locationGitOwnerMap.has(loc)) {\n return false;\n }\n const owner = locationGitOwnerMap.get(loc)!;\n return (\n allAccessibleAppOrgs.has(owner) ||\n allAccessibleTokenOrgs.has(owner) ||\n allAccessibleUsernames.has(owner)\n );\n });\n }\n\n async findImportOpenPr(\n logger: LoggerService,\n input: {\n repoUrl: string;\n includeCatalogInfoContent?: boolean;\n },\n ): Promise<{\n prNum?: number;\n prUrl?: string;\n prTitle?: string;\n prBody?: string;\n prCatalogInfoContent?: string;\n lastUpdate?: string;\n }> {\n const ghConfig = this.integrations.github.byUrl(input.repoUrl)?.config;\n if (!ghConfig) {\n throw new Error(`Could not find GH integration from ${input.repoUrl}`);\n }\n\n const gitUrl = gitUrlParse(input.repoUrl);\n const owner = gitUrl.organization;\n const repo = gitUrl.name;\n\n const credentials = await this.githubCredentialsProvider.getAllCredentials({\n host: ghConfig.host,\n });\n if (credentials.length === 0) {\n throw new Error(`No credentials for GH integration`);\n }\n\n const branchName = getBranchName(this.config);\n for (const credential of credentials) {\n const octo = buildOcto(\n {\n logger: this.logger,\n cache: this.cache,\n },\n { credential, owner },\n ghConfig.apiBaseUrl,\n );\n if (!octo) {\n continue;\n }\n try {\n return await findOpenPRForBranch(\n logger,\n this.config,\n octo,\n owner,\n repo,\n branchName,\n input.includeCatalogInfoContent,\n );\n } catch (error: any) {\n logErrorIfNeeded(this.logger, 'Error fetching pull requests', error);\n }\n }\n return {};\n }\n\n async submitPrToRepo(\n logger: LoggerService,\n input: {\n repoUrl: string;\n gitUrl: gitUrlParse.GitUrl;\n defaultBranch?: string;\n prTitle: string;\n prBody: string;\n catalogInfoContent: string;\n },\n ): Promise<{\n prUrl?: string;\n prNumber?: number;\n hasChanges?: boolean;\n lastUpdate?: string;\n errors?: string[];\n }> {\n const fileName = getCatalogFilename(this.config);\n const errors: any[] = [];\n\n const result = await executeFunctionOnFirstSuccessfulIntegration(\n {\n logger: this.logger,\n cache: this.cache,\n config: this.config,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n repoUrl: input.repoUrl,\n fn: async (\n validatedRepo: ValidatedRepo,\n octo: Octokit,\n ): Promise<{\n successful: boolean;\n result?: {\n prUrl?: string;\n prNumber?: number;\n hasChanges?: boolean;\n lastUpdate?: string;\n };\n }> => {\n const { owner, repo, branchName } = validatedRepo;\n try {\n // Check if there is already a catalogInfo in the default branch\n const catalogInfoFileExists = await fileExistsInDefaultBranch(\n logger,\n octo,\n owner,\n repo,\n fileName,\n input.defaultBranch,\n );\n if (catalogInfoFileExists) {\n // No need to create a PR => component will be imported as is\n return {\n successful: true,\n result: {\n hasChanges: false,\n },\n };\n }\n\n const existingPrForBranch = await findOpenPRForBranch(\n logger,\n this.config,\n octo,\n owner,\n repo,\n branchName,\n );\n\n const repoData = await octo.rest.repos.get({\n owner,\n repo,\n });\n const parentRef = await octo.rest.git.getRef({\n owner,\n repo,\n ref: `heads/${repoData.data.default_branch}`,\n });\n if (existingPrForBranch.prNum) {\n await createOrUpdateFileInBranch(\n octo,\n owner,\n repo,\n branchName,\n fileName,\n input.catalogInfoContent,\n );\n const pullRequestResponse = await octo.rest.pulls.update({\n owner,\n repo,\n pull_number: existingPrForBranch.prNum,\n title: input.prTitle,\n body: input.prBody,\n head: branchName,\n base: repoData.data.default_branch,\n });\n return {\n successful: true,\n result: {\n prNumber: existingPrForBranch.prNum,\n prUrl: pullRequestResponse.data.html_url,\n lastUpdate: pullRequestResponse.data.updated_at,\n },\n };\n }\n\n let branchExists = false;\n try {\n await octo.rest.git.getRef({\n owner,\n repo,\n ref: `heads/${branchName}`,\n });\n branchExists = true;\n } catch (error: any) {\n if (error.status === 404) {\n await octo.rest.git.createRef({\n owner,\n repo,\n ref: `refs/heads/${branchName}`,\n sha: parentRef.data.object.sha,\n });\n } else {\n throw error;\n }\n }\n\n if (branchExists) {\n // update it in case it is outdated compared to the base branch\n try {\n await octo.repos.merge({\n owner: owner,\n repo: repo,\n base: branchName,\n head: repoData.data.default_branch,\n });\n } catch (error: any) {\n logErrorIfNeeded(\n this.logger,\n `Could not merge default branch ${repoData.data.default_branch} into import branch ${branchName}`,\n error,\n );\n }\n }\n\n await createOrUpdateFileInBranch(\n octo,\n owner,\n repo,\n branchName,\n fileName,\n input.catalogInfoContent,\n );\n\n const pullRequestResponse = await octo.rest.pulls.create({\n owner,\n repo,\n title: input.prTitle,\n body: input.prBody,\n head: branchName,\n base: repoData.data.default_branch,\n });\n return {\n successful: true,\n result: {\n prNumber: pullRequestResponse.data.number,\n prUrl: pullRequestResponse.data.html_url,\n lastUpdate: pullRequestResponse.data.updated_at,\n hasChanges: true,\n },\n };\n } catch (e: any) {\n logErrorIfNeeded(\n this.logger,\n `Couldn't create PR in ${input.repoUrl}`,\n e,\n );\n errors.push(e.message);\n return { successful: false };\n }\n },\n },\n );\n\n if (result) {\n return result;\n }\n\n logger.warn(\n `Tried all possible GitHub credentials, but could not create PR in ${input.repoUrl}. Please try again later...`,\n );\n\n return {\n errors: errors,\n };\n }\n\n async hasFileInRepo(input: {\n repoUrl: string;\n defaultBranch?: string;\n fileName: string;\n }) {\n const fileExists = await executeFunctionOnFirstSuccessfulIntegration(\n {\n logger: this.logger,\n cache: this.cache,\n config: this.config,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n repoUrl: input.repoUrl,\n fn: async (validatedRepo: ValidatedRepo, octo: Octokit) => {\n const { owner, repo } = validatedRepo;\n const exists = await fileExistsInDefaultBranch(\n this.logger,\n octo,\n owner,\n repo,\n input.fileName,\n input.defaultBranch,\n );\n if (exists === undefined) {\n return { successful: false };\n }\n return { successful: true, result: exists };\n },\n },\n );\n\n if (fileExists === undefined) {\n throw new Error(\n `Could not determine if repo at ${input.repoUrl} already has a file named ${input.fileName} in its default branch (${input.defaultBranch})`,\n );\n }\n\n return fileExists;\n }\n\n async closeImportPR(\n logger: LoggerService,\n input: {\n repoUrl: string;\n gitUrl: gitUrlParse.GitUrl;\n comment: string;\n },\n ) {\n await executeFunctionOnFirstSuccessfulIntegration(\n {\n logger: this.logger,\n cache: this.cache,\n config: this.config,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n repoUrl: input.repoUrl,\n fn: async (validatedRepo: ValidatedRepo, octo: Octokit) => {\n const { owner, repo, branchName } = validatedRepo;\n try {\n const existingPrForBranch = await findOpenPRForBranch(\n logger,\n this.config,\n octo,\n owner,\n repo,\n branchName,\n );\n if (existingPrForBranch.prNum) {\n await closePRWithComment(\n octo,\n owner,\n repo,\n existingPrForBranch.prNum,\n input.comment,\n );\n }\n return { successful: true };\n } catch (e: any) {\n logErrorIfNeeded(\n this.logger,\n `Couldn't close PR in ${input.repoUrl}`,\n e,\n );\n return { successful: false };\n }\n },\n },\n );\n }\n\n async deleteImportBranch(input: {\n repoUrl: string;\n gitUrl: gitUrlParse.GitUrl;\n }) {\n await executeFunctionOnFirstSuccessfulIntegration(\n {\n logger: this.logger,\n cache: this.cache,\n config: this.config,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n repoUrl: input.repoUrl,\n fn: async (validatedRepo: ValidatedRepo, octo: Octokit) => {\n const { owner, repo, branchName } = validatedRepo;\n try {\n await octo.git.deleteRef({\n owner: owner,\n repo: repo,\n ref: `heads/${branchName}`,\n });\n return { successful: true };\n } catch (e: any) {\n logErrorIfNeeded(\n this.logger,\n `Couldn't close import PR and/or delete import branch in ${input.repoUrl}`,\n e,\n );\n return { successful: false };\n }\n },\n },\n );\n }\n\n async isRepoEmpty(input: { repoUrl: string }) {\n return await executeFunctionOnFirstSuccessfulIntegration(\n {\n logger: this.logger,\n cache: this.cache,\n config: this.config,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n repoUrl: input.repoUrl,\n fn: async (validatedRepo: ValidatedRepo, octo: Octokit) => {\n const { owner, repo } = validatedRepo;\n const resp = await octo.rest.repos.listContributors({\n owner: owner,\n repo: repo,\n page: 1,\n per_page: 1,\n });\n const status = resp.status as 200 | 204;\n return { successful: true, result: status === 204 };\n },\n },\n );\n }\n}\n"],"names":["ScmIntegrations","CustomGithubCredentialsProvider","gitUrlParse","getCredentialsForConfig","buildOcto","DefaultPageNumber","DefaultPageSize","fetchFromAllIntegrations","isGithubAppCredential","addGithubAppOrgs","addGithubTokenOrgs","computeTotalCount","addGithubAppRepositories","addGithubTokenOrgRepositories","addGithubTokenRepositories","extractLocationOwnerMap","getAllAppOrgs","getBranchName","findOpenPRForBranch","logErrorIfNeeded","getCatalogFilename","executeFunctionOnFirstSuccessfulIntegration","fileExistsInDefaultBranch","createOrUpdateFileInBranch","pullRequestResponse","closePRWithComment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsEO,MAAM,gBAAiB,CAAA;AAAA,EACX,MAAA;AAAA,EACA,YAAA;AAAA,EACA,yBAAA;AAAA,EACA,MAAA;AAAA;AAAA,EAEA,KAAA;AAAA,EAEjB,WAAA,CACE,MACA,EAAA,MAAA,EACA,YACA,EAAA;AACA,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA;AACd,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA;AACd,IAAK,IAAA,CAAA,YAAA,GAAeA,2BAAgB,CAAA,UAAA,CAAW,MAAM,CAAA;AACrD,IAAA,IAAA,CAAK,yBACH,GAAAC,gDAAA,CAAgC,gBAAiB,CAAA,IAAA,CAAK,YAAY,CAAA;AACpE,IAAA,IAAA,CAAK,KAAQ,GAAA,YAAA;AAAA;AACf,EAEA,MAAM,8BAA8B,OAGjC,EAAA;AACD,IAAM,MAAA,MAAA,GAASC,6BAAY,OAAO,CAAA;AAElC,IAAA,MAAM,WAAW,IAAK,CAAA,YAAA,CAAa,MAAO,CAAA,KAAA,CAAM,OAAO,CAAG,EAAA,MAAA;AAC1D,IAAA,IAAI,CAAC,QAAU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CAAA;AAAA,YACN,QAAU,EAAA;AAAA,WACX,CAAA;AACD,UAAA,MAAM,SAAS,IAAK,CAAA,MAAA;AACpB,UAAA,OAAO,EAAE,UAAA,EAAY,IAAM,EAAA,MAAA,EAAQ,WAAW,GAAI,EAAA;AAAA;AACpD;AACF,KACF;AAAA;AAEJ;;;;"}
1
+ {"version":3,"file":"githubApiService.cjs.js","sources":["../../src/github/githubApiService.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n CacheService,\n LoggerService,\n} from '@backstage/backend-plugin-api';\nimport type { Config } from '@backstage/config';\nimport {\n GithubIntegrationConfig,\n ScmIntegrations,\n} from '@backstage/integration';\n\nimport { Octokit } from '@octokit/rest';\nimport gitUrlParse from 'git-url-parse';\n\nimport { getBranchName, getCatalogFilename } from '../catalog/catalogUtils';\nimport {\n computeTotalCount,\n extractLocationOwnerMap,\n logErrorIfNeeded,\n} from '../helpers';\nimport {\n DefaultPageNumber,\n DefaultPageSize,\n} from '../service/handlers/handlers';\nimport { CustomGithubCredentialsProvider } from './GithubAppManager';\nimport {\n isGithubAppCredential,\n type ExtendedGithubCredentials,\n type GithubFetchError,\n type GithubOrganization,\n type GithubOrganizationResponse,\n type GithubRepository,\n type GithubRepositoryResponse,\n} from './types';\nimport { buildOcto } from './utils/ghUtils';\nimport {\n addGithubAppOrgs,\n addGithubTokenOrgs,\n getAllAppOrgs,\n} from './utils/orgUtils';\nimport {\n closePRWithComment,\n findOpenPRForBranch,\n getCatalogInfoContentFromPR,\n} from './utils/prUtils';\nimport {\n addGithubAppRepositories,\n addGithubTokenOrgRepositories,\n addGithubTokenRepositories,\n fileExistsInDefaultBranch,\n type ValidatedRepo,\n} from './utils/repoUtils';\nimport {\n executeFunctionOnFirstSuccessfulIntegration,\n fetchFromAllIntegrations,\n fetchFromMatchedIntegration,\n} from './utils/utils';\n\nexport class GithubApiService {\n private readonly logger: LoggerService;\n private readonly integrations: ScmIntegrations;\n public readonly githubCredentialsProvider: CustomGithubCredentialsProvider;\n private readonly config: Config;\n // Cache for storing ETags (used for efficient caching of unchanged data returned by GitHub)\n private readonly cache: CacheService;\n\n constructor(\n logger: LoggerService,\n config: Config,\n cacheService: CacheService,\n ) {\n this.logger = logger;\n this.config = config;\n this.integrations = ScmIntegrations.fromConfig(config);\n this.githubCredentialsProvider =\n CustomGithubCredentialsProvider.fromIntegrations(this.integrations);\n this.cache = cacheService;\n }\n\n async getRepositoryFromIntegrations(repoUrl: string): Promise<{\n repository?: GithubRepository;\n errors?: GithubFetchError[];\n }> {\n const { data, errors } = await fetchFromMatchedIntegration(\n {\n logger: this.logger,\n cache: this.cache,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n repoUrl,\n async (octokit, gitUrl) => {\n const resp = await octokit.rest.repos.get({\n owner: gitUrl.owner,\n repo: gitUrl.name,\n });\n const repo = resp?.data;\n if (!repo) {\n return undefined;\n }\n return {\n name: repo.name,\n full_name: repo.full_name,\n url: repo.url,\n html_url: repo.html_url,\n default_branch: repo.default_branch,\n updated_at: repo.updated_at,\n };\n },\n );\n\n return {\n repository: data,\n errors,\n };\n }\n\n async getOrganizationsFromIntegrations(\n search?: string,\n pageNumber: number = DefaultPageNumber,\n pageSize: number = DefaultPageSize,\n ): Promise<GithubOrganizationResponse> {\n const orgs = new Map<string, GithubOrganization>();\n const result = await fetchFromAllIntegrations(\n {\n logger: this.logger,\n cache: this.cache,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n dataFetcher: async (\n octokit: Octokit,\n credential: ExtendedGithubCredentials,\n ghConfig: GithubIntegrationConfig,\n ) => {\n const dataFetchErrors = new Map<number, GithubFetchError>();\n const resp = isGithubAppCredential(credential)\n ? await addGithubAppOrgs(\n {\n logger: this.logger,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n octokit,\n ghConfig,\n {\n credentialAccountLogin: credential.accountLogin,\n search,\n orgs,\n errors: dataFetchErrors,\n },\n )\n : await addGithubTokenOrgs(\n {\n logger: this.logger,\n },\n octokit,\n credential,\n {\n search,\n orgs,\n pageNumber,\n pageSize,\n errors: dataFetchErrors,\n },\n );\n\n this.logger.debug(\n `Got ${resp.totalCount} org(s) for ${ghConfig.host}`,\n );\n return {\n result: resp.totalCount ?? 0,\n errors: Array.from(dataFetchErrors.values()),\n };\n },\n },\n );\n\n const orgList = Array.from(orgs.values());\n const totalCount = computeTotalCount(orgList, result.data, pageSize);\n return {\n organizations: orgList,\n errors: Array.from(result.errors?.values() ?? []),\n totalCount,\n };\n }\n\n async getOrgRepositoriesFromIntegrations(\n orgName: string,\n search?: string,\n pageNumber: number = DefaultPageNumber,\n pageSize: number = DefaultPageSize,\n ): Promise<GithubRepositoryResponse> {\n const repositories = new Map<string, GithubRepository>();\n const result = await fetchFromAllIntegrations(\n {\n logger: this.logger,\n cache: this.cache,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n dataFetcher: async (\n octokit: Octokit,\n credential: ExtendedGithubCredentials,\n ghConfig: GithubIntegrationConfig,\n ) => {\n const dataFetchErrors = new Map<number, GithubFetchError>();\n let resp: { totalCount?: number };\n if (isGithubAppCredential(credential)) {\n if (credential.accountLogin !== orgName) {\n return {};\n }\n resp = await addGithubAppRepositories(\n {\n logger: this.logger,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n octokit,\n credential,\n ghConfig,\n repositories,\n dataFetchErrors,\n {\n search,\n pageNumber,\n pageSize,\n },\n );\n } else {\n resp = await addGithubTokenOrgRepositories(\n {\n logger: this.logger,\n },\n octokit,\n credential,\n orgName,\n repositories,\n dataFetchErrors,\n {\n search,\n pageNumber,\n pageSize,\n },\n );\n }\n this.logger.debug(\n `Got ${resp.totalCount} org repo(s) for ${ghConfig.host}`,\n );\n return {\n stopFetchingData: true,\n result: resp.totalCount ?? 0,\n errors: Array.from(dataFetchErrors.values()),\n };\n },\n },\n );\n\n const repoList = Array.from(repositories.values());\n const totalCount = computeTotalCount(repoList, result.data, pageSize);\n return {\n repositories: repoList,\n errors: Array.from(result.errors?.values() ?? []),\n totalCount,\n };\n }\n\n /**\n * Returns GithubRepositoryResponse containing:\n * - a list of unique repositories the github integrations have access to\n * - a list of errors encountered by each app and/or token (if any exist)\n */\n async getRepositoriesFromIntegrations(\n search?: string,\n pageNumber: number = DefaultPageNumber,\n pageSize: number = DefaultPageSize,\n ): Promise<GithubRepositoryResponse> {\n const repositories = new Map<string, GithubRepository>();\n const result = await fetchFromAllIntegrations(\n {\n logger: this.logger,\n cache: this.cache,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n dataFetcher: async (\n octokit: Octokit,\n credential: ExtendedGithubCredentials,\n ghConfig: GithubIntegrationConfig,\n ) => {\n const dataFetchErrors = new Map<number, GithubFetchError>();\n const resp = isGithubAppCredential(credential)\n ? await addGithubAppRepositories(\n {\n logger: this.logger,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n octokit,\n credential,\n ghConfig,\n repositories,\n dataFetchErrors,\n {\n search,\n pageNumber,\n pageSize,\n },\n )\n : await addGithubTokenRepositories(\n {\n logger: this.logger,\n },\n octokit,\n credential,\n repositories,\n dataFetchErrors,\n {\n search,\n pageNumber,\n pageSize,\n },\n );\n this.logger.debug(\n `Got ${resp.totalCount} repo(s) for ${ghConfig.host}`,\n );\n return {\n result: resp.totalCount ?? 0,\n errors: Array.from(dataFetchErrors.values()),\n };\n },\n },\n );\n\n const repoList = Array.from(repositories.values());\n const totalCount = computeTotalCount(repoList, result.data, pageSize);\n return {\n repositories: repoList,\n errors: Array.from(result.errors?.values() ?? []),\n totalCount,\n };\n }\n\n async filterLocationsAccessibleFromIntegrations(\n locationUrls: string[],\n ): Promise<string[]> {\n const locationGitOwnerMap = extractLocationOwnerMap(locationUrls);\n\n const allAccessibleAppOrgs = new Set<string>();\n const allAccessibleTokenOrgs = new Set<string>();\n const allAccessibleUsernames = new Set<string>();\n await fetchFromAllIntegrations(\n {\n logger: this.logger,\n cache: this.cache,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n dataFetcher: async (\n octokit: Octokit,\n credential: ExtendedGithubCredentials,\n ghConfig: GithubIntegrationConfig,\n ) => {\n if (isGithubAppCredential(credential)) {\n const appOrgMap = await getAllAppOrgs(\n this.githubCredentialsProvider,\n ghConfig,\n credential.accountLogin,\n );\n for (const [_, ghOrg] of appOrgMap) {\n allAccessibleAppOrgs.add(ghOrg.name);\n }\n } else {\n // find authenticated GitHub owner...\n const username = (await octokit.rest.users.getAuthenticated())?.data\n ?.login;\n if (username) {\n allAccessibleUsernames.add(username);\n }\n // ... along with orgs accessible from the token auth\n (await octokit.paginate(octokit.rest.orgs.listForAuthenticatedUser))\n ?.map(org => org.login)\n ?.forEach(orgName => allAccessibleTokenOrgs.add(orgName));\n }\n return {};\n },\n },\n );\n\n return locationUrls.filter(loc => {\n if (!locationGitOwnerMap.has(loc)) {\n return false;\n }\n const owner = locationGitOwnerMap.get(loc)!;\n return (\n allAccessibleAppOrgs.has(owner) ||\n allAccessibleTokenOrgs.has(owner) ||\n allAccessibleUsernames.has(owner)\n );\n });\n }\n\n async getPullRequest(\n repoUrl: string,\n pullRequestNumber: number,\n ): Promise<{\n title?: string;\n body?: string;\n merged?: boolean;\n lastUpdated?: string;\n prSha?: string;\n prBranch?: string;\n }> {\n const { data } = await fetchFromMatchedIntegration(\n {\n logger: this.logger,\n cache: this.cache,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n repoUrl,\n async (octokit, gitUrl) => {\n try {\n const resp = await octokit.rest.pulls.get({\n owner: gitUrl.owner,\n repo: gitUrl.name,\n pull_number: pullRequestNumber,\n });\n const pr = resp.data;\n return {\n title: pr.title,\n body: pr.body ?? undefined,\n merged: pr.merged,\n lastUpdated: pr.updated_at,\n prSha: pr.head.sha,\n prBranch: pr.head.ref,\n };\n } catch (error: any) {\n logErrorIfNeeded(this.logger, 'Error fetching pull requests', error);\n return undefined;\n }\n },\n );\n return data ?? {};\n }\n\n async updatePullRequest(\n repoUrl: string,\n pullRequestNumber: number,\n title?: string,\n body?: string,\n ): Promise<void> {\n await fetchFromMatchedIntegration(\n {\n logger: this.logger,\n cache: this.cache,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n repoUrl,\n async (octokit, gitUrl) => {\n try {\n await octokit.rest.pulls.update({\n owner: gitUrl.owner,\n repo: gitUrl.name,\n pull_number: pullRequestNumber,\n title: title,\n body: body,\n });\n return;\n } catch (error: any) {\n logErrorIfNeeded(this.logger, 'Error updating pull requests', error);\n throw error;\n }\n },\n );\n }\n\n async createOrUpdateFileInBranch(\n owner: string,\n repo: string,\n branchName: string,\n fileName: string,\n fileContent: string,\n ): Promise<void> {\n try {\n const ghConfig = this.integrations.github.byUrl(\n `https://github.com/${owner}/${repo}`,\n )?.config;\n if (!ghConfig) {\n throw new Error(\n `Could not find GH integration from https://github.com/${owner}/${repo}`,\n );\n }\n\n const credentials =\n await this.githubCredentialsProvider.getAllCredentials({\n host: ghConfig.host,\n });\n\n if (credentials.length === 0) {\n throw new Error(`No credentials for GH integration`);\n }\n\n for (const credential of credentials) {\n const octokit = buildOcto(\n {\n logger: this.logger,\n cache: this.cache,\n },\n { credential, owner },\n ghConfig.apiBaseUrl,\n );\n if (!octokit) {\n continue;\n }\n\n try {\n const { data: existingFile } = await octokit.rest.repos.getContent({\n owner: owner,\n repo: repo,\n path: fileName,\n ref: branchName,\n });\n // Response can either be a directory (array of files) or a single file element. In this case, we ensure it has the sha property to update it.\n if (Array.isArray(existingFile) || !('sha' in existingFile)) {\n throw new Error(\n `The content at path ${fileName} is not a file or the response from GitHub does not contain the 'sha' property.`,\n );\n }\n // If the file already exists, update it\n await octokit.rest.repos.createOrUpdateFileContents({\n owner,\n repo,\n path: fileName,\n message: `Add ${fileName} config file`,\n content: btoa(fileContent),\n sha: existingFile.sha,\n branch: branchName,\n });\n } catch (error: any) {\n if (error.status === 404) {\n // If the file does not exist, create it\n await octokit.rest.repos.createOrUpdateFileContents({\n owner,\n repo,\n path: fileName,\n message: `Add ${fileName} config file`,\n content: btoa(fileContent),\n branch: branchName,\n });\n } else {\n throw error;\n }\n }\n }\n } catch (error: any) {\n this.logger.error(\n `Error creating or updating file in branch ${branchName}`,\n error,\n );\n throw error;\n }\n }\n\n async findImportOpenPr(\n logger: LoggerService,\n input: {\n repoUrl: string;\n includeCatalogInfoContent?: boolean;\n },\n ): Promise<{\n prNum?: number;\n prUrl?: string;\n prTitle?: string;\n prBody?: string;\n prCatalogInfoContent?: string;\n lastUpdate?: string;\n }> {\n const branchName = getBranchName(this.config);\n const { data } = await fetchFromMatchedIntegration(\n {\n logger: this.logger,\n cache: this.cache,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n input.repoUrl,\n async (octokit, gitUrl) => {\n try {\n return await findOpenPRForBranch(\n logger,\n this.config,\n octokit,\n gitUrl.organization,\n gitUrl.name,\n branchName,\n input.includeCatalogInfoContent,\n );\n } catch (error: any) {\n logErrorIfNeeded(this.logger, 'Error fetching pull requests', error);\n return undefined;\n }\n },\n );\n return data ?? {};\n }\n\n async getCatalogInfoFile(\n logger: LoggerService,\n input: {\n repoUrl: string;\n prNumber: number;\n prHeadSha: string;\n },\n ): Promise<string | undefined> {\n const { data } = await fetchFromMatchedIntegration(\n {\n logger: this.logger,\n cache: this.cache,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n input.repoUrl,\n async (octokit, gitUrl) => {\n try {\n return await getCatalogInfoContentFromPR(\n logger,\n this.config,\n octokit,\n gitUrl.organization,\n gitUrl.name,\n input.prNumber,\n input.prHeadSha,\n );\n } catch (error: any) {\n logErrorIfNeeded(\n this.logger,\n 'Error fetching catalog info file content requests',\n error,\n );\n return undefined;\n }\n },\n );\n return data;\n }\n\n async submitPrToRepo(\n logger: LoggerService,\n input: {\n repoUrl: string;\n gitUrl: gitUrlParse.GitUrl;\n defaultBranch?: string;\n prTitle: string;\n prBody: string;\n catalogInfoContent: string;\n },\n ): Promise<{\n prUrl?: string;\n prNumber?: number;\n hasChanges?: boolean;\n lastUpdate?: string;\n errors?: string[];\n }> {\n const fileName = getCatalogFilename(this.config);\n const errors: any[] = [];\n\n const result = await executeFunctionOnFirstSuccessfulIntegration(\n {\n logger: this.logger,\n cache: this.cache,\n config: this.config,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n repoUrl: input.repoUrl,\n fn: async (\n validatedRepo: ValidatedRepo,\n octo: Octokit,\n ): Promise<{\n successful: boolean;\n result?: {\n prUrl?: string;\n prNumber?: number;\n hasChanges?: boolean;\n lastUpdate?: string;\n };\n }> => {\n const { owner, repo, branchName } = validatedRepo;\n try {\n // Check if there is already a catalogInfo in the default branch\n const catalogInfoFileExists = await fileExistsInDefaultBranch(\n logger,\n octo,\n owner,\n repo,\n fileName,\n input.defaultBranch,\n );\n if (catalogInfoFileExists) {\n // No need to create a PR => component will be imported as is\n return {\n successful: true,\n result: {\n hasChanges: false,\n },\n };\n }\n\n const existingPrForBranch = await findOpenPRForBranch(\n logger,\n this.config,\n octo,\n owner,\n repo,\n branchName,\n );\n\n const repoData = await octo.rest.repos.get({\n owner,\n repo,\n });\n const parentRef = await octo.rest.git.getRef({\n owner,\n repo,\n ref: `heads/${repoData.data.default_branch}`,\n });\n if (existingPrForBranch.prNum) {\n await this.createOrUpdateFileInBranch(\n owner,\n repo,\n branchName,\n fileName,\n input.catalogInfoContent,\n );\n const pullRequestResponse = await octo.rest.pulls.update({\n owner,\n repo,\n pull_number: existingPrForBranch.prNum,\n title: input.prTitle,\n body: input.prBody,\n head: branchName,\n base: repoData.data.default_branch,\n });\n return {\n successful: true,\n result: {\n prNumber: existingPrForBranch.prNum,\n prUrl: pullRequestResponse.data.html_url,\n lastUpdate: pullRequestResponse.data.updated_at,\n },\n };\n }\n\n let branchExists = false;\n try {\n await octo.rest.git.getRef({\n owner,\n repo,\n ref: `heads/${branchName}`,\n });\n branchExists = true;\n } catch (error: any) {\n if (error.status === 404) {\n await octo.rest.git.createRef({\n owner,\n repo,\n ref: `refs/heads/${branchName}`,\n sha: parentRef.data.object.sha,\n });\n } else {\n throw error;\n }\n }\n\n if (branchExists) {\n // update it in case it is outdated compared to the base branch\n try {\n await octo.repos.merge({\n owner: owner,\n repo: repo,\n base: branchName,\n head: repoData.data.default_branch,\n });\n } catch (error: any) {\n logErrorIfNeeded(\n this.logger,\n `Could not merge default branch ${repoData.data.default_branch} into import branch ${branchName}`,\n error,\n );\n }\n }\n\n await this.createOrUpdateFileInBranch(\n owner,\n repo,\n branchName,\n fileName,\n input.catalogInfoContent,\n );\n\n const pullRequestResponse = await octo.rest.pulls.create({\n owner,\n repo,\n title: input.prTitle,\n body: input.prBody,\n head: branchName,\n base: repoData.data.default_branch,\n });\n return {\n successful: true,\n result: {\n prNumber: pullRequestResponse.data.number,\n prUrl: pullRequestResponse.data.html_url,\n lastUpdate: pullRequestResponse.data.updated_at,\n hasChanges: true,\n },\n };\n } catch (e: any) {\n logErrorIfNeeded(\n this.logger,\n `Couldn't create PR in ${input.repoUrl}`,\n e,\n );\n errors.push(e.message);\n return { successful: false };\n }\n },\n },\n );\n\n if (result) {\n return result;\n }\n\n logger.warn(\n `Tried all possible GitHub credentials, but could not create PR in ${input.repoUrl}. Please try again later...`,\n );\n\n return {\n errors: errors,\n };\n }\n\n async hasFileInRepo(input: {\n repoUrl: string;\n defaultBranch?: string;\n fileName: string;\n }) {\n const fileExists = await executeFunctionOnFirstSuccessfulIntegration(\n {\n logger: this.logger,\n cache: this.cache,\n config: this.config,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n repoUrl: input.repoUrl,\n fn: async (validatedRepo: ValidatedRepo, octo: Octokit) => {\n const { owner, repo } = validatedRepo;\n const exists = await fileExistsInDefaultBranch(\n this.logger,\n octo,\n owner,\n repo,\n input.fileName,\n input.defaultBranch,\n );\n if (exists === undefined) {\n return { successful: false };\n }\n return { successful: true, result: exists };\n },\n },\n );\n\n if (fileExists === undefined) {\n throw new Error(\n `Could not determine if repo at ${input.repoUrl} already has a file named ${input.fileName} in its default branch (${input.defaultBranch})`,\n );\n }\n\n return fileExists;\n }\n\n async closeImportPR(\n logger: LoggerService,\n input: {\n repoUrl: string;\n gitUrl: gitUrlParse.GitUrl;\n comment: string;\n },\n ) {\n await executeFunctionOnFirstSuccessfulIntegration(\n {\n logger: this.logger,\n cache: this.cache,\n config: this.config,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n repoUrl: input.repoUrl,\n fn: async (validatedRepo: ValidatedRepo, octo: Octokit) => {\n const { owner, repo, branchName } = validatedRepo;\n try {\n const existingPrForBranch = await findOpenPRForBranch(\n logger,\n this.config,\n octo,\n owner,\n repo,\n branchName,\n );\n if (existingPrForBranch.prNum) {\n await closePRWithComment(\n octo,\n owner,\n repo,\n existingPrForBranch.prNum,\n input.comment,\n );\n }\n return { successful: true };\n } catch (e: any) {\n logErrorIfNeeded(\n this.logger,\n `Couldn't close PR in ${input.repoUrl}`,\n e,\n );\n return { successful: false };\n }\n },\n },\n );\n }\n\n async deleteImportBranch(input: {\n repoUrl: string;\n gitUrl: gitUrlParse.GitUrl;\n }) {\n await executeFunctionOnFirstSuccessfulIntegration(\n {\n logger: this.logger,\n cache: this.cache,\n config: this.config,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n repoUrl: input.repoUrl,\n fn: async (validatedRepo: ValidatedRepo, octo: Octokit) => {\n const { owner, repo, branchName } = validatedRepo;\n try {\n await octo.git.deleteRef({\n owner: owner,\n repo: repo,\n ref: `heads/${branchName}`,\n });\n return { successful: true };\n } catch (e: any) {\n logErrorIfNeeded(\n this.logger,\n `Couldn't close import PR and/or delete import branch in ${input.repoUrl}`,\n e,\n );\n return { successful: false };\n }\n },\n },\n );\n }\n\n async isRepoEmpty(input: { repoUrl: string }) {\n return await executeFunctionOnFirstSuccessfulIntegration(\n {\n logger: this.logger,\n cache: this.cache,\n config: this.config,\n githubCredentialsProvider: this.githubCredentialsProvider,\n },\n this.integrations,\n {\n repoUrl: input.repoUrl,\n fn: async (validatedRepo: ValidatedRepo, octo: Octokit) => {\n const { owner, repo } = validatedRepo;\n const resp = await octo.rest.repos.listContributors({\n owner: owner,\n repo: repo,\n page: 1,\n per_page: 1,\n });\n const status = resp.status as 200 | 204;\n return { successful: true, result: status === 204 };\n },\n },\n );\n }\n}\n"],"names":["ScmIntegrations","CustomGithubCredentialsProvider","fetchFromMatchedIntegration","DefaultPageNumber","DefaultPageSize","fetchFromAllIntegrations","isGithubAppCredential","addGithubAppOrgs","addGithubTokenOrgs","computeTotalCount","addGithubAppRepositories","addGithubTokenOrgRepositories","addGithubTokenRepositories","extractLocationOwnerMap","getAllAppOrgs","logErrorIfNeeded","buildOcto","getBranchName","findOpenPRForBranch","getCatalogInfoContentFromPR","getCatalogFilename","executeFunctionOnFirstSuccessfulIntegration","fileExistsInDefaultBranch","pullRequestResponse","closePRWithComment"],"mappings":";;;;;;;;;;;;;;;;;;;AAyEO,MAAM,gBAAiB,CAAA;AAAA,EACX,MAAA;AAAA,EACA,YAAA;AAAA,EACD,yBAAA;AAAA,EACC,MAAA;AAAA;AAAA,EAEA,KAAA;AAAA,EAEjB,WAAA,CACE,MACA,EAAA,MAAA,EACA,YACA,EAAA;AACA,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA;AACd,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA;AACd,IAAK,IAAA,CAAA,YAAA,GAAeA,2BAAgB,CAAA,UAAA,CAAW,MAAM,C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B,IAAkB,KAAA;AACzD,UAAM,MAAA,EAAE,KAAO,EAAA,IAAA,EAAS,GAAA,aAAA;AACxB,UAAA,MAAM,IAAO,GAAA,MAAM,IAAK,CAAA,IAAA,CAAK,MAAM,gBAAiB,CAAA;AAAA,YAClD,KAAA;AAAA,YACA,IAAA;AAAA,YACA,IAAM,EAAA,CAAA;AAAA,YACN,QAAU,EAAA;AAAA,WACX,CAAA;AACD,UAAA,MAAM,SAAS,IAAK,CAAA,MAAA;AACpB,UAAA,OAAO,EAAE,UAAA,EAAY,IAAM,EAAA,MAAA,EAAQ,WAAW,GAAI,EAAA;AAAA;AACpD;AACF,KACF;AAAA;AAEJ;;;;"}
@@ -6,6 +6,7 @@ require('@red-hat-developer-hub/backstage-plugin-bulk-import-common');
6
6
  require('just-kebab-case');
7
7
  var loggingUtils = require('../../helpers/loggingUtils.cjs.js');
8
8
  var pagination = require('../../helpers/pagination.cjs.js');
9
+ require('@backstage/catalog-model');
9
10
  require('git-url-parse');
10
11
  var handlers = require('../../service/handlers/handlers.cjs.js');
11
12
  var utils = require('./utils.cjs.js');
@@ -1 +1 @@
1
- {"version":3,"file":"orgUtils.cjs.js","sources":["../../../src/github/utils/orgUtils.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { LoggerService } from '@backstage/backend-plugin-api';\nimport type {\n GithubCredentials,\n GithubIntegrationConfig,\n} from '@backstage/integration';\n\nimport { Octokit } from '@octokit/rest';\n\nimport { logErrorIfNeeded, paginateArray } from '../../helpers';\nimport {\n DefaultPageNumber,\n DefaultPageSize,\n} from '../../service/handlers/handlers';\nimport type { CustomGithubCredentialsProvider } from '../GithubAppManager';\nimport type { GithubFetchError, GithubOrganization } from '../types';\nimport { computeTotalCountFromGitHubToken, handleError } from './utils';\n\nexport async function getAllAppOrgs(\n githubCredentialsProvider: CustomGithubCredentialsProvider,\n ghConfig: GithubIntegrationConfig,\n credentialAccountLogin?: string,\n) {\n const result = new Map<string, GithubOrganization>();\n const resp = await githubCredentialsProvider.getAllAppInstallations(ghConfig);\n for (const installation of resp ?? []) {\n if (\n !(\n installation.account &&\n installation.target_type?.toLowerCase() === 'organization'\n )\n ) {\n continue;\n }\n const acc = installation.account!;\n if (credentialAccountLogin !== acc.login) {\n continue;\n }\n result.set(acc.url, {\n id: acc.id,\n description: acc.description ?? undefined,\n name: acc.login,\n url: acc.html_url,\n html_url: acc.html_url,\n repos_url: acc.repos_url,\n events_url: acc.events_url,\n });\n }\n return result;\n}\n\nexport async function addGithubAppOrgs(\n deps: {\n logger: LoggerService;\n githubCredentialsProvider: CustomGithubCredentialsProvider;\n },\n octokit: Octokit,\n ghConfig: GithubIntegrationConfig,\n params: {\n credentialAccountLogin: string | undefined;\n search: string | undefined;\n orgs: Map<string, GithubOrganization>;\n errors: Map<number, GithubFetchError>;\n },\n): Promise<{ totalCount?: number }> {\n const credentialAccountLogin = params.credentialAccountLogin;\n const search = params.search;\n const orgs = params.orgs;\n const errors = params.errors;\n let totalCount = 0;\n try {\n const resp = await getAllAppOrgs(\n deps.githubCredentialsProvider,\n ghConfig,\n credentialAccountLogin,\n );\n for (const [orgUrl, ghOrg] of resp) {\n if (search && !ghOrg.name.toLowerCase().includes(search.toLowerCase())) {\n continue;\n }\n const orgData = await octokit.request(\n orgUrl.replace('/users/', '/orgs/'),\n );\n orgs.set(ghOrg.name, {\n ...ghOrg,\n public_repos: orgData?.data?.public_repos,\n total_private_repos: orgData?.data?.total_private_repos,\n owned_private_repos: orgData?.data?.owned_private_repos,\n });\n totalCount++;\n }\n } catch (err: any) {\n logErrorIfNeeded(\n deps.logger,\n `Fetching organizations with access token for github app`,\n err,\n );\n errors.set(-1, err.message);\n }\n return { totalCount };\n}\n\nexport async function addGithubTokenOrgs(\n deps: {\n logger: LoggerService;\n },\n octokit: Octokit,\n credential: GithubCredentials,\n params: {\n search: string | undefined;\n orgs: Map<string, GithubOrganization>;\n errors: Map<number, GithubFetchError>;\n pageNumber: number;\n pageSize: number;\n },\n): Promise<{ totalCount?: number }> {\n const search = params.search;\n const orgs = params.orgs;\n const errors = params.errors;\n const pageNumber = params.pageNumber ?? DefaultPageNumber;\n const pageSize = params.pageSize ?? DefaultPageSize;\n\n let totalCount: number | undefined;\n try {\n let matchingOrgs;\n if (search) {\n // Initial idea was to leverage octokit.rest.search.users({q: `${search} type:org`}),\n // but this searches across all of GitHub, not only the orgs accessible by the current creds.\n // That's why we are searching in everything, hoping the list of organizations to not be that big in size\n const resp = await octokit.paginate(\n octokit.rest.orgs.listForAuthenticatedUser,\n {\n sort: 'full_name',\n direction: 'asc',\n },\n );\n const allMatchingOrgs =\n resp?.filter(org =>\n org.login.toLowerCase().includes(search.toLowerCase()),\n ) ?? [];\n const matchingOrgsPage = paginateArray(\n allMatchingOrgs,\n pageNumber,\n pageSize,\n );\n matchingOrgs = matchingOrgsPage.result;\n totalCount = matchingOrgsPage.totalCount;\n } else {\n /**\n * The listForAuthenticatedUser endpoint will grab all the repositories the github token has explicit access to.\n * These would include repositories they own, repositories where they are a collaborator,\n * and repositories that they can access through an organization membership.\n */\n const resp = await octokit.rest.orgs.listForAuthenticatedUser({\n page: pageNumber,\n per_page: pageSize,\n sort: 'full_name',\n direction: 'asc',\n });\n matchingOrgs = resp?.data ?? [];\n\n totalCount = await computeTotalCountFromGitHubToken(\n deps,\n async (lastPageNumber: number) =>\n octokit.orgs\n .listForAuthenticatedUser({\n page: lastPageNumber,\n per_page: 100,\n })\n .then(lastPageResp => lastPageResp.data.length),\n 'orgs.listForAuthenticatedUser',\n resp?.data?.length,\n resp?.headers?.link,\n );\n }\n\n for (const org of matchingOrgs) {\n const orgData = await octokit.request(org.url);\n const ghOrg: GithubOrganization = {\n id: org.id,\n name: org.login,\n description: org.description ?? undefined,\n url: orgData?.data?.html_url ?? org.url,\n repos_url: org.repos_url,\n hooks_url: org.hooks_url,\n issues_url: org.issues_url,\n members_url: org.members_url,\n public_members_url: org.public_members_url,\n avatar_url: org.avatar_url,\n public_repos: orgData?.data?.public_repos,\n total_private_repos: orgData?.data?.total_private_repos,\n owned_private_repos: orgData?.data?.owned_private_repos,\n };\n orgs.set(org.login, ghOrg);\n }\n } catch (err) {\n handleError(\n { logger: deps.logger },\n 'Fetching orgs with token from token',\n credential,\n errors,\n err,\n );\n }\n return { totalCount };\n}\n"],"names":["logErrorIfNeeded","DefaultPageNumber","DefaultPageSize","paginateArray","computeTotalCountFromGitHubToken","handleError"],"mappings":";;;;;;;;;;;;AAiCsB,eAAA,aAAA,CACpB,yBACA,EAAA,QAAA,EACA,sBACA,EAAA;AACA,EAAM,MAAA,MAAA,uBAAa,GAAgC,EAAA;AACnD,EAAA,MAAM,IAAO,GAAA,MAAM,yBAA0B,CAAA,sBAAA,CAAuB,QAAQ,CAAA;AAC5E,EAAW,KAAA,MAAA,YAAA,IAAgB,IAAQ,IAAA,EAAI,EAAA;AACrC,IAAA,IACE,EACE,YAAa,CAAA,OAAA,IACb,aAAa,WAAa,EAAA,WAAA,OAAkB,cAE9C,CAAA,EAAA;AACA,MAAA;AAAA;AAEF,IAAA,MAAM,MAAM,YAAa,CAAA,OAAA;AACzB,IAAI,IAAA,sBAAA,KAA2B,IAAI,KAAO,EAAA;AACxC,MAAA;AAAA;AAEF,IAAO,MAAA,CAAA,GAAA,CAAI,IAAI,GAAK,EAAA;AAAA,MAClB,IAAI,GAAI,CAAA,EAAA;AAAA,MACR,WAAA,EAAa,IAAI,WAAe,IAAA,SAAA;AAAA,MAChC,MAAM,GAAI,CAAA,KAAA;AAAA,MACV,KAAK,GAAI,CAAA,QAAA;AAAA,MACT,UAAU,G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,IAAA,CAAA,GAAA,CAAI,GAAI,CAAA,KAAA,EAAO,KAAK,CAAA;AAAA;AAC3B,WACO,GAAK,EAAA;AACZ,IAAAC,iBAAA;AAAA,MACE,EAAE,MAAQ,EAAA,IAAA,CAAK,MAAO,EAAA;AAAA,MACtB,qCAAA;AAAA,MACA,UAAA;AAAA,MACA,MAAA;AAAA,MACA;AAAA,KACF;AAAA;AAEF,EAAA,OAAO,EAAE,UAAW,EAAA;AACtB;;;;;;"}
1
+ {"version":3,"file":"orgUtils.cjs.js","sources":["../../../src/github/utils/orgUtils.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { LoggerService } from '@backstage/backend-plugin-api';\nimport type {\n GithubCredentials,\n GithubIntegrationConfig,\n} from '@backstage/integration';\n\nimport { Octokit } from '@octokit/rest';\n\nimport { logErrorIfNeeded, paginateArray } from '../../helpers';\nimport {\n DefaultPageNumber,\n DefaultPageSize,\n} from '../../service/handlers/handlers';\nimport type { CustomGithubCredentialsProvider } from '../GithubAppManager';\nimport type { GithubFetchError, GithubOrganization } from '../types';\nimport { computeTotalCountFromGitHubToken, handleError } from './utils';\n\nexport async function getAllAppOrgs(\n githubCredentialsProvider: CustomGithubCredentialsProvider,\n ghConfig: GithubIntegrationConfig,\n credentialAccountLogin?: string,\n) {\n const result = new Map<string, GithubOrganization>();\n const resp = await githubCredentialsProvider.getAllAppInstallations(ghConfig);\n for (const installation of resp ?? []) {\n if (\n !(\n installation.account &&\n installation.target_type?.toLowerCase() === 'organization'\n )\n ) {\n continue;\n }\n const acc = installation.account!;\n if (credentialAccountLogin !== acc.login) {\n continue;\n }\n result.set(acc.url, {\n id: acc.id,\n description: acc.description ?? undefined,\n name: acc.login,\n url: acc.html_url,\n html_url: acc.html_url,\n repos_url: acc.repos_url,\n events_url: acc.events_url,\n });\n }\n return result;\n}\n\nexport async function addGithubAppOrgs(\n deps: {\n logger: LoggerService;\n githubCredentialsProvider: CustomGithubCredentialsProvider;\n },\n octokit: Octokit,\n ghConfig: GithubIntegrationConfig,\n params: {\n credentialAccountLogin: string | undefined;\n search: string | undefined;\n orgs: Map<string, GithubOrganization>;\n errors: Map<number, GithubFetchError>;\n },\n): Promise<{ totalCount?: number }> {\n const credentialAccountLogin = params.credentialAccountLogin;\n const search = params.search;\n const orgs = params.orgs;\n const errors = params.errors;\n let totalCount = 0;\n try {\n const resp = await getAllAppOrgs(\n deps.githubCredentialsProvider,\n ghConfig,\n credentialAccountLogin,\n );\n for (const [orgUrl, ghOrg] of resp) {\n if (search && !ghOrg.name.toLowerCase().includes(search.toLowerCase())) {\n continue;\n }\n const orgData = await octokit.request(\n orgUrl.replace('/users/', '/orgs/'),\n );\n orgs.set(ghOrg.name, {\n ...ghOrg,\n public_repos: orgData?.data?.public_repos,\n total_private_repos: orgData?.data?.total_private_repos,\n owned_private_repos: orgData?.data?.owned_private_repos,\n });\n totalCount++;\n }\n } catch (err: any) {\n logErrorIfNeeded(\n deps.logger,\n `Fetching organizations with access token for github app`,\n err,\n );\n errors.set(-1, err.message);\n }\n return { totalCount };\n}\n\nexport async function addGithubTokenOrgs(\n deps: {\n logger: LoggerService;\n },\n octokit: Octokit,\n credential: GithubCredentials,\n params: {\n search: string | undefined;\n orgs: Map<string, GithubOrganization>;\n errors: Map<number, GithubFetchError>;\n pageNumber: number;\n pageSize: number;\n },\n): Promise<{ totalCount?: number }> {\n const search = params.search;\n const orgs = params.orgs;\n const errors = params.errors;\n const pageNumber = params.pageNumber ?? DefaultPageNumber;\n const pageSize = params.pageSize ?? DefaultPageSize;\n\n let totalCount: number | undefined;\n try {\n let matchingOrgs;\n if (search) {\n // Initial idea was to leverage octokit.rest.search.users({q: `${search} type:org`}),\n // but this searches across all of GitHub, not only the orgs accessible by the current creds.\n // That's why we are searching in everything, hoping the list of organizations to not be that big in size\n const resp = await octokit.paginate(\n octokit.rest.orgs.listForAuthenticatedUser,\n {\n sort: 'full_name',\n direction: 'asc',\n },\n );\n const allMatchingOrgs =\n resp?.filter(org =>\n org.login.toLowerCase().includes(search.toLowerCase()),\n ) ?? [];\n const matchingOrgsPage = paginateArray(\n allMatchingOrgs,\n pageNumber,\n pageSize,\n );\n matchingOrgs = matchingOrgsPage.result;\n totalCount = matchingOrgsPage.totalCount;\n } else {\n /**\n * The listForAuthenticatedUser endpoint will grab all the repositories the github token has explicit access to.\n * These would include repositories they own, repositories where they are a collaborator,\n * and repositories that they can access through an organization membership.\n */\n const resp = await octokit.rest.orgs.listForAuthenticatedUser({\n page: pageNumber,\n per_page: pageSize,\n sort: 'full_name',\n direction: 'asc',\n });\n matchingOrgs = resp?.data ?? [];\n\n totalCount = await computeTotalCountFromGitHubToken(\n deps,\n async (lastPageNumber: number) =>\n octokit.orgs\n .listForAuthenticatedUser({\n page: lastPageNumber,\n per_page: 100,\n })\n .then(lastPageResp => lastPageResp.data.length),\n 'orgs.listForAuthenticatedUser',\n resp?.data?.length,\n resp?.headers?.link,\n );\n }\n\n for (const org of matchingOrgs) {\n const orgData = await octokit.request(org.url);\n const ghOrg: GithubOrganization = {\n id: org.id,\n name: org.login,\n description: org.description ?? undefined,\n url: orgData?.data?.html_url ?? org.url,\n repos_url: org.repos_url,\n hooks_url: org.hooks_url,\n issues_url: org.issues_url,\n members_url: org.members_url,\n public_members_url: org.public_members_url,\n avatar_url: org.avatar_url,\n public_repos: orgData?.data?.public_repos,\n total_private_repos: orgData?.data?.total_private_repos,\n owned_private_repos: orgData?.data?.owned_private_repos,\n };\n orgs.set(org.login, ghOrg);\n }\n } catch (err) {\n handleError(\n { logger: deps.logger },\n 'Fetching orgs with token from token',\n credential,\n errors,\n err,\n );\n }\n return { totalCount };\n}\n"],"names":["logErrorIfNeeded","DefaultPageNumber","DefaultPageSize","paginateArray","computeTotalCountFromGitHubToken","handleError"],"mappings":";;;;;;;;;;;;;AAiCsB,eAAA,aAAA,CACpB,yBACA,EAAA,QAAA,EACA,sBACA,EAAA;AACA,EAAM,MAAA,MAAA,uBAAa,GAAgC,EAAA;AACnD,EAAA,MAAM,IAAO,GAAA,MAAM,yBAA0B,CAAA,sBAAA,CAAuB,QAAQ,CAAA;AAC5E,EAAW,KAAA,MAAA,YAAA,IAAgB,IAAQ,IAAA,EAAI,EAAA;AACrC,IAAA,IACE,EACE,YAAa,CAAA,OAAA,IACb,aAAa,WAAa,EAAA,WAAA,OAAkB,cAE9C,CAAA,EAAA;AACA,MAAA;AAAA;AAEF,IAAA,MAAM,MAAM,YAAa,CAAA,OAAA;AACzB,IAAI,IAAA,sBAAA,KAA2B,IAAI,KAAO,EAAA;AACxC,MAAA;AAAA;AAEF,IAAO,MAAA,CAAA,GAAA,CAAI,IAAI,GAAK,EAAA;AAAA,MAClB,IAAI,GAAI,CAAA,EAAA;AAAA,MACR,WAAA,EAAa,IAAI,WAAe,IAAA,SAAA;AAAA,MAChC,MAAM,GAAI,CAAA,KAAA;AAAA,MACV,KAAK,GAAI,CAAA,QAAA;AAAA,MACT,UAAU,GAAI,CAAA,QAAA;AAAA,MACd,WAAW,GAAI,CAAA,SAAA;AAAA,MACf,YAAY,GAAI,CAAA;AAAA,KACjB,CAAA;AAAA;AAEH,EAAO,OAAA,MAAA;AACT;AAEA,eAAsB,gBACpB,CAAA,IAAA,EAIA,OACA,EAAA,QAAA,EACA,MAMkC,EAAA;AAClC,EAAA,MAAM,yBAAyB,MAAO,CAAA,sBAAA;AACtC,EAAA,MAAM,SAAS,MAAO,CAAA,MAAA;AACtB,EAAA,MAAM,OAAO,MAAO,CAAA,IAAA;AACpB,EAAA,MAAM,SAAS,MAAO,CAAA,MAAA;AACtB,EAAA,I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