@red-hat-developer-hub/backstage-plugin-bulk-import-backend 6.2.0 → 6.4.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 +26 -0
- package/README.md +28 -0
- package/config.d.ts +9 -1
- package/dist/catalog/catalogHttpClient.cjs.js +3 -0
- package/dist/catalog/catalogHttpClient.cjs.js.map +1 -1
- package/dist/catalog/catalogInfoGenerator.cjs.js +1 -0
- package/dist/catalog/catalogInfoGenerator.cjs.js.map +1 -1
- package/dist/database/migration.cjs.js +20 -0
- package/dist/database/migration.cjs.js.map +1 -0
- package/dist/database/repositoryDao.cjs.js +117 -0
- package/dist/database/repositoryDao.cjs.js.map +1 -0
- package/dist/generated/openapidocument.cjs.js +366 -38
- package/dist/generated/openapidocument.cjs.js.map +1 -1
- package/dist/github/githubApiService.cjs.js +222 -95
- package/dist/github/githubApiService.cjs.js.map +1 -1
- package/dist/github/utils/orgUtils.cjs.js +2 -0
- package/dist/github/utils/orgUtils.cjs.js.map +1 -1
- package/dist/github/utils/prUtils.cjs.js +3 -0
- package/dist/github/utils/prUtils.cjs.js.map +1 -1
- package/dist/github/utils/repoUtils.cjs.js +1 -38
- package/dist/github/utils/repoUtils.cjs.js.map +1 -1
- package/dist/github/utils/utils.cjs.js +29 -18
- package/dist/github/utils/utils.cjs.js.map +1 -1
- package/dist/gitlab/GitlabAppManager.cjs.js +54 -0
- package/dist/gitlab/GitlabAppManager.cjs.js.map +1 -0
- package/dist/gitlab/gitlabApiService.cjs.js +660 -0
- package/dist/gitlab/gitlabApiService.cjs.js.map +1 -0
- package/dist/gitlab/utils/glUtils.cjs.js +15 -0
- package/dist/gitlab/utils/glUtils.cjs.js.map +1 -0
- package/dist/gitlab/utils/orgUtils.cjs.js +72 -0
- package/dist/gitlab/utils/orgUtils.cjs.js.map +1 -0
- package/dist/gitlab/utils/prUtils.cjs.js +73 -0
- package/dist/gitlab/utils/prUtils.cjs.js.map +1 -0
- package/dist/gitlab/utils/repoUtils.cjs.js +200 -0
- package/dist/gitlab/utils/repoUtils.cjs.js.map +1 -0
- package/dist/gitlab/utils/utils.cjs.js +131 -0
- package/dist/gitlab/utils/utils.cjs.js.map +1 -0
- package/dist/helpers/utils.cjs.js +58 -0
- package/dist/helpers/utils.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/plugin.cjs.js +6 -3
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/service/handlers/import/bulkImports.cjs.js +216 -34
- package/dist/service/handlers/import/bulkImports.cjs.js.map +1 -1
- package/dist/service/handlers/import/execute-template.cjs.js +264 -0
- package/dist/service/handlers/import/execute-template.cjs.js.map +1 -0
- package/dist/service/handlers/import/importStatus.cjs.js +5 -8
- package/dist/service/handlers/import/importStatus.cjs.js.map +1 -1
- package/dist/service/handlers/organization/organizations.cjs.js +2 -2
- package/dist/service/handlers/organization/organizations.cjs.js.map +1 -1
- package/dist/service/handlers/repository/repositories.cjs.js +5 -2
- package/dist/service/handlers/repository/repositories.cjs.js.map +1 -1
- package/dist/service/router.cjs.js +199 -34
- package/dist/service/router.cjs.js.map +1 -1
- package/migrations/20250808122501_migrations.js +53 -0
- package/package.json +17 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gitlabApiService.cjs.js","sources":["../../src/gitlab/gitlabApiService.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 GitLabIntegrationConfig,\n ScmIntegrations,\n} from '@backstage/integration';\n\nimport { Gitlab } from '@gitbeaker/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 { CustomGitlabCredentialsProvider } from './GitlabAppManager';\nimport {\n ExtendedGitlabCredentials,\n GitlabFetchError,\n GitlabOrganization,\n GitlabOrganizationResponse,\n GitlabRepository,\n GitlabRepositoryResponse,\n} from './types';\nimport { buildGitlab } from './utils/glUtils';\nimport { addGitlabTokenGroups } from './utils/orgUtils';\nimport { closePRWithComment, findOpenPRForBranch } from './utils/prUtils';\nimport {\n addGitlabTokenOrgRepositories,\n addGitlabTokenRepositories,\n createOrUpdateFileInBranch,\n fileExistsInDefaultBranch,\n ValidatedRepo,\n} from './utils/repoUtils';\nimport {\n executeFunctionOnFirstSuccessfulIntegration,\n fetchFromAllIntegrations,\n getCredentialsForConfig,\n} from './utils/utils';\n\nexport class GitlabApiService {\n private readonly logger: LoggerService;\n private readonly integrations: ScmIntegrations;\n private readonly gitlabCredentialsProvider: CustomGitlabCredentialsProvider;\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 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.gitlabCredentialsProvider =\n CustomGitlabCredentialsProvider.fromIntegrations(this.integrations);\n this.cache = cacheService;\n }\n\n async getRepositoryFromIntegrations(repoUrl: string): Promise<{\n repository?: GitlabRepository;\n errors?: GitlabFetchError[];\n }> {\n const gitUrl = gitUrlParse(repoUrl);\n\n const glConfig = this.integrations.gitlab.byUrl(repoUrl)?.config;\n if (!glConfig) {\n throw new Error(\n `No Gitlab integration config found for repo ${repoUrl}. Please add a configuration entry under 'integrations.gitlab`,\n );\n }\n\n const credentials = await getCredentialsForConfig(\n this.gitlabCredentialsProvider,\n glConfig,\n );\n let repository: GitlabRepository | undefined = undefined;\n for (const credential of credentials) {\n const glKit = buildGitlab(\n {\n logger: this.logger,\n cache: this.cache,\n },\n { credential, owner: gitUrl.owner },\n glConfig.baseUrl,\n );\n const repo = await glKit.Projects.show(`${gitUrl.owner}/${gitUrl.name}`);\n if (!repo) {\n continue;\n }\n repository = {\n name: repo.name,\n full_name: repo.path_with_namespace,\n url: repo._links.self,\n html_url: repo.web_url,\n default_branch: repo.default_branch,\n updated_at: repo.updated_at,\n };\n break;\n }\n\n return {\n repository,\n errors: [],\n };\n }\n\n async getOrganizationsFromIntegrations(\n search?: string,\n pageNumber: number = DefaultPageNumber,\n pageSize: number = DefaultPageSize,\n ): Promise<GitlabOrganizationResponse> {\n const groups = new Map<string, GitlabOrganization>();\n const result = await fetchFromAllIntegrations(\n {\n logger: this.logger,\n cache: this.cache,\n gitlabCredentialsProvider: this.gitlabCredentialsProvider,\n },\n this.integrations,\n {\n dataFetcher: async (\n glApi: InstanceType<typeof Gitlab<false>>,\n credential: ExtendedGitlabCredentials,\n glConfig: GitLabIntegrationConfig,\n ) => {\n const dataFetchErrors = new Map<number, GitlabFetchError>();\n const resp = await addGitlabTokenGroups(\n {\n logger: this.logger,\n },\n glApi,\n credential,\n {\n search,\n groups,\n pageNumber,\n pageSize,\n errors: dataFetchErrors,\n },\n );\n this.logger.debug(\n `Got ${resp.totalCount} groups(s) for ${glConfig.host}`,\n );\n return {\n result: resp.totalCount ?? 0,\n errors: Array.from(dataFetchErrors.values()),\n };\n },\n },\n );\n\n const groupList = Array.from(groups.values());\n const totalCount = computeTotalCount(groupList, result.data, pageSize);\n return {\n organizations: groupList,\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<GitlabRepositoryResponse> {\n const orgRepositories = new Map<string, GitlabRepository>();\n const result = await fetchFromAllIntegrations(\n {\n logger: this.logger,\n cache: this.cache,\n gitlabCredentialsProvider: this.gitlabCredentialsProvider,\n },\n this.integrations,\n {\n dataFetcher: async (\n glApi: InstanceType<typeof Gitlab<false>>,\n credential: ExtendedGitlabCredentials,\n glConfig: GitLabIntegrationConfig,\n ) => {\n const dataFetchErrors = new Map<number, GitlabFetchError>();\n const resp = await addGitlabTokenOrgRepositories(\n {\n logger: this.logger,\n },\n glApi,\n credential,\n orgName,\n orgRepositories,\n dataFetchErrors,\n {\n search,\n pageNumber,\n pageSize,\n },\n );\n this.logger.debug(\n `Got ${resp.totalCount} org repo(s) for ${glConfig.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(orgRepositories.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 GitlabRepositoryResponse containing:\n * - a list of unique repositories the gitlab integrations have access to\n * - a list of errors encountered by each token (if any exist)\n */\n async getRepositoriesFromIntegrations(\n search?: string,\n pageNumber: number = DefaultPageNumber,\n pageSize: number = DefaultPageSize,\n ): Promise<GitlabRepositoryResponse> {\n const repositories = new Map<string, GitlabRepository>();\n const result = await fetchFromAllIntegrations(\n {\n logger: this.logger,\n cache: this.cache,\n gitlabCredentialsProvider: this.gitlabCredentialsProvider,\n },\n this.integrations,\n {\n dataFetcher: async (\n glApi: InstanceType<typeof Gitlab<false>>,\n credential: ExtendedGitlabCredentials,\n glConfig: GitLabIntegrationConfig,\n ) => {\n const dataFetchErrors = new Map<number, GitlabFetchError>();\n const resp = await addGitlabTokenRepositories(\n {\n logger: this.logger,\n },\n glApi,\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 ${glConfig.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 allAccessibleTokenOrgs = new Set<string>();\n const allAccessibleUsernames = new Set<string>();\n await fetchFromAllIntegrations(\n {\n logger: this.logger,\n cache: this.cache,\n gitlabCredentialsProvider: this.gitlabCredentialsProvider,\n },\n this.integrations,\n {\n dataFetcher: async (gitlab: InstanceType<typeof Gitlab<false>>) => {\n // find authenticated gitlab owner...\n const username = (await gitlab.Users.showCurrentUser()).username;\n if (username) {\n allAccessibleUsernames.add(username);\n }\n // ... along with orgs accessible from the token auth\n\n const allGroups = await gitlab.Groups.all<false, 'offset'>({\n allAvailable: false,\n });\n allGroups\n .map(org => org.path)\n ?.forEach((orgName: string) => allAccessibleTokenOrgs.add(orgName));\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 allAccessibleTokenOrgs.has(owner) || 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 glConfig = this.integrations.gitlab.byUrl(input.repoUrl)?.config;\n if (!glConfig) {\n throw new Error(`Could not find GL 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.gitlabCredentialsProvider.getAllCredentials({\n host: glConfig.host,\n });\n if (credentials.length === 0) {\n throw new Error(`No credentials for GL integration`);\n }\n\n const branchName = getBranchName(this.config);\n for (const credential of credentials) {\n const glKit = buildGitlab(\n {\n logger: this.logger,\n cache: this.cache,\n },\n { credential, owner },\n glConfig.baseUrl,\n );\n try {\n return await findOpenPRForBranch(\n logger,\n this.config,\n glKit,\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 gitlabCredentialsProvider: this.gitlabCredentialsProvider,\n },\n this.integrations,\n {\n repoUrl: input.repoUrl,\n fn: async (\n validatedRepo: ValidatedRepo,\n gitlab: InstanceType<typeof Gitlab<false>>,\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 gitlab,\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 gitlab,\n owner,\n repo,\n branchName,\n );\n\n const repoData = await gitlab.Projects.show(`${owner}/${repo}`);\n\n const parentRef = await gitlab.Branches.show(\n `${owner}/${repo}`,\n repoData.default_branch,\n ); // This might not be neccesarry\n\n if (existingPrForBranch.prNum) {\n await createOrUpdateFileInBranch(\n gitlab,\n owner,\n repo,\n branchName,\n fileName,\n input.catalogInfoContent,\n );\n const pullRequestResponse = await gitlab.MergeRequests.edit(\n `${owner}/${repo}`,\n existingPrForBranch.prNum,\n {\n description: input.prBody,\n title: input.prTitle,\n targetBranch: repoData.default_branch,\n },\n );\n return {\n successful: true,\n result: {\n prNumber: existingPrForBranch.prNum,\n prUrl: pullRequestResponse.web_url,\n lastUpdate: pullRequestResponse.updated_at,\n },\n };\n }\n\n try {\n await gitlab.Branches.show(`${owner}/${repo}`, branchName);\n } catch (error: any) {\n if (error.cause.response.status === 404) {\n await gitlab.Branches.create(\n `${owner}/${repo}`,\n branchName,\n parentRef.name,\n );\n } else {\n throw error;\n }\n }\n\n // Might not be able to do this in the gitlab api\n // This is if the branch exists, but there wasn't a PR yet\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 gitlab,\n owner,\n repo,\n branchName,\n fileName,\n input.catalogInfoContent,\n );\n\n const pullRequestResponse = await gitlab.MergeRequests.create(\n `${owner}/${repo}`,\n branchName,\n repoData.default_branch,\n input.prTitle,\n {\n description: input.prBody,\n },\n );\n return {\n successful: true,\n result: {\n prNumber: pullRequestResponse.iid,\n prUrl: pullRequestResponse.web_url,\n lastUpdate: pullRequestResponse.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 Gitlab 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 gitlabCredentialsProvider: this.gitlabCredentialsProvider,\n },\n this.integrations,\n {\n repoUrl: input.repoUrl,\n fn: async (\n validatedRepo: ValidatedRepo,\n gitlab: InstanceType<typeof Gitlab<false>>,\n ) => {\n const { owner, repo } = validatedRepo;\n const exists = await fileExistsInDefaultBranch(\n this.logger,\n gitlab,\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 gitlabCredentialsProvider: this.gitlabCredentialsProvider,\n },\n this.integrations,\n {\n repoUrl: input.repoUrl,\n fn: async (\n validatedRepo: ValidatedRepo,\n gitlab: InstanceType<typeof Gitlab<false>>,\n ) => {\n const { owner, repo, branchName } = validatedRepo;\n try {\n const existingPrForBranch = await findOpenPRForBranch(\n logger,\n this.config,\n gitlab,\n owner,\n repo,\n branchName,\n );\n if (existingPrForBranch.prNum) {\n await closePRWithComment(\n gitlab,\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 gitlabCredentialsProvider: this.gitlabCredentialsProvider,\n },\n this.integrations,\n {\n repoUrl: input.repoUrl,\n fn: async (\n validatedRepo: ValidatedRepo,\n gitlab: InstanceType<typeof Gitlab<false>>,\n ) => {\n const { owner, repo, branchName } = validatedRepo;\n try {\n await gitlab.Branches.remove(`${owner}/${repo}`, branchName);\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 gitlabCredentialsProvider: this.gitlabCredentialsProvider,\n },\n this.integrations,\n {\n repoUrl: input.repoUrl,\n fn: async (\n validatedRepo: ValidatedRepo,\n gitlab: InstanceType<typeof Gitlab<false>>,\n ) => {\n const { owner, repo } = validatedRepo;\n const resp = await gitlab.Repositories.allContributors(\n `${owner}/${repo}`,\n {\n showExpanded: true,\n },\n );\n return { successful: true, result: resp?.data?.length < 1 };\n },\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 glConfig = this.integrations.gitlab.byUrl(repoUrl)?.config;\n if (!glConfig) {\n this.logger.error(\n `No Gitlab integration config found for repo ${repoUrl}`,\n );\n return {};\n }\n\n const gitUrl = gitUrlParse(repoUrl);\n const owner = gitUrl.owner;\n const repo = gitUrl.name;\n\n const credentials = await this.gitlabCredentialsProvider.getAllCredentials({\n host: glConfig.host,\n });\n\n if (credentials.length === 0) {\n this.logger.error(`No credentials for GL integration`);\n return {};\n }\n\n for (const credential of credentials) {\n const glKit = buildGitlab(\n {\n logger: this.logger,\n cache: this.cache,\n },\n { credential, owner },\n glConfig.baseUrl,\n );\n\n try {\n const pr = await glKit.MergeRequests.show(\n `${owner}/${repo}`,\n pullRequestNumber,\n );\n\n return {\n title: pr.title,\n body: pr.description || undefined,\n merged: pr.state === 'merged',\n lastUpdated: pr.updated_at,\n prSha: pr.sha,\n prBranch: pr.source_branch,\n };\n } catch (error: any) {\n this.logger.error(\n `Error fetching pull request ${pullRequestNumber} from ${repoUrl}`,\n error,\n );\n }\n }\n\n return {};\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 glConfig = this.integrations.gitlab.byUrl(input.repoUrl)?.config;\n if (!glConfig) {\n logger.error(\n `No Gitlab integration config found for repo ${input.repoUrl}`,\n );\n return undefined;\n }\n\n const gitUrl = gitUrlParse(input.repoUrl);\n const owner = gitUrl.owner;\n const repo = gitUrl.name;\n\n const credentials = await this.gitlabCredentialsProvider.getAllCredentials({\n host: glConfig.host,\n });\n\n if (credentials.length === 0) {\n logger.error(`No credentials for GL integration`);\n return undefined;\n }\n\n for (const credential of credentials) {\n const glKit = buildGitlab(\n {\n logger: this.logger,\n cache: this.cache,\n },\n { credential, owner },\n glConfig.baseUrl,\n );\n\n try {\n const file = await glKit.RepositoryFiles.show(\n `${owner}/${repo}`,\n getCatalogFilename(this.config),\n input.prHeadSha,\n );\n\n if (file) {\n const content = Buffer.from(file.content, 'base64').toString('utf-8');\n return content;\n }\n } catch (error: any) {\n if (error.cause?.response?.status === 404) {\n logger.warn(\n `catalog-info.yaml not found in PR ${input.prNumber} of ${input.repoUrl}`,\n );\n return undefined;\n }\n logger.error(\n `Error fetching catalog-info.yaml from PR ${input.prNumber} of ${input.repoUrl}`,\n error,\n );\n return undefined;\n }\n }\n\n return undefined;\n }\n}\n"],"names":["ScmIntegrations","CustomGitlabCredentialsProvider","gitUrlParse","getCredentialsForConfig","buildGitlab","DefaultPageNumber","DefaultPageSize","fetchFromAllIntegrations","addGitlabTokenGroups","computeTotalCount","addGitlabTokenOrgRepositories","addGitlabTokenRepositories","extractLocationOwnerMap","getBranchName","findOpenPRForBranch","logErrorIfNeeded","getCatalogFilename","executeFunctionOnFirstSuccessfulIntegration","fileExistsInDefaultBranch","createOrUpdateFileInBranch","pullRequestResponse","closePRWithComment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgEO,MAAM,gBAAiB,CAAA;AAAA,EACX,MAAA;AAAA,EACA,YAAA;AAAA,EACA,yBAAA;AAAA,EACA,MAAA;AAAA;AAAA,EAEA,KAAA;AAAA,EACjB,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,EAAA;AACb,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,+CAA+C,OAAO,CAAA,6DAAA;AAAA,OACxD;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B_BASEURL_ENDPOINT) {
|
|
7
|
+
const apiThing = new rest.Gitlab({
|
|
8
|
+
host: baseUrl,
|
|
9
|
+
token: input.credential.token
|
|
10
|
+
});
|
|
11
|
+
return apiThing;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.buildGitlab = buildGitlab;
|
|
15
|
+
//# sourceMappingURL=glUtils.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glUtils.cjs.js","sources":["../../../src/gitlab/utils/glUtils.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';\n\nimport { Gitlab } from '@gitbeaker/rest';\n\nimport {\n type ExtendedGitlabCredentials,\n type GitlabFetchError,\n} from '../types';\n\nconst GITLAB_BASEURL_ENDPOINT = 'https://gitlab.com';\n\nexport function buildGitlab(\n _deps: {\n logger: LoggerService;\n cache: CacheService;\n },\n input: {\n credential: ExtendedGitlabCredentials;\n owner?: string;\n errors?: Map<number, GitlabFetchError>;\n },\n baseUrl: string = GITLAB_BASEURL_ENDPOINT,\n): InstanceType<typeof Gitlab<false>> {\n const apiThing = new Gitlab({\n host: baseUrl,\n token: input.credential.token,\n });\n return apiThing;\n}\n"],"names":["Gitlab"],"mappings":";;;;AA4BA,MAAM,uBAA0B,GAAA,oBAAA;AAEzB,SAAS,WACd,CAAA,KAAA,EAIA,KAKA,EAAA,OAAA,GAAkB,uBACkB,EAAA;AACpC,EAAM,MAAA,QAAA,GAAW,IAAIA,WAAO,CAAA;AAAA,IAC1B,IAAM,EAAA,OAAA;AAAA,IACN,KAAA,EAAO,MAAM,UAAW,CAAA;AAAA,GACzB,CAAA;AACD,EAAO,OAAA,QAAA;AACT;;;;"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var handlers = require('../../service/handlers/handlers.cjs.js');
|
|
4
|
+
var utils = require('./utils.cjs.js');
|
|
5
|
+
|
|
6
|
+
async function addGitlabTokenGroups(deps, gitlab, credential, params) {
|
|
7
|
+
const search = params.search;
|
|
8
|
+
const groups = params.groups;
|
|
9
|
+
const errors = params.errors;
|
|
10
|
+
const pageNumber = params.pageNumber ?? handlers.DefaultPageNumber;
|
|
11
|
+
const pageSize = params.pageSize ?? handlers.DefaultPageSize;
|
|
12
|
+
let totalCount;
|
|
13
|
+
try {
|
|
14
|
+
let matchingGroups;
|
|
15
|
+
if (search) {
|
|
16
|
+
const { data, paginationInfo } = await gitlab.Groups.all({
|
|
17
|
+
allAvailable: false,
|
|
18
|
+
search,
|
|
19
|
+
perPage: pageSize,
|
|
20
|
+
page: pageNumber,
|
|
21
|
+
showExpanded: true
|
|
22
|
+
});
|
|
23
|
+
matchingGroups = data ?? [];
|
|
24
|
+
totalCount = await utils.computeTotalCountFromPaginationInfo(
|
|
25
|
+
deps,
|
|
26
|
+
paginationInfo,
|
|
27
|
+
pageSize
|
|
28
|
+
// Not thrilled with this for some reason
|
|
29
|
+
);
|
|
30
|
+
} else {
|
|
31
|
+
const { data, paginationInfo } = await gitlab.Groups.all({
|
|
32
|
+
allAvailable: false,
|
|
33
|
+
perPage: pageSize,
|
|
34
|
+
page: pageNumber,
|
|
35
|
+
showExpanded: true
|
|
36
|
+
});
|
|
37
|
+
matchingGroups = data ?? [];
|
|
38
|
+
totalCount = await utils.computeTotalCountFromPaginationInfo(
|
|
39
|
+
deps,
|
|
40
|
+
paginationInfo,
|
|
41
|
+
pageSize
|
|
42
|
+
// Not thrilled with this for some reason
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
for (const group of matchingGroups) {
|
|
46
|
+
const glGroup = {
|
|
47
|
+
id: group.id,
|
|
48
|
+
name: group.path,
|
|
49
|
+
description: group.description ?? void 0,
|
|
50
|
+
url: group.web_url,
|
|
51
|
+
avatar_url: group.avatar_url
|
|
52
|
+
// From here down gitlab doesn't really have while calling the group api
|
|
53
|
+
// public_repos: group?.data?.public_repos,
|
|
54
|
+
// total_private_repos: group?.data?.total_private_repos,
|
|
55
|
+
// owned_private_repos: group?.data?.owned_private_repos,
|
|
56
|
+
};
|
|
57
|
+
groups.set(group.path, glGroup);
|
|
58
|
+
}
|
|
59
|
+
} catch (err) {
|
|
60
|
+
utils.handleError(
|
|
61
|
+
{ logger: deps.logger },
|
|
62
|
+
"Fetching groups with token from token",
|
|
63
|
+
credential,
|
|
64
|
+
errors,
|
|
65
|
+
err
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return { totalCount };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
exports.addGitlabTokenGroups = addGitlabTokenGroups;
|
|
72
|
+
//# sourceMappingURL=orgUtils.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orgUtils.cjs.js","sources":["../../../src/gitlab/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 { GitlabCredentials } from '@backstage/integration';\n\nimport { Gitlab } from '@gitbeaker/rest';\n\nimport {\n DefaultPageNumber,\n DefaultPageSize,\n} from '../../service/handlers/handlers';\nimport type { GitlabFetchError, GitlabOrganization } from '../types';\nimport { computeTotalCountFromPaginationInfo, handleError } from './utils';\n\nexport async function addGitlabTokenGroups(\n deps: {\n logger: LoggerService;\n },\n gitlab: InstanceType<typeof Gitlab<false>>,\n credential: GitlabCredentials,\n params: {\n search: string | undefined;\n groups: Map<string, GitlabOrganization>;\n errors: Map<number, GitlabFetchError>;\n pageNumber: number;\n pageSize: number;\n },\n): Promise<{ totalCount?: number }> {\n const search = params.search;\n const groups = params.groups;\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 matchingGroups;\n if (search) {\n // Use the group api with the search param.\n // I noticed that using this api will only return values when 3 or more characters are used for the search\n // that api gives us all the things the token has access\n const { data, paginationInfo } = await gitlab.Groups.all<true, 'offset'>({\n allAvailable: false,\n search: search,\n perPage: pageSize,\n page: pageNumber,\n showExpanded: true,\n });\n\n matchingGroups = data ?? [];\n\n totalCount = await computeTotalCountFromPaginationInfo(\n deps,\n paginationInfo,\n pageSize, // Not thrilled with this for some reason\n );\n } else {\n /**\n * The Groups all endpoint will grab all the groups the gitlab token has explicit access to.\n */\n\n const { data, paginationInfo } = await gitlab.Groups.all<true, 'offset'>({\n allAvailable: false,\n perPage: pageSize,\n page: pageNumber,\n showExpanded: true,\n });\n\n matchingGroups = data ?? [];\n\n totalCount = await computeTotalCountFromPaginationInfo(\n deps,\n paginationInfo,\n pageSize, // Not thrilled with this for some reason\n );\n }\n\n // Gitlab groups don't provide the same info that the github org provides, but some might not be needed\n // All the info we need is already part of that first request, so no need to go out again\n // Just in case we need it in the future, the gitlab.Groups.show('GROUP_ID') can be used to get a few more pieced of info\n for (const group of matchingGroups) {\n const glGroup: GitlabOrganization = {\n id: group.id,\n name: group.path,\n description: group.description ?? undefined,\n url: group.web_url,\n avatar_url: group.avatar_url,\n // From here down gitlab doesn't really have while calling the group api\n // public_repos: group?.data?.public_repos,\n // total_private_repos: group?.data?.total_private_repos,\n // owned_private_repos: group?.data?.owned_private_repos,\n };\n groups.set(group.path, glGroup);\n }\n } catch (err) {\n handleError(\n { logger: deps.logger },\n 'Fetching groups with token from token',\n credential,\n errors,\n err,\n );\n }\n return { totalCount };\n}\n"],"names":["DefaultPageNumber","DefaultPageSize","computeTotalCountFromPaginationInfo","handleError"],"mappings":";;;;;AA4BA,eAAsB,oBACpB,CAAA,IAAA,EAGA,MACA,EAAA,UAAA,EACA,MAOkC,EAAA;AAClC,EAAA,MAAM,SAAS,MAAO,CAAA,MAAA;AACtB,EAAA,MAAM,SAAS,MAAO,CAAA,MAAA;AACtB,EAAA,MAAM,SAAS,MAAO,CAAA,MAAA;AACtB,EAAM,MAAA,UAAA,GAAa,OAAO,UAAc,IAAAA,0BAAA;AACxC,EAAM,MAAA,QAAA,GAAW,OAAO,QAAY,IAAAC,wBAAA;AAEpC,EAAI,IAAA,UAAA;AACJ,EAAI,IAAA;AACF,IAAI,IAAA,cAAA;AACJ,IAAA,IAAI,MAAQ,EAAA;AAIV,MAAA,MAAM,EAAE,IAAM,EAAA,cAAA,KAAmB,MAAM,MAAA,CAAO,OAAO,GAAoB,CAAA;AAAA,QACvE,YAAc,EAAA,KAAA;AAAA,QACd,MAAA;AAAA,QACA,OAAS,EAAA,QAAA;AAAA,QACT,IAAM,EAAA,UAAA;AAAA,QACN,YAAc,EAAA;AAAA,OACf,CAAA;AAED,MAAA,cAAA,GAAiB,QAAQ,EAAC;AAE1B,MAAA,UAAA,GAAa,MAAMC,yCAAA;AAAA,QACjB,IAAA;AAAA,QACA,cAAA;AAAA,QACA;AAAA;AAAA,OACF;AAAA,KACK,MAAA;AAKL,MAAA,MAAM,EAAE,IAAM,EAAA,cAAA,KAAmB,MAAM,MAAA,CAAO,OAAO,GAAoB,CAAA;AAAA,QACvE,YAAc,EAAA,KAAA;AAAA,QACd,OAAS,EAAA,QAAA;AAAA,QACT,IAAM,EAAA,UAAA;AAAA,QACN,YAAc,EAAA;AAAA,OACf,CAAA;AAED,MAAA,cAAA,GAAiB,QAAQ,EAAC;AAE1B,MAAA,UAAA,GAAa,MAAMA,yCAAA;AAAA,QACjB,IAAA;AAAA,QACA,cAAA;AAAA,QACA;AAAA;AAAA,OACF;AAAA;AAMF,IAAA,KAAA,MAAW,SAAS,cAAgB,EAAA;AAClC,MAAA,MAAM,OAA8B,GAAA;AAAA,QAClC,IAAI,KAAM,CAAA,EAAA;AAAA,QACV,MAAM,KAAM,CAAA,IAAA;AAAA,QACZ,WAAA,EAAa,MAAM,WAAe,IAAA,KAAA,CAAA;AAAA,QAClC,KAAK,KAAM,CAAA,OAAA;AAAA,QACX,YAAY,KAAM,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAKpB;AACA,MAAO,MAAA,CAAA,GAAA,CAAI,KAAM,CAAA,IAAA,EAAM,OAAO,CAAA;AAAA;AAChC,WACO,GAAK,EAAA;AACZ,IAAAC,iBAAA;AAAA,MACE,EAAE,MAAQ,EAAA,IAAA,CAAK,MAAO,EAAA;AAAA,MACtB,uCAAA;AAAA,MACA,UAAA;AAAA,MACA,MAAA;AAAA,MACA;AAAA,KACF;AAAA;AAEF,EAAA,OAAO,EAAE,UAAW,EAAA;AACtB;;;;"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var catalogUtils = require('../../catalog/catalogUtils.cjs.js');
|
|
4
|
+
require('@backstage/errors');
|
|
5
|
+
require('@backstage/plugin-permission-common');
|
|
6
|
+
require('@red-hat-developer-hub/backstage-plugin-bulk-import-common');
|
|
7
|
+
require('just-kebab-case');
|
|
8
|
+
var loggingUtils = require('../../helpers/loggingUtils.cjs.js');
|
|
9
|
+
require('@backstage/catalog-model');
|
|
10
|
+
require('git-url-parse');
|
|
11
|
+
|
|
12
|
+
async function findOpenPRForBranch(logger, config, gitlab, owner, repo, branchName, withCatalogInfoContent = false) {
|
|
13
|
+
try {
|
|
14
|
+
const response = await gitlab.MergeRequests.all({
|
|
15
|
+
projectId: `${owner}/${repo}`,
|
|
16
|
+
state: "opened"
|
|
17
|
+
});
|
|
18
|
+
for (const pull of response) {
|
|
19
|
+
if (pull.source_branch === branchName) {
|
|
20
|
+
return {
|
|
21
|
+
prNum: pull.iid,
|
|
22
|
+
prUrl: pull.web_url,
|
|
23
|
+
prTitle: pull.title,
|
|
24
|
+
prBody: pull.description ?? void 0,
|
|
25
|
+
prCatalogInfoContent: withCatalogInfoContent ? await getCatalogInfoContentFromPR(
|
|
26
|
+
logger,
|
|
27
|
+
config,
|
|
28
|
+
gitlab,
|
|
29
|
+
owner,
|
|
30
|
+
repo,
|
|
31
|
+
pull.iid,
|
|
32
|
+
pull.sha
|
|
33
|
+
) : void 0,
|
|
34
|
+
lastUpdate: pull.updated_at
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
loggingUtils.logErrorIfNeeded(logger, "Error fetching pull requests", error);
|
|
40
|
+
}
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
async function getCatalogInfoContentFromPR(logger, config, gitlab, owner, repo, prNumber, prHeadSha) {
|
|
44
|
+
try {
|
|
45
|
+
const filePath = catalogUtils.getCatalogFilename(config);
|
|
46
|
+
const fileContentResponse = await gitlab.RepositoryFiles.show(
|
|
47
|
+
`${owner}/${repo}`,
|
|
48
|
+
filePath,
|
|
49
|
+
prHeadSha
|
|
50
|
+
);
|
|
51
|
+
if (!("content" in fileContentResponse)) {
|
|
52
|
+
return void 0;
|
|
53
|
+
}
|
|
54
|
+
return Buffer.from(fileContentResponse.content, "base64").toString("utf-8");
|
|
55
|
+
} catch (error) {
|
|
56
|
+
loggingUtils.logErrorIfNeeded(
|
|
57
|
+
logger,
|
|
58
|
+
`Error fetching catalog-info content from PR ${prNumber}`,
|
|
59
|
+
error
|
|
60
|
+
);
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function closePRWithComment(gitlab, owner, repo, prNum, comment) {
|
|
65
|
+
await gitlab.MergeRequestNotes.create(`${owner}/${repo}`, prNum, comment);
|
|
66
|
+
await gitlab.MergeRequests.edit(`${owner}/${repo}`, prNum, {
|
|
67
|
+
stateEvent: "close"
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
exports.closePRWithComment = closePRWithComment;
|
|
72
|
+
exports.findOpenPRForBranch = findOpenPRForBranch;
|
|
73
|
+
//# sourceMappingURL=prUtils.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prUtils.cjs.js","sources":["../../../src/gitlab/utils/prUtils.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 { Config } from '@backstage/config';\n\nimport { getCatalogFilename } from '../../catalog/catalogUtils';\nimport { logErrorIfNeeded } from '../../helpers';\n\nexport async function findOpenPRForBranch(\n logger: LoggerService,\n config: Config,\n gitlab: any,\n owner: string,\n repo: string,\n branchName: string,\n withCatalogInfoContent: boolean = false,\n): Promise<{\n prNum?: number;\n prUrl?: string;\n prTitle?: string;\n prBody?: string;\n prCatalogInfoContent?: string;\n lastUpdate?: string;\n}> {\n try {\n const response = await gitlab.MergeRequests.all({\n projectId: `${owner}/${repo}`,\n state: 'opened',\n });\n\n for (const pull of response) {\n if (pull.source_branch === branchName) {\n return {\n prNum: pull.iid,\n prUrl: pull.web_url,\n prTitle: pull.title,\n prBody: pull.description ?? undefined,\n prCatalogInfoContent: withCatalogInfoContent\n ? await getCatalogInfoContentFromPR(\n logger,\n config,\n gitlab,\n owner,\n repo,\n pull.iid,\n pull.sha,\n )\n : undefined,\n lastUpdate: pull.updated_at,\n };\n }\n }\n } catch (error) {\n logErrorIfNeeded(logger, 'Error fetching pull requests', error);\n }\n return {};\n}\n\nasync function getCatalogInfoContentFromPR(\n logger: LoggerService,\n config: Config,\n gitlab: any,\n owner: string,\n repo: string,\n prNumber: number,\n prHeadSha: string,\n): Promise<string | undefined> {\n try {\n const filePath = getCatalogFilename(config);\n const fileContentResponse = await gitlab.RepositoryFiles.show(\n `${owner}/${repo}`,\n filePath,\n prHeadSha,\n );\n if (!('content' in fileContentResponse)) {\n return undefined;\n }\n return Buffer.from(fileContentResponse.content, 'base64').toString('utf-8');\n } catch (error: any) {\n logErrorIfNeeded(\n logger,\n `Error fetching catalog-info content from PR ${prNumber}`,\n error,\n );\n return undefined;\n }\n}\n\nexport async function closePRWithComment(\n gitlab: any,\n owner: string,\n repo: string,\n prNum: number,\n comment: string,\n) {\n await gitlab.MergeRequestNotes.create(`${owner}/${repo}`, prNum, comment);\n await gitlab.MergeRequests.edit(`${owner}/${repo}`, prNum, {\n stateEvent: 'close',\n });\n}\n"],"names":["logErrorIfNeeded","getCatalogFilename"],"mappings":";;;;;;;;;;;AAsBsB,eAAA,mBAAA,CACpB,QACA,MACA,EAAA,MAAA,EACA,OACA,IACA,EAAA,UAAA,EACA,yBAAkC,KAQjC,EAAA;AACD,EAAI,IAAA;AACF,IAAA,MAAM,QAAW,GAAA,MAAM,MAAO,CAAA,aAAA,CAAc,GAAI,CAAA;AAAA,MAC9C,SAAW,EAAA,CAAA,EAAG,KAAK,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA;AAAA,MAC3B,KAAO,EAAA;AAAA,KACR,CAAA;AAED,IAAA,KAAA,MAAW,QAAQ,QAAU,EAAA;AAC3B,MAAI,IAAA,IAAA,CAAK,kBAAkB,UAAY,EAAA;A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AEA,eAAsB,kBACpB,CAAA,MAAA,EACA,KACA,EAAA,IAAA,EACA,OACA,OACA,EAAA;AACA,EAAM,MAAA,MAAA,CAAO,kBAAkB,MAAO,CAAA,CAAA,EAAG,KAAK,CAAI,CAAA,EAAA,IAAI,CAAI,CAAA,EAAA,KAAA,EAAO,OAAO,CAAA;AACxE,EAAM,MAAA,MAAA,CAAO,cAAc,IAAK,CAAA,CAAA,EAAG,KAAK,CAAI,CAAA,EAAA,IAAI,IAAI,KAAO,EAAA;AAAA,IACzD,UAAY,EAAA;AAAA,GACb,CAAA;AACH;;;;;"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var gitUrlParse = require('git-url-parse');
|
|
4
|
+
var catalogUtils = require('../../catalog/catalogUtils.cjs.js');
|
|
5
|
+
var handlers = require('../../service/handlers/handlers.cjs.js');
|
|
6
|
+
var utils = require('./utils.cjs.js');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var gitUrlParse__default = /*#__PURE__*/_interopDefaultCompat(gitUrlParse);
|
|
11
|
+
|
|
12
|
+
async function validateAndBuildRepoData(gitlabCredentialsProvider, integrations, config, input) {
|
|
13
|
+
const glConfig = integrations.gitlab.byUrl(input.repoUrl)?.config;
|
|
14
|
+
if (!glConfig) {
|
|
15
|
+
throw new Error(`Could not find GL integration from ${input.repoUrl}`);
|
|
16
|
+
}
|
|
17
|
+
const gitUrl = gitUrlParse__default.default(input.repoUrl);
|
|
18
|
+
const owner = gitUrl.organization;
|
|
19
|
+
const repo = gitUrl.name;
|
|
20
|
+
const credentials = await gitlabCredentialsProvider.getAllCredentials({
|
|
21
|
+
host: glConfig.host
|
|
22
|
+
});
|
|
23
|
+
if (credentials.length === 0) {
|
|
24
|
+
throw new Error(`No credentials for GL integration`);
|
|
25
|
+
}
|
|
26
|
+
const branchName = catalogUtils.getBranchName(config);
|
|
27
|
+
return { glConfig, owner, repo, credentials, branchName };
|
|
28
|
+
}
|
|
29
|
+
async function searchRepos(gitlab, glSearchQuery, pageNumber = handlers.DefaultPageNumber, pageSize = handlers.DefaultPageSize) {
|
|
30
|
+
const repoSearchResp = await gitlab.Projects.all({
|
|
31
|
+
search: glSearchQuery,
|
|
32
|
+
membership: true,
|
|
33
|
+
perPage: pageSize,
|
|
34
|
+
page: pageNumber
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
totalCount: repoSearchResp?.paginationInfo?.total,
|
|
38
|
+
repositories: repoSearchResp?.data?.map((repo) => {
|
|
39
|
+
return {
|
|
40
|
+
name: repo.name,
|
|
41
|
+
full_name: repo.path_with_namespace,
|
|
42
|
+
url: repo._links.self,
|
|
43
|
+
html_url: repo.web_url,
|
|
44
|
+
default_branch: repo.default_branch,
|
|
45
|
+
updated_at: repo.updated_at
|
|
46
|
+
};
|
|
47
|
+
}) ?? []
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async function addGitlabTokenRepositories(deps, gitlab, credential, repositories, errors, reqParams) {
|
|
51
|
+
const search = reqParams?.search;
|
|
52
|
+
const pageNumber = reqParams?.pageNumber ?? handlers.DefaultPageNumber;
|
|
53
|
+
const pageSize = reqParams?.pageSize ?? handlers.DefaultPageSize;
|
|
54
|
+
let totalCount;
|
|
55
|
+
try {
|
|
56
|
+
if (search) {
|
|
57
|
+
const searchResp = await searchRepos(
|
|
58
|
+
gitlab,
|
|
59
|
+
search,
|
|
60
|
+
pageNumber,
|
|
61
|
+
pageSize
|
|
62
|
+
);
|
|
63
|
+
totalCount = searchResp.totalCount;
|
|
64
|
+
searchResp.repositories.forEach(
|
|
65
|
+
(repo) => repositories.set(repo.full_name, repo)
|
|
66
|
+
);
|
|
67
|
+
} else {
|
|
68
|
+
const { data, paginationInfo } = await gitlab.Projects.all({
|
|
69
|
+
membership: true,
|
|
70
|
+
perPage: pageSize,
|
|
71
|
+
page: pageNumber,
|
|
72
|
+
showExpanded: true
|
|
73
|
+
});
|
|
74
|
+
data?.forEach((repo) => {
|
|
75
|
+
repositories.set(repo.path_with_namespace, {
|
|
76
|
+
name: repo.name,
|
|
77
|
+
full_name: repo.path_with_namespace,
|
|
78
|
+
url: repo._links.self,
|
|
79
|
+
html_url: repo.web_url,
|
|
80
|
+
default_branch: repo.default_branch,
|
|
81
|
+
updated_at: repo?.updated_at
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
totalCount = await utils.computeTotalCountFromPaginationInfo(
|
|
85
|
+
deps,
|
|
86
|
+
paginationInfo,
|
|
87
|
+
pageSize
|
|
88
|
+
// Not thrilled with this for some reason
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
utils.handleError(
|
|
93
|
+
deps,
|
|
94
|
+
"Fetching repositories with token from token",
|
|
95
|
+
credential,
|
|
96
|
+
errors,
|
|
97
|
+
err
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return { totalCount };
|
|
101
|
+
}
|
|
102
|
+
async function addGitlabTokenOrgRepositories(deps, gitlab, credential, org, repositories, errors, reqParams) {
|
|
103
|
+
const search = reqParams?.search;
|
|
104
|
+
const pageNumber = reqParams?.pageNumber ?? handlers.DefaultPageNumber;
|
|
105
|
+
const pageSize = reqParams?.pageSize ?? handlers.DefaultPageSize;
|
|
106
|
+
let totalCount;
|
|
107
|
+
try {
|
|
108
|
+
const params = {
|
|
109
|
+
perPage: pageSize,
|
|
110
|
+
search: search ?? void 0,
|
|
111
|
+
page: pageNumber,
|
|
112
|
+
showExpanded: true
|
|
113
|
+
};
|
|
114
|
+
const { data, paginationInfo } = await gitlab.Groups.allProjects(org, params);
|
|
115
|
+
data?.forEach((repo) => {
|
|
116
|
+
repositories.set(repo.path_with_namespace, {
|
|
117
|
+
name: repo.name,
|
|
118
|
+
full_name: repo.path_with_namespace,
|
|
119
|
+
url: repo._links.self,
|
|
120
|
+
html_url: repo.web_url,
|
|
121
|
+
default_branch: repo.default_branch,
|
|
122
|
+
updated_at: repo.updated_at
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
totalCount = await utils.computeTotalCountFromPaginationInfo(
|
|
126
|
+
deps,
|
|
127
|
+
paginationInfo,
|
|
128
|
+
pageSize
|
|
129
|
+
// Not thrilled with this for some reason
|
|
130
|
+
);
|
|
131
|
+
} catch (err) {
|
|
132
|
+
utils.handleError(
|
|
133
|
+
deps,
|
|
134
|
+
"Fetching org repositories with token from token",
|
|
135
|
+
credential,
|
|
136
|
+
errors,
|
|
137
|
+
err
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
return { totalCount };
|
|
141
|
+
}
|
|
142
|
+
async function fileExistsInDefaultBranch(logger, gitlab, owner, repo, fileName, defaultBranch = "main") {
|
|
143
|
+
try {
|
|
144
|
+
await gitlab.RepositoryFiles.show(
|
|
145
|
+
`${owner}/${repo}`,
|
|
146
|
+
fileName,
|
|
147
|
+
defaultBranch
|
|
148
|
+
);
|
|
149
|
+
return true;
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (error.cause.response.status === 404) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
logger.debug(
|
|
155
|
+
`Unable to determine if a file named ${fileName} already exists in repo ${repo}: ${error}`
|
|
156
|
+
);
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async function createOrUpdateFileInBranch(gitlab, owner, repo, branchName, fileName, fileContent) {
|
|
161
|
+
try {
|
|
162
|
+
const existingFile = await gitlab.RepositoryFiles.show(
|
|
163
|
+
`${owner}/${repo}`,
|
|
164
|
+
fileName,
|
|
165
|
+
branchName
|
|
166
|
+
);
|
|
167
|
+
if (Array.isArray(existingFile) || !("content_sha256" in existingFile)) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`The content at path ${fileName} is not a file or the response from gitlab does not contain the 'content_sha256' property.`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
await gitlab.RepositoryFiles.edit(
|
|
173
|
+
`${owner}/${repo}`,
|
|
174
|
+
fileName,
|
|
175
|
+
branchName,
|
|
176
|
+
fileContent,
|
|
177
|
+
`Add ${fileName} config file`
|
|
178
|
+
);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (error.cause.response.status === 404) {
|
|
181
|
+
await gitlab.RepositoryFiles.create(
|
|
182
|
+
`${owner}/${repo}`,
|
|
183
|
+
fileName,
|
|
184
|
+
branchName,
|
|
185
|
+
fileContent,
|
|
186
|
+
`Add ${fileName} config file`
|
|
187
|
+
);
|
|
188
|
+
} else {
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
exports.addGitlabTokenOrgRepositories = addGitlabTokenOrgRepositories;
|
|
195
|
+
exports.addGitlabTokenRepositories = addGitlabTokenRepositories;
|
|
196
|
+
exports.createOrUpdateFileInBranch = createOrUpdateFileInBranch;
|
|
197
|
+
exports.fileExistsInDefaultBranch = fileExistsInDefaultBranch;
|
|
198
|
+
exports.searchRepos = searchRepos;
|
|
199
|
+
exports.validateAndBuildRepoData = validateAndBuildRepoData;
|
|
200
|
+
//# sourceMappingURL=repoUtils.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repoUtils.cjs.js","sources":["../../../src/gitlab/utils/repoUtils.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 { Config } from '@backstage/config';\nimport type {\n GitlabCredentials,\n GitLabIntegrationConfig,\n ScmIntegrations,\n} from '@backstage/integration';\n\nimport {\n AllGroupProjectsOptions,\n BasePaginationRequestOptions,\n Gitlab,\n OffsetPaginationRequestOptions,\n ProjectSchema,\n ShowExpanded,\n Sudo,\n} from '@gitbeaker/rest';\nimport gitUrlParse from 'git-url-parse';\n\nimport { getBranchName } from '../../catalog/catalogUtils';\nimport {\n DefaultPageNumber,\n DefaultPageSize,\n} from '../../service/handlers/handlers';\nimport { CustomGitlabCredentialsProvider } from '../GitlabAppManager';\nimport type {\n ExtendedGitlabCredentials,\n GitlabFetchError,\n GitlabRepository,\n} from '../types';\nimport { computeTotalCountFromPaginationInfo, handleError } from './utils';\n\nexport type ValidatedRepo = {\n glConfig: GitLabIntegrationConfig;\n credentials: ExtendedGitlabCredentials[];\n owner: string;\n repo: string;\n branchName: string;\n};\n\nexport async function validateAndBuildRepoData(\n gitlabCredentialsProvider: CustomGitlabCredentialsProvider,\n integrations: ScmIntegrations,\n config: Config,\n input: {\n repoUrl: string;\n },\n): Promise<ValidatedRepo> {\n const glConfig = integrations.gitlab.byUrl(input.repoUrl)?.config;\n if (!glConfig) {\n throw new Error(`Could not find GL 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 gitlabCredentialsProvider.getAllCredentials({\n host: glConfig.host,\n });\n if (credentials.length === 0) {\n throw new Error(`No credentials for GL integration`);\n }\n\n const branchName = getBranchName(config);\n return { glConfig, owner, repo, credentials, branchName };\n}\n\nexport async function searchRepos(\n gitlab: InstanceType<typeof Gitlab<false>>,\n glSearchQuery: string,\n pageNumber: number = DefaultPageNumber,\n pageSize: number = DefaultPageSize,\n): Promise<{ totalCount?: number; repositories: GitlabRepository[] }> {\n const repoSearchResp = await gitlab.Projects.all<true, 'offset'>({\n search: glSearchQuery,\n membership: true,\n perPage: pageSize,\n page: pageNumber,\n });\n\n return {\n totalCount: repoSearchResp?.paginationInfo?.total,\n repositories:\n repoSearchResp?.data?.map((repo: ProjectSchema) => {\n return {\n name: repo.name,\n full_name: repo.path_with_namespace,\n url: repo._links.self,\n html_url: repo.web_url,\n default_branch: repo.default_branch,\n updated_at: repo.updated_at,\n };\n }) ?? [],\n };\n}\n\n/**\n * Adds the user or organization repositories accessible by the github token to the provided repositories Map<string, GithubRepository> if they're owned by the specified owner\n * If any errors occurs, adds them to the provided errors Map<number, GithubFetchError>\n */\nexport async function addGitlabTokenRepositories(\n deps: {\n logger: LoggerService;\n },\n gitlab: InstanceType<typeof Gitlab<false>>,\n credential: GitlabCredentials,\n repositories: Map<string, GitlabRepository>,\n errors: Map<number, GitlabFetchError>,\n reqParams?: {\n search?: string;\n pageNumber?: number;\n pageSize?: number;\n },\n): Promise<{ totalCount?: number }> {\n const search = reqParams?.search;\n const pageNumber = reqParams?.pageNumber ?? DefaultPageNumber;\n const pageSize = reqParams?.pageSize ?? DefaultPageSize;\n let totalCount: number | undefined;\n try {\n if (search) {\n // Use the projects api with the search param\n // that api gives us all the things the token has access to including the different projects in various groups\n\n const searchResp = await searchRepos(\n gitlab,\n search,\n pageNumber,\n pageSize,\n );\n totalCount = searchResp.totalCount;\n searchResp.repositories.forEach(repo =>\n repositories.set(repo.full_name, repo),\n );\n } else {\n /**\n * The Projects.all method with the membership: true option will grab all the repositories/projects the gitlab 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 { data, paginationInfo } = await gitlab.Projects.all<\n true,\n 'offset'\n >({\n membership: true,\n perPage: pageSize,\n page: pageNumber,\n showExpanded: true,\n });\n\n data?.forEach((repo: ProjectSchema) => {\n repositories.set(repo.path_with_namespace, {\n name: repo.name,\n full_name: repo.path_with_namespace,\n url: repo._links.self,\n html_url: repo.web_url,\n default_branch: repo.default_branch,\n updated_at: repo?.updated_at,\n });\n });\n\n /*\n paginationInfo: {\n total: , This is the total amount of repos, but will be NaN if the value is above 10k, see: https://github.com/jdalrymple/gitbeaker/issues/839#issuecomment-636482319\n next: ,\n current: ,\n previous: ,\n perPage: ,\n totalPages:\n }\n */\n\n totalCount = await computeTotalCountFromPaginationInfo(\n deps,\n paginationInfo,\n pageSize, // Not thrilled with this for some reason\n );\n }\n } catch (err) {\n handleError(\n deps,\n 'Fetching repositories with token from token',\n credential,\n errors,\n err,\n );\n }\n return { totalCount };\n}\n\nexport async function addGitlabTokenOrgRepositories(\n deps: {\n logger: LoggerService;\n },\n gitlab: InstanceType<typeof Gitlab<false>>,\n credential: GitlabCredentials,\n org: string,\n repositories: Map<string, GitlabRepository>,\n errors: Map<number, GitlabFetchError>,\n reqParams?: {\n search?: string;\n pageNumber?: number;\n pageSize?: number;\n },\n): Promise<{ totalCount?: number }> {\n const search = reqParams?.search;\n const pageNumber = reqParams?.pageNumber ?? DefaultPageNumber;\n const pageSize = reqParams?.pageSize ?? DefaultPageSize;\n let totalCount: number | undefined;\n try {\n // For Search: Use the group allProjects api with the search param.\n // I noticed that using this api will only return values when 3 or more characters are used for the search\n // that api gives us all the things the token has access\n const params:\n | (AllGroupProjectsOptions &\n BasePaginationRequestOptions<'offset'> &\n OffsetPaginationRequestOptions &\n Sudo &\n ShowExpanded<true>)\n | undefined = {\n perPage: pageSize,\n search: search ?? undefined,\n page: pageNumber,\n showExpanded: true,\n };\n\n const { data, paginationInfo } = await gitlab.Groups.allProjects<\n true,\n 'offset'\n >(org, params);\n\n data?.forEach((repo: ProjectSchema) => {\n repositories.set(repo.path_with_namespace, {\n name: repo.name,\n full_name: repo.path_with_namespace,\n url: repo._links.self,\n html_url: repo.web_url,\n default_branch: repo.default_branch,\n updated_at: repo.updated_at,\n });\n });\n\n totalCount = await computeTotalCountFromPaginationInfo(\n deps,\n paginationInfo,\n pageSize, // Not thrilled with this for some reason\n );\n } catch (err) {\n handleError(\n deps,\n 'Fetching org repositories with token from token',\n credential,\n errors,\n err,\n );\n }\n return { totalCount };\n}\n\nexport async function fileExistsInDefaultBranch(\n logger: LoggerService,\n gitlab: InstanceType<typeof Gitlab<false>>,\n owner: string,\n repo: string,\n fileName: string,\n defaultBranch: string = 'main',\n) {\n try {\n await gitlab.RepositoryFiles.show(\n `${owner}/${repo}`,\n fileName,\n defaultBranch,\n );\n return true;\n } catch (error: any) {\n if (error.cause.response.status === 404) {\n return false;\n }\n logger.debug(\n `Unable to determine if a file named ${fileName} already exists in repo ${repo}: ${error}`,\n );\n return undefined;\n }\n}\n\nexport async function createOrUpdateFileInBranch(\n gitlab: InstanceType<typeof Gitlab<false>>,\n owner: string,\n repo: string,\n branchName: string,\n fileName: string,\n fileContent: string,\n): Promise<void> {\n try {\n const existingFile = await gitlab.RepositoryFiles.show(\n `${owner}/${repo}`,\n fileName,\n 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) || !('content_sha256' in existingFile)) {\n throw new Error(\n `The content at path ${fileName} is not a file or the response from gitlab does not contain the 'content_sha256' property.`,\n );\n }\n // If the file already exists, update it\n await gitlab.RepositoryFiles.edit(\n `${owner}/${repo}`,\n fileName,\n branchName,\n fileContent,\n `Add ${fileName} config file`,\n );\n } catch (error: any) {\n if (error.cause.response.status === 404) {\n // If the file does not exist, create it\n await gitlab.RepositoryFiles.create(\n `${owner}/${repo}`,\n fileName,\n branchName,\n fileContent,\n `Add ${fileName} config file`,\n );\n } else {\n throw error;\n }\n }\n}\n"],"names":["gitUrlParse","getBranchName","DefaultPageNumber","DefaultPageSize","computeTotalCountFromPaginationInfo","handleError"],"mappings":";;;;;;;;;;;AAwDA,eAAsB,wBACpB,CAAA,yBAAA,EACA,YACA,EAAA,MAAA,EACA,KAGwB,EAAA;AACxB,EAAA,MAAM,WAAW,YAAa,CAAA,MAAA,CAAO,KAAM,CAAA,KAAA,CAAM,OAAO,CAAG,EAAA,MAAA;AAC3D,EAAA,IAAI,CAAC,QAAU,EAAA;AACb,IAAA,MAAM,IAAI,KAAA,CAAM,CAAsC,mC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