@red-hat-developer-hub/backstage-plugin-bulk-import-backend 7.1.1 → 7.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/catalog/catalogHttpClient.cjs.js.map +1 -1
- package/dist/catalog/catalogInfoGenerator.cjs.js.map +1 -1
- package/dist/catalog/catalogUtils.cjs.js.map +1 -1
- package/dist/database/migration.cjs.js.map +1 -1
- package/dist/database/repositoryDao.cjs.js.map +1 -1
- package/dist/generated/openapidocument.cjs.js.map +1 -1
- package/dist/github/GithubAppManager.cjs.js +8 -8
- package/dist/github/GithubAppManager.cjs.js.map +1 -1
- package/dist/github/githubApiService.cjs.js +6 -6
- package/dist/github/githubApiService.cjs.js.map +1 -1
- package/dist/github/types.cjs.js.map +1 -1
- package/dist/github/utils/ghUtils.cjs.js +3 -3
- package/dist/github/utils/ghUtils.cjs.js.map +1 -1
- package/dist/github/utils/orgUtils.cjs.js +1 -1
- package/dist/github/utils/orgUtils.cjs.js.map +1 -1
- package/dist/github/utils/prUtils.cjs.js +1 -1
- package/dist/github/utils/prUtils.cjs.js.map +1 -1
- package/dist/github/utils/repoUtils.cjs.js +1 -1
- package/dist/github/utils/repoUtils.cjs.js.map +1 -1
- package/dist/github/utils/utils.cjs.js +3 -3
- package/dist/github/utils/utils.cjs.js.map +1 -1
- package/dist/gitlab/GitlabAppManager.cjs.js.map +1 -1
- package/dist/gitlab/gitlabApiService.cjs.js +11 -11
- package/dist/gitlab/gitlabApiService.cjs.js.map +1 -1
- package/dist/gitlab/utils/glUtils.cjs.js.map +1 -1
- package/dist/gitlab/utils/orgUtils.cjs.js +1 -1
- package/dist/gitlab/utils/orgUtils.cjs.js.map +1 -1
- package/dist/gitlab/utils/prUtils.cjs.js +1 -1
- package/dist/gitlab/utils/prUtils.cjs.js.map +1 -1
- package/dist/gitlab/utils/repoUtils.cjs.js +1 -1
- package/dist/gitlab/utils/repoUtils.cjs.js.map +1 -1
- package/dist/gitlab/utils/utils.cjs.js +3 -3
- package/dist/gitlab/utils/utils.cjs.js.map +1 -1
- package/dist/helpers/auditorUtils.cjs.js.map +1 -1
- package/dist/helpers/auth.cjs.js.map +1 -1
- package/dist/helpers/loggingUtils.cjs.js.map +1 -1
- package/dist/helpers/pagination.cjs.js.map +1 -1
- package/dist/helpers/utils.cjs.js +1 -1
- package/dist/helpers/utils.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/service/handlers/handlers.cjs.js.map +1 -1
- package/dist/service/handlers/import/bulkImports.cjs.js +12 -12
- package/dist/service/handlers/import/bulkImports.cjs.js.map +1 -1
- package/dist/service/handlers/import/execute-orchestrator-workflow.cjs.js.map +1 -1
- package/dist/service/handlers/import/execute-template.cjs.js.map +1 -1
- package/dist/service/handlers/import/importStatus.cjs.js.map +1 -1
- package/dist/service/handlers/organization/organizations.cjs.js +4 -4
- package/dist/service/handlers/organization/organizations.cjs.js.map +1 -1
- package/dist/service/handlers/ping/ping.cjs.js.map +1 -1
- package/dist/service/handlers/repository/repositories.cjs.js +5 -5
- package/dist/service/handlers/repository/repositories.cjs.js.map +1 -1
- package/dist/service/router.cjs.js +5 -7
- package/dist/service/router.cjs.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repoUtils.cjs.js","sources":["../../../src/github/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 GithubCredentials,\n GithubIntegrationConfig,\n ScmIntegrations,\n} from '@backstage/integration';\n\nimport { Octokit } from '@octokit/rest';\nimport gitUrlParse from 'git-url-parse';\n\nimport { getBranchName } from '../../catalog/catalogUtils';\nimport { logErrorIfNeeded } from '../../helpers';\nimport {\n DefaultPageNumber,\n DefaultPageSize,\n} from '../../service/handlers/handlers';\nimport type { CustomGithubCredentialsProvider } from '../GithubAppManager';\nimport type {\n ExtendedGithubCredentials,\n GithubAppCredentials,\n GithubFetchError,\n GithubRepository,\n} from '../types';\nimport { getAllAppOrgs } from './orgUtils';\nimport {\n computeTotalCountFromGitHubToken,\n createCredentialError,\n handleError,\n} from './utils';\n\nexport type ValidatedRepo = {\n ghConfig: GithubIntegrationConfig;\n credentials: ExtendedGithubCredentials[];\n owner: string;\n repo: string;\n branchName: string;\n};\n\nexport async function validateAndBuildRepoData(\n githubCredentialsProvider: CustomGithubCredentialsProvider,\n integrations: ScmIntegrations,\n config: Config,\n input: {\n repoUrl: string;\n },\n): Promise<ValidatedRepo> {\n const ghConfig = 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 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(config);\n return { ghConfig, owner, repo, credentials, branchName };\n}\n\nexport async function searchRepos(\n octokit: Octokit,\n ghSearchQuery: string,\n pageNumber: number = DefaultPageNumber,\n pageSize: number = DefaultPageSize,\n): Promise<{ totalCount?: number; repositories: GithubRepository[] }> {\n const repoSearchResp = await octokit.rest.search.repos({\n q: ghSearchQuery,\n order: 'asc',\n page: pageNumber,\n per_page: pageSize,\n });\n return {\n totalCount: repoSearchResp?.data?.total_count,\n repositories:\n repoSearchResp?.data?.items?.map(repo => {\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\n/**\n * Adds the repositories accessible by the provided github app to the provided repositories Map<string, GithubRepository>\n * If any errors occurs, adds them to the provided errors Map<number, GithubFetchError>\n */\nexport async function addGithubAppRepositories(\n deps: {\n logger: LoggerService;\n githubCredentialsProvider: CustomGithubCredentialsProvider;\n },\n octokit: Octokit,\n credential: GithubAppCredentials,\n ghConfig: GithubIntegrationConfig,\n repositories: Map<string, GithubRepository>,\n errors: Map<number, GithubFetchError>,\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 const allOrgsMap = await getAllAppOrgs(\n deps.githubCredentialsProvider,\n ghConfig,\n credential.accountLogin,\n );\n const orgSearch: string[] = [];\n for (const [_orgUrl, ghOrg] of allOrgsMap) {\n orgSearch.push(`org:${ghOrg.name}`);\n }\n const query = `${search} in:name ${orgSearch.join(' ')}`;\n const searchResp = await searchRepos(\n octokit,\n query,\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 const resp = await octokit.apps.listReposAccessibleToInstallation({\n page: pageNumber,\n per_page: pageSize,\n });\n const repos = resp?.data?.repositories ?? resp?.data;\n repos?.forEach(repo => {\n repositories.set(repo.full_name, {\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 totalCount = resp?.data?.total_count;\n }\n } catch (err: any) {\n logErrorIfNeeded(\n deps.logger,\n `Fetching repositories with access token for github app ${credential.appId}`,\n err,\n );\n const credentialError = createCredentialError(credential, err as Error);\n if (credentialError) {\n errors.set(credential.appId, credentialError);\n }\n }\n return { totalCount };\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 addGithubTokenRepositories(\n deps: {\n logger: LoggerService;\n },\n octokit: Octokit,\n credential: GithubCredentials,\n repositories: Map<string, GithubRepository>,\n errors: Map<number, GithubFetchError>,\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 // Get currently authenticated user\n const username = (await octokit.rest.users.getAuthenticated())?.data\n ?.login;\n let query = `${search} in:name user:${username}`;\n\n const allOrgsResp = await octokit.paginate(\n octokit.rest.orgs.listForAuthenticatedUser,\n {\n sort: 'full_name',\n direction: 'asc',\n },\n );\n const orgSearch: string[] = [];\n allOrgsResp?.forEach(org => orgSearch.push(`org:${org.login}`));\n if (orgSearch.length > 0) {\n query += ` ${orgSearch.join(' ')}`;\n }\n\n const searchResp = await searchRepos(\n octokit,\n query,\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 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.repos.listForAuthenticatedUser({\n page: pageNumber,\n per_page: pageSize,\n sort: 'full_name',\n direction: 'asc',\n });\n resp?.data?.forEach(repo => {\n repositories.set(repo.full_name, {\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 totalCount = await computeTotalCountFromGitHubToken(\n deps,\n async (lastPageNumber: number) =>\n octokit.repos\n .listForAuthenticatedUser({\n page: lastPageNumber,\n per_page: 100,\n })\n .then(lastPageResp => lastPageResp.data.length),\n 'repos.listForAuthenticatedUser',\n resp?.data?.length,\n resp?.headers?.link,\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 addGithubTokenOrgRepositories(\n deps: {\n logger: LoggerService;\n },\n octokit: Octokit,\n credential: GithubCredentials,\n org: string,\n repositories: Map<string, GithubRepository>,\n errors: Map<number, GithubFetchError>,\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 const query = `${search} in:name org:${org}`;\n const searchResp = await searchRepos(\n octokit,\n query,\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 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.repos.listForOrg({\n org,\n page: pageNumber,\n per_page: pageSize,\n sort: 'full_name',\n direction: 'asc',\n });\n resp?.data?.forEach(repo => {\n const githubRepo: GithubRepository = {\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 ?? 'main',\n updated_at: repo.updated_at,\n };\n repositories.set(githubRepo.full_name, githubRepo);\n });\n\n totalCount = await computeTotalCountFromGitHubToken(\n deps,\n async (lastPageNumber: number) =>\n octokit.repos\n .listForOrg({\n org,\n page: lastPageNumber,\n per_page: 100,\n })\n .then(lastPageResp => lastPageResp.data.length),\n 'repos.listForOrg',\n resp?.data?.length,\n resp?.headers?.link,\n );\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 octo: Octokit,\n owner: string,\n repo: string,\n fileName: string,\n defaultBranch: string = 'main',\n) {\n try {\n await octo.rest.repos.getContent({\n owner,\n repo,\n path: fileName,\n ref: defaultBranch,\n });\n return true;\n } catch (error: any) {\n if (error.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 octo: Octokit,\n owner: string,\n repo: string,\n branchName: string,\n fileName: string,\n fileContent: string,\n): Promise<void> {\n try {\n const { data: existingFile } = await octo.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 octo.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 octo.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"],"names":["gitUrlParse","getBranchName","DefaultPageNumber","DefaultPageSize","getAllAppOrgs","logErrorIfNeeded","createCredentialError","computeTotalCountFromGitHubToken","handleError"],"mappings":";;;;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,IAAA;AAAA,QACA,OAAO,cAAA,KACL,OAAQ,CAAA,KAAA,CACL,UAAW,CAAA;AAAA,UACV,GAAA;AAAA,UACA,IAAM,EAAA,cAAA;AAAA,UACN,QAAU,EAAA;AAAA,SACX,CACA,CAAA,IAAA,CAAK,CAAgB,YAAA,KAAA,YAAA,CAAa,KAAK,MAAM,CAAA;AAAA,QAClD,kBAAA;AAAA,QACA,MAAM,IAAM,EAAA,MAAA;AAAA,QACZ,MAAM,OAAS,EAAA;AAAA,OACjB;AAAA;AACF,WACO,GAAK,EAAA;AACZ,IAAAC,iBAAA;AAAA,MACE,IAAA;AAAA,MACA,iDAAA;AAAA,MACA,UAAA;AAAA,MACA,MAAA;AAAA,MACA;AAAA,KACF;AAAA;AAEF,EAAA,OAAO,EAAE,UAAW,EAAA;AACtB;AAEA,eAAsB,0BACpB,MACA,EAAA,IAAA,EACA,OACA,IACA,EAAA,QAAA,EACA,gBAAwB,MACxB,EAAA;AACA,EAAI,IAAA;AACF,IAAM,MAAA,IAAA,CAAK,IAAK,CAAA,KAAA,CAAM,UAAW,CAAA;AAAA,MAC/B,KAAA;AAAA,MACA,IAAA;AAAA,MACA,IAAM,EAAA,QAAA;AAAA,MACN,GAAK,EAAA;AAAA,KACN,CAAA;AACD,IAAO,OAAA,IAAA;AAAA,WACA,KAAY,EAAA;AACnB,IAAI,IAAA,KAAA,CAAM,WAAW,GAAK,EAAA;AACxB,MAAO,OAAA,KAAA;AAAA;AAET,IAAO,MAAA,CAAA,KAAA;AAAA,MACL,CAAuC,oCAAA,EAAA,QAAQ,CAA2B,wBAAA,EAAA,IAAI,KAAK,KAAK,CAAA;AAAA,KAC1F;AACA,IAAO,OAAA,SAAA;AAAA;AAEX;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"repoUtils.cjs.js","sources":["../../../src/github/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 GithubCredentials,\n GithubIntegrationConfig,\n ScmIntegrations,\n} from '@backstage/integration';\n\nimport { Octokit } from '@octokit/rest';\nimport gitUrlParse from 'git-url-parse';\n\nimport { getBranchName } from '../../catalog/catalogUtils';\nimport { logErrorIfNeeded } from '../../helpers';\nimport {\n DefaultPageNumber,\n DefaultPageSize,\n} from '../../service/handlers/handlers';\nimport type { CustomGithubCredentialsProvider } from '../GithubAppManager';\nimport type {\n ExtendedGithubCredentials,\n GithubAppCredentials,\n GithubFetchError,\n GithubRepository,\n} from '../types';\nimport { getAllAppOrgs } from './orgUtils';\nimport {\n computeTotalCountFromGitHubToken,\n createCredentialError,\n handleError,\n} from './utils';\n\nexport type ValidatedRepo = {\n ghConfig: GithubIntegrationConfig;\n credentials: ExtendedGithubCredentials[];\n owner: string;\n repo: string;\n branchName: string;\n};\n\nexport async function validateAndBuildRepoData(\n githubCredentialsProvider: CustomGithubCredentialsProvider,\n integrations: ScmIntegrations,\n config: Config,\n input: {\n repoUrl: string;\n },\n): Promise<ValidatedRepo> {\n const ghConfig = 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 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(config);\n return { ghConfig, owner, repo, credentials, branchName };\n}\n\nexport async function searchRepos(\n octokit: Octokit,\n ghSearchQuery: string,\n pageNumber: number = DefaultPageNumber,\n pageSize: number = DefaultPageSize,\n): Promise<{ totalCount?: number; repositories: GithubRepository[] }> {\n const repoSearchResp = await octokit.rest.search.repos({\n q: ghSearchQuery,\n order: 'asc',\n page: pageNumber,\n per_page: pageSize,\n });\n return {\n totalCount: repoSearchResp?.data?.total_count,\n repositories:\n repoSearchResp?.data?.items?.map(repo => {\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\n/**\n * Adds the repositories accessible by the provided github app to the provided repositories Map<string, GithubRepository>\n * If any errors occurs, adds them to the provided errors Map<number, GithubFetchError>\n */\nexport async function addGithubAppRepositories(\n deps: {\n logger: LoggerService;\n githubCredentialsProvider: CustomGithubCredentialsProvider;\n },\n octokit: Octokit,\n credential: GithubAppCredentials,\n ghConfig: GithubIntegrationConfig,\n repositories: Map<string, GithubRepository>,\n errors: Map<number, GithubFetchError>,\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 const allOrgsMap = await getAllAppOrgs(\n deps.githubCredentialsProvider,\n ghConfig,\n credential.accountLogin,\n );\n const orgSearch: string[] = [];\n for (const [_orgUrl, ghOrg] of allOrgsMap) {\n orgSearch.push(`org:${ghOrg.name}`);\n }\n const query = `${search} in:name ${orgSearch.join(' ')}`;\n const searchResp = await searchRepos(\n octokit,\n query,\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 const resp = await octokit.apps.listReposAccessibleToInstallation({\n page: pageNumber,\n per_page: pageSize,\n });\n const repos = resp?.data?.repositories ?? resp?.data;\n repos?.forEach(repo => {\n repositories.set(repo.full_name, {\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 totalCount = resp?.data?.total_count;\n }\n } catch (err: any) {\n logErrorIfNeeded(\n deps.logger,\n `Fetching repositories with access token for github app ${credential.appId}`,\n err,\n );\n const credentialError = createCredentialError(credential, err as Error);\n if (credentialError) {\n errors.set(credential.appId, credentialError);\n }\n }\n return { totalCount };\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 addGithubTokenRepositories(\n deps: {\n logger: LoggerService;\n },\n octokit: Octokit,\n credential: GithubCredentials,\n repositories: Map<string, GithubRepository>,\n errors: Map<number, GithubFetchError>,\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 // Get currently authenticated user\n const username = (await octokit.rest.users.getAuthenticated())?.data\n ?.login;\n let query = `${search} in:name user:${username}`;\n\n const allOrgsResp = await octokit.paginate(\n octokit.rest.orgs.listForAuthenticatedUser,\n {\n sort: 'full_name',\n direction: 'asc',\n },\n );\n const orgSearch: string[] = [];\n allOrgsResp?.forEach(org => orgSearch.push(`org:${org.login}`));\n if (orgSearch.length > 0) {\n query += ` ${orgSearch.join(' ')}`;\n }\n\n const searchResp = await searchRepos(\n octokit,\n query,\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 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.repos.listForAuthenticatedUser({\n page: pageNumber,\n per_page: pageSize,\n sort: 'full_name',\n direction: 'asc',\n });\n resp?.data?.forEach(repo => {\n repositories.set(repo.full_name, {\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 totalCount = await computeTotalCountFromGitHubToken(\n deps,\n async (lastPageNumber: number) =>\n octokit.repos\n .listForAuthenticatedUser({\n page: lastPageNumber,\n per_page: 100,\n })\n .then(lastPageResp => lastPageResp.data.length),\n 'repos.listForAuthenticatedUser',\n resp?.data?.length,\n resp?.headers?.link,\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 addGithubTokenOrgRepositories(\n deps: {\n logger: LoggerService;\n },\n octokit: Octokit,\n credential: GithubCredentials,\n org: string,\n repositories: Map<string, GithubRepository>,\n errors: Map<number, GithubFetchError>,\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 const query = `${search} in:name org:${org}`;\n const searchResp = await searchRepos(\n octokit,\n query,\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 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.repos.listForOrg({\n org,\n page: pageNumber,\n per_page: pageSize,\n sort: 'full_name',\n direction: 'asc',\n });\n resp?.data?.forEach(repo => {\n const githubRepo: GithubRepository = {\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 ?? 'main',\n updated_at: repo.updated_at,\n };\n repositories.set(githubRepo.full_name, githubRepo);\n });\n\n totalCount = await computeTotalCountFromGitHubToken(\n deps,\n async (lastPageNumber: number) =>\n octokit.repos\n .listForOrg({\n org,\n page: lastPageNumber,\n per_page: 100,\n })\n .then(lastPageResp => lastPageResp.data.length),\n 'repos.listForOrg',\n resp?.data?.length,\n resp?.headers?.link,\n );\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 octo: Octokit,\n owner: string,\n repo: string,\n fileName: string,\n defaultBranch: string = 'main',\n) {\n try {\n await octo.rest.repos.getContent({\n owner,\n repo,\n path: fileName,\n ref: defaultBranch,\n });\n return true;\n } catch (error: any) {\n if (error.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 octo: Octokit,\n owner: string,\n repo: string,\n branchName: string,\n fileName: string,\n fileContent: string,\n): Promise<void> {\n try {\n const { data: existingFile } = await octo.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 octo.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 octo.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"],"names":["gitUrlParse","getBranchName","DefaultPageNumber","DefaultPageSize","getAllAppOrgs","logErrorIfNeeded","createCredentialError","computeTotalCountFromGitHubToken","handleError"],"mappings":";;;;;;;;;;;;;;;;;;AAuDA,eAAsB,wBAAA,CACpB,yBAAA,EACA,YAAA,EACA,MAAA,EACA,KAAA,EAGwB;AACxB,EAAA,MAAM,WAAW,YAAA,CAAa,MAAA,CAAO,KAAA,CAAM,KAAA,CAAM,OAAO,CAAA,EAAG,MAAA;AAC3D,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,mCAAA,EAAsC,KAAA,CAAM,OAAO,CAAA,CAAE,CAAA;AAAA,EACvE;AAEA,EAAA,MAAM,MAAA,GAASA,4BAAA,CAAY,KAAA,CAAM,OAAO,CAAA;AACxC,EAAA,MAAM,QAAQ,MAAA,CAAO,YAAA;AACrB,EAAA,MAAM,OAAO,MAAA,CAAO,IAAA;AAEpB,EAAA,MAAM,WAAA,GAAc,MAAM,yBAAA,CAA0B,iBAAA,CAAkB;AAAA,IACpE,MAAM,QAAA,CAAS;AAAA,GAChB,CAAA;AACD,EAAA,IAAI,WAAA,CAAY,WAAW,CAAA,EAAG;AAC5B,IAAA,MAAM,IAAI,MAAM,CAAA,iCAAA,CAAmC,CAAA;AAAA,EACrD;AAEA,EAAA,MAAM,UAAA,GAAaC,2BAAc,MAAM,CAAA;AACvC,EAAA,OAAO,EAAE,QAAA,EAAU,KAAA,EAAO,IAAA,EAAM,aAAa,UAAA,EAAW;AAC1D;AAEA,eAAsB,YACpB,OAAA,EACA,aAAA,EACA,UAAA,GAAqBC,0BAAA,EACrB,WAAmBC,wBAAA,EACiD;AACpE,EAAA,MAAM,cAAA,GAAiB,MAAM,OAAA,CAAQ,IAAA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AACxB,MAAA,OAAO,KAAA;AAAA,IACT;AACA,IAAA,MAAA,CAAO,KAAA;AAAA,MACL,CAAA,oCAAA,EAAuC,QAAQ,CAAA,wBAAA,EAA2B,IAAI,KAAK,KAAK,CAAA;AAAA,KAC1F;AACA,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;;;;;;;"}
|
|
@@ -45,7 +45,7 @@ function createCredentialError(credential, err) {
|
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
-
return
|
|
48
|
+
return void 0;
|
|
49
49
|
}
|
|
50
50
|
function verifyAndGetIntegrations(deps, integrations) {
|
|
51
51
|
const ghConfigs = integrations.github.list().map((ghInt) => ghInt.config);
|
|
@@ -105,7 +105,7 @@ async function computeTotalCountFromGitHubToken(deps, lastPageDataLengthProvider
|
|
|
105
105
|
}
|
|
106
106
|
const lastPageNumber = parseInt(match[1], 10);
|
|
107
107
|
const lastPageDataLength = await lastPageDataLengthProviderFn(lastPageNumber);
|
|
108
|
-
return pageSize ? (lastPageNumber - 1) * pageSize + lastPageDataLength :
|
|
108
|
+
return pageSize ? (lastPageNumber - 1) * pageSize + lastPageDataLength : void 0;
|
|
109
109
|
}
|
|
110
110
|
async function executeFunctionOnFirstSuccessfulIntegration(deps, integrations, params) {
|
|
111
111
|
const validatedRepo = await repoUtils.validateAndBuildRepoData(
|
|
@@ -132,7 +132,7 @@ async function executeFunctionOnFirstSuccessfulIntegration(deps, integrations, p
|
|
|
132
132
|
}
|
|
133
133
|
return res.result;
|
|
134
134
|
}
|
|
135
|
-
return
|
|
135
|
+
return void 0;
|
|
136
136
|
}
|
|
137
137
|
async function fetchFromAllIntegrations(deps, integrations, params) {
|
|
138
138
|
const ghConfigs = verifyAndGetIntegrations(deps, integrations);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs.js","sources":["../../../src/github/utils/utils.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 ScmIntegrations,\n type GithubIntegrationConfig,\n} from '@backstage/integration';\n\nimport { Octokit } from '@octokit/rest';\nimport gitUrlParse from 'git-url-parse';\n\nimport { logErrorIfNeeded } from '../../helpers';\nimport type { CustomGithubCredentialsProvider } from '../GithubAppManager';\nimport {\n isGithubAppCredential,\n type ExtendedGithubCredentials,\n type GithubFetchError,\n} from '../types';\nimport { buildOcto } from './ghUtils';\nimport { validateAndBuildRepoData, ValidatedRepo } from './repoUtils';\n\n/**\n * Creates the GithubFetchError to be stored in the returned errors array of the returned GithubRepositoryResponse object\n */\nexport function createCredentialError(\n credential: ExtendedGithubCredentials,\n err?: Error,\n): GithubFetchError | undefined {\n if (err) {\n if (isGithubAppCredential(credential)) {\n return {\n appId: credential.appId,\n type: 'app',\n error: {\n name: err.name,\n message: err.message,\n },\n };\n }\n return {\n type: 'token',\n error: {\n name: err.name,\n message: err.message,\n },\n };\n }\n if ('error' in credential) {\n return {\n appId: credential.appId,\n type: 'app',\n error: {\n name: credential.error.name,\n message: credential.error.message,\n },\n };\n }\n return undefined;\n}\n\nexport function verifyAndGetIntegrations(\n deps: {\n logger: LoggerService;\n },\n\n integrations: ScmIntegrations,\n) {\n const ghConfigs = integrations.github.list().map(ghInt => ghInt.config);\n if (ghConfigs.length === 0) {\n deps.logger.debug(\n 'No GitHub Integration in config => returning an empty list of repositories.',\n );\n throw new Error(\n \"Looks like there is no GitHub Integration in config. Please add a configuration entry under 'integrations.github\",\n );\n }\n return ghConfigs;\n}\n\nexport async function getCredentialsFromIntegrations(\n githubCredentialsProvider: CustomGithubCredentialsProvider,\n ghConfigs: GithubIntegrationConfig[],\n) {\n const credentialsByConfig = new Map<\n GithubIntegrationConfig,\n ExtendedGithubCredentials[]\n >();\n for (const ghConfig of ghConfigs) {\n const creds = await getCredentialsForConfig(\n githubCredentialsProvider,\n ghConfig,\n );\n credentialsByConfig.set(ghConfig, creds);\n }\n return credentialsByConfig;\n}\n\nexport async function getCredentialsForConfig(\n githubCredentialsProvider: CustomGithubCredentialsProvider,\n ghConfig: GithubIntegrationConfig,\n) {\n return await githubCredentialsProvider.getAllCredentials({\n host: ghConfig.host,\n });\n}\n\nexport async function extractConfigAndCreds(\n githubCredentialsProvider: CustomGithubCredentialsProvider,\n integrations: ScmIntegrations,\n input: {\n repoUrl: string;\n defaultBranch?: string;\n },\n) {\n const ghConfig = 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 credentials = await 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 gitUrl = gitUrlParse(input.repoUrl);\n return { ghConfig, credentials, gitUrl };\n}\n\nexport function handleError(\n deps: {\n logger: LoggerService;\n },\n desc: string,\n credential: ExtendedGithubCredentials,\n errors: Map<number, GithubFetchError>,\n err: any,\n) {\n logErrorIfNeeded(deps.logger, `${desc} failed`, err);\n const credentialError = createCredentialError(credential, err as Error);\n if (credentialError) {\n errors.set(-1, credentialError);\n }\n}\n\nexport async function computeTotalCountFromGitHubToken(\n deps: {\n logger: LoggerService;\n },\n lastPageDataLengthProviderFn: (lastPageNumber: number) => Promise<number>,\n ghApiName: string,\n pageSize?: number,\n linkHeader?: string,\n): Promise<number | undefined> {\n // There is no direct way to get the total count of repositories other than using octokit.paginate,\n // but will make us retrieve all pages, thus increasing our response time.\n // Workaround here is to analyze the headers, and get the link to the last page.\n if (!linkHeader) {\n deps.logger.debug(\n `No link header found in response from ${ghApiName} GH endpoint => returning current page size`,\n );\n return pageSize;\n }\n const lastPageLink = linkHeader\n .split(',')\n .find(s => s.includes('rel=\"last\"'));\n if (!lastPageLink) {\n deps.logger.debug(\n `No rel='last' link found in response headers from ${ghApiName} GH endpoint => returning current page size`,\n );\n return pageSize;\n }\n const match = lastPageLink.match(/page=(\\d+)/);\n if (!match || match.length < 2) {\n deps.logger.debug(\n `Unable to extract page number from rel='last' link found in response headers from ${ghApiName} GH endpoint => returning current page size`,\n );\n return pageSize;\n }\n\n const lastPageNumber = parseInt(match[1], 10);\n // Fetch the last page to count its items, as it might contain fewer than the requested size\n const lastPageDataLength = await lastPageDataLengthProviderFn(lastPageNumber);\n return pageSize\n ? (lastPageNumber - 1) * pageSize + lastPageDataLength\n : undefined;\n}\n\nexport async function executeFunctionOnFirstSuccessfulIntegration<T>(\n deps: {\n logger: LoggerService;\n cache: CacheService;\n config: Config;\n githubCredentialsProvider: CustomGithubCredentialsProvider;\n },\n integrations: ScmIntegrations,\n params: {\n repoUrl: string;\n fn: (\n validatedRepo: ValidatedRepo,\n octo: Octokit,\n ) => Promise<{ successful: boolean; result?: T }>;\n },\n) {\n const validatedRepo = await validateAndBuildRepoData(\n deps.githubCredentialsProvider,\n integrations,\n deps.config,\n params,\n );\n for (const credential of validatedRepo.credentials) {\n const octo = buildOcto(\n {\n logger: deps.logger,\n cache: deps.cache,\n },\n { credential, owner: validatedRepo.owner },\n validatedRepo.ghConfig.apiBaseUrl,\n );\n if (!octo) {\n continue;\n }\n const res = await params.fn(validatedRepo, octo);\n if (!res.successful) {\n continue;\n }\n return res.result;\n }\n return undefined;\n}\n\nexport async function fetchFromAllIntegrations<T>(\n deps: {\n logger: LoggerService;\n cache: CacheService;\n githubCredentialsProvider: CustomGithubCredentialsProvider;\n },\n integrations: ScmIntegrations,\n params: {\n dataFetcher: (\n octo: Octokit,\n credential: ExtendedGithubCredentials,\n ghConfig: GithubIntegrationConfig,\n ) => Promise<{\n stopFetchingData?: boolean;\n result?: T;\n errors?: GithubFetchError[];\n }>;\n },\n) {\n const ghConfigs = verifyAndGetIntegrations(deps, integrations);\n\n const credentialsByConfig = await getCredentialsFromIntegrations(\n deps.githubCredentialsProvider,\n ghConfigs,\n );\n const errors = new Map<number, GithubFetchError>();\n const data: T[] = [];\n const dataErrs: GithubFetchError[] = [];\n let stopFetchingData: boolean | undefined = false;\n for (const [ghConfig, credentials] of credentialsByConfig) {\n if (stopFetchingData) {\n break;\n }\n deps.logger.debug(\n `Got ${credentials.length} credential(s) for ${ghConfig.host}`,\n );\n for (const credential of credentials) {\n const octokit = buildOcto(\n deps,\n { credential, errors },\n ghConfig.apiBaseUrl,\n );\n if (!octokit) {\n continue;\n }\n const res = await params.dataFetcher(octokit, credential, ghConfig);\n res.errors?.forEach(err => dataErrs.push(err));\n\n if (res.result) {\n data.push(res.result);\n }\n\n stopFetchingData = res.stopFetchingData;\n }\n }\n\n const aggregatedErrors = new Map<number, GithubFetchError>();\n errors.forEach((err, num) => aggregatedErrors.set(num, err));\n dataErrs.forEach((err, idx) => aggregatedErrors.set(idx, err));\n\n return { data, errors: aggregatedErrors };\n}\n\nexport async function fetchFromMatchedIntegration<T>(\n deps: {\n logger: LoggerService;\n cache: CacheService;\n githubCredentialsProvider: CustomGithubCredentialsProvider;\n },\n integrations: ScmIntegrations,\n repoUrl: string,\n fetcher: (\n octokit: Octokit,\n gitUrl: gitUrlParse.GitUrl,\n ) => Promise<T | undefined>,\n): Promise<{ data?: T; errors: GithubFetchError[] }> {\n const gitUrl = gitUrlParse(repoUrl);\n const errors = new Map<number, GithubFetchError>();\n\n const ghConfig = 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 deps.githubCredentialsProvider,\n ghConfig,\n );\n\n for (const credential of credentials) {\n const octokit = buildOcto(\n {\n logger: deps.logger,\n cache: deps.cache,\n },\n { credential, errors, owner: gitUrl.owner },\n ghConfig.apiBaseUrl,\n );\n if (!octokit) {\n continue;\n }\n const data = await fetcher(octokit, gitUrl);\n if (data) {\n return { data, errors: Array.from(errors.values()) };\n }\n }\n\n return { errors: Array.from(errors.values()) };\n}\n"],"names":["isGithubAppCredential","logErrorIfNeeded","validateAndBuildRepoData","buildOcto","gitUrlParse"],"mappings":";;;;;;;;;;;;;;;;;AA0CgB,SAAA,qBAAA,CACd,YACA,GAC8B,EAAA;AAC9B,EAAA,IAAI,GAAK,EAAA;AACP,IAAI,IAAAA,2BAAA,CAAsB,UAAU,CAAG,EAAA;AACrC,MAAO,OAAA;AAAA,QACL,OAAO,UAAW,CAAA,KAAA;AAAA,QAClB,IAAM,EAAA,KAAA;AAAA,QACN,KAAO,EAAA;AAAA,UACL,MAAM,GAAI,CAAA,IAAA;AAAA,UACV,SAAS,GAAI,CAAA;AAAA;AACf,OACF;AAAA;AAEF,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,OAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,MAAM,GAAI,CAAA,IAAA;AAAA,QACV,SAAS,GAAI,CAAA;AAAA;AACf,KACF;AAAA;AAEF,EAAA,IAAI,WAAW,UAAY,EAAA;AACzB,IAAO,OAAA;AAAA,MACL,OAAO,UAAW,CAAA,KAAA;AAAA,MAClB,IAAM,EAAA,KAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IAAA,EAAM,WAAW,KAAM,CAAA,IAAA;AAAA,QACvB,OAAA,EAAS,WAAW,KAAM,CAAA;AAAA;AAC5B,KACF;AAAA;AAEF,EAAO,OAAA,SAAA;AACT;AAEgB,SAAA,wBAAA,CACd,MAIA,YACA,EAAA;AACA,EAAM,MAAA,SAAA,GAAY,aAAa,MAAO,CAAA,IAAA,GAAO,GAAI,CAAA,CAAA,KAAA,KAAS,MAAM,MAAM,CAAA;AACtE,EAAI,IAAA,SAAA,CA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,MACA,EAAE,UAAA,EAAY,MAAQ,EAAA,KAAA,EAAO,OAAO,KAAM,EAAA;AAAA,MAC1C,QAAS,CAAA;AAAA,KACX;AACA,IAAA,IAAI,CAAC,OAAS,EAAA;AACZ,MAAA;AAAA;AAEF,IAAA,MAAM,IAAO,GAAA,MAAM,OAAQ,CAAA,OAAA,EAAS,MAAM,CAAA;AAC1C,IAAA,IAAI,IAAM,EAAA;AACR,MAAO,OAAA,EAAE,MAAM,MAAQ,EAAA,KAAA,CAAM,KAAK,MAAO,CAAA,MAAA,EAAQ,CAAE,EAAA;AAAA;AACrD;AAGF,EAAA,OAAO,EAAE,MAAQ,EAAA,KAAA,CAAM,KAAK,MAAO,CAAA,MAAA,EAAQ,CAAE,EAAA;AAC/C;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.cjs.js","sources":["../../../src/github/utils/utils.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 ScmIntegrations,\n type GithubIntegrationConfig,\n} from '@backstage/integration';\n\nimport { Octokit } from '@octokit/rest';\nimport gitUrlParse from 'git-url-parse';\n\nimport { logErrorIfNeeded } from '../../helpers';\nimport type { CustomGithubCredentialsProvider } from '../GithubAppManager';\nimport {\n isGithubAppCredential,\n type ExtendedGithubCredentials,\n type GithubFetchError,\n} from '../types';\nimport { buildOcto } from './ghUtils';\nimport { validateAndBuildRepoData, ValidatedRepo } from './repoUtils';\n\n/**\n * Creates the GithubFetchError to be stored in the returned errors array of the returned GithubRepositoryResponse object\n */\nexport function createCredentialError(\n credential: ExtendedGithubCredentials,\n err?: Error,\n): GithubFetchError | undefined {\n if (err) {\n if (isGithubAppCredential(credential)) {\n return {\n appId: credential.appId,\n type: 'app',\n error: {\n name: err.name,\n message: err.message,\n },\n };\n }\n return {\n type: 'token',\n error: {\n name: err.name,\n message: err.message,\n },\n };\n }\n if ('error' in credential) {\n return {\n appId: credential.appId,\n type: 'app',\n error: {\n name: credential.error.name,\n message: credential.error.message,\n },\n };\n }\n return undefined;\n}\n\nexport function verifyAndGetIntegrations(\n deps: {\n logger: LoggerService;\n },\n\n integrations: ScmIntegrations,\n) {\n const ghConfigs = integrations.github.list().map(ghInt => ghInt.config);\n if (ghConfigs.length === 0) {\n deps.logger.debug(\n 'No GitHub Integration in config => returning an empty list of repositories.',\n );\n throw new Error(\n \"Looks like there is no GitHub Integration in config. Please add a configuration entry under 'integrations.github\",\n );\n }\n return ghConfigs;\n}\n\nexport async function getCredentialsFromIntegrations(\n githubCredentialsProvider: CustomGithubCredentialsProvider,\n ghConfigs: GithubIntegrationConfig[],\n) {\n const credentialsByConfig = new Map<\n GithubIntegrationConfig,\n ExtendedGithubCredentials[]\n >();\n for (const ghConfig of ghConfigs) {\n const creds = await getCredentialsForConfig(\n githubCredentialsProvider,\n ghConfig,\n );\n credentialsByConfig.set(ghConfig, creds);\n }\n return credentialsByConfig;\n}\n\nexport async function getCredentialsForConfig(\n githubCredentialsProvider: CustomGithubCredentialsProvider,\n ghConfig: GithubIntegrationConfig,\n) {\n return await githubCredentialsProvider.getAllCredentials({\n host: ghConfig.host,\n });\n}\n\nexport async function extractConfigAndCreds(\n githubCredentialsProvider: CustomGithubCredentialsProvider,\n integrations: ScmIntegrations,\n input: {\n repoUrl: string;\n defaultBranch?: string;\n },\n) {\n const ghConfig = 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 credentials = await 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 gitUrl = gitUrlParse(input.repoUrl);\n return { ghConfig, credentials, gitUrl };\n}\n\nexport function handleError(\n deps: {\n logger: LoggerService;\n },\n desc: string,\n credential: ExtendedGithubCredentials,\n errors: Map<number, GithubFetchError>,\n err: any,\n) {\n logErrorIfNeeded(deps.logger, `${desc} failed`, err);\n const credentialError = createCredentialError(credential, err as Error);\n if (credentialError) {\n errors.set(-1, credentialError);\n }\n}\n\nexport async function computeTotalCountFromGitHubToken(\n deps: {\n logger: LoggerService;\n },\n lastPageDataLengthProviderFn: (lastPageNumber: number) => Promise<number>,\n ghApiName: string,\n pageSize?: number,\n linkHeader?: string,\n): Promise<number | undefined> {\n // There is no direct way to get the total count of repositories other than using octokit.paginate,\n // but will make us retrieve all pages, thus increasing our response time.\n // Workaround here is to analyze the headers, and get the link to the last page.\n if (!linkHeader) {\n deps.logger.debug(\n `No link header found in response from ${ghApiName} GH endpoint => returning current page size`,\n );\n return pageSize;\n }\n const lastPageLink = linkHeader\n .split(',')\n .find(s => s.includes('rel=\"last\"'));\n if (!lastPageLink) {\n deps.logger.debug(\n `No rel='last' link found in response headers from ${ghApiName} GH endpoint => returning current page size`,\n );\n return pageSize;\n }\n const match = lastPageLink.match(/page=(\\d+)/);\n if (!match || match.length < 2) {\n deps.logger.debug(\n `Unable to extract page number from rel='last' link found in response headers from ${ghApiName} GH endpoint => returning current page size`,\n );\n return pageSize;\n }\n\n const lastPageNumber = parseInt(match[1], 10);\n // Fetch the last page to count its items, as it might contain fewer than the requested size\n const lastPageDataLength = await lastPageDataLengthProviderFn(lastPageNumber);\n return pageSize\n ? (lastPageNumber - 1) * pageSize + lastPageDataLength\n : undefined;\n}\n\nexport async function executeFunctionOnFirstSuccessfulIntegration<T>(\n deps: {\n logger: LoggerService;\n cache: CacheService;\n config: Config;\n githubCredentialsProvider: CustomGithubCredentialsProvider;\n },\n integrations: ScmIntegrations,\n params: {\n repoUrl: string;\n fn: (\n validatedRepo: ValidatedRepo,\n octo: Octokit,\n ) => Promise<{ successful: boolean; result?: T }>;\n },\n) {\n const validatedRepo = await validateAndBuildRepoData(\n deps.githubCredentialsProvider,\n integrations,\n deps.config,\n params,\n );\n for (const credential of validatedRepo.credentials) {\n const octo = buildOcto(\n {\n logger: deps.logger,\n cache: deps.cache,\n },\n { credential, owner: validatedRepo.owner },\n validatedRepo.ghConfig.apiBaseUrl,\n );\n if (!octo) {\n continue;\n }\n const res = await params.fn(validatedRepo, octo);\n if (!res.successful) {\n continue;\n }\n return res.result;\n }\n return undefined;\n}\n\nexport async function fetchFromAllIntegrations<T>(\n deps: {\n logger: LoggerService;\n cache: CacheService;\n githubCredentialsProvider: CustomGithubCredentialsProvider;\n },\n integrations: ScmIntegrations,\n params: {\n dataFetcher: (\n octo: Octokit,\n credential: ExtendedGithubCredentials,\n ghConfig: GithubIntegrationConfig,\n ) => Promise<{\n stopFetchingData?: boolean;\n result?: T;\n errors?: GithubFetchError[];\n }>;\n },\n) {\n const ghConfigs = verifyAndGetIntegrations(deps, integrations);\n\n const credentialsByConfig = await getCredentialsFromIntegrations(\n deps.githubCredentialsProvider,\n ghConfigs,\n );\n const errors = new Map<number, GithubFetchError>();\n const data: T[] = [];\n const dataErrs: GithubFetchError[] = [];\n let stopFetchingData: boolean | undefined = false;\n for (const [ghConfig, credentials] of credentialsByConfig) {\n if (stopFetchingData) {\n break;\n }\n deps.logger.debug(\n `Got ${credentials.length} credential(s) for ${ghConfig.host}`,\n );\n for (const credential of credentials) {\n const octokit = buildOcto(\n deps,\n { credential, errors },\n ghConfig.apiBaseUrl,\n );\n if (!octokit) {\n continue;\n }\n const res = await params.dataFetcher(octokit, credential, ghConfig);\n res.errors?.forEach(err => dataErrs.push(err));\n\n if (res.result) {\n data.push(res.result);\n }\n\n stopFetchingData = res.stopFetchingData;\n }\n }\n\n const aggregatedErrors = new Map<number, GithubFetchError>();\n errors.forEach((err, num) => aggregatedErrors.set(num, err));\n dataErrs.forEach((err, idx) => aggregatedErrors.set(idx, err));\n\n return { data, errors: aggregatedErrors };\n}\n\nexport async function fetchFromMatchedIntegration<T>(\n deps: {\n logger: LoggerService;\n cache: CacheService;\n githubCredentialsProvider: CustomGithubCredentialsProvider;\n },\n integrations: ScmIntegrations,\n repoUrl: string,\n fetcher: (\n octokit: Octokit,\n gitUrl: gitUrlParse.GitUrl,\n ) => Promise<T | undefined>,\n): Promise<{ data?: T; errors: GithubFetchError[] }> {\n const gitUrl = gitUrlParse(repoUrl);\n const errors = new Map<number, GithubFetchError>();\n\n const ghConfig = 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 deps.githubCredentialsProvider,\n ghConfig,\n );\n\n for (const credential of credentials) {\n const octokit = buildOcto(\n {\n logger: deps.logger,\n cache: deps.cache,\n },\n { credential, errors, owner: gitUrl.owner },\n ghConfig.apiBaseUrl,\n );\n if (!octokit) {\n continue;\n }\n const data = await fetcher(octokit, gitUrl);\n if (data) {\n return { data, errors: Array.from(errors.values()) };\n }\n }\n\n return { errors: Array.from(errors.values()) };\n}\n"],"names":["isGithubAppCredential","logErrorIfNeeded","validateAndBuildRepoData","buildOcto","gitUrlParse"],"mappings":";;;;;;;;;;;;;;;;;AA0CO,SAAS,qBAAA,CACd,YACA,GAAA,EAC8B;AAC9B,EAAA,IAAI,GAAA,EAAK;AACP,IAAA,IAAIA,2BAAA,CAAsB,UAAU,CAAA,EAAG;AACrC,MAAA,OAAO;AAAA,QACL,OAAO,UAAA,CAAW,KAAA;AAAA,QAClB,IAAA,EAAM,KAAA;AAAA,QACN,KAAA,EAAO;AAAA,UACL,MAAM,GAAA,CAAI,IAAA;AAAA,UACV,SAAS,GAAA,CAAI;AAAA;AACf,OACF;AAAA,IACF;AACA,I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ppManager.cjs.js","sources":["../../src/gitlab/GitlabAppManager.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 */\nimport type {\n GitlabCredentials,\n GitLabIntegrationConfig,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\n\nimport {\n ExtendedGitlabCredentials,\n ExtendedGitlabCredentialsProvider,\n} from './types';\n\n// For reference\n// https://github.com/backstage/backstage/blob/master/packages/integration/src/gitlab/SingleInstanceGitlabCredentialsProvider.ts\n\nexport class CustomSingleInstanceGitlabCredentialsProvider implements ExtendedGitlabCredentialsProvider {\n static readonly create: (\n config: GitLabIntegrationConfig,\n ) => ExtendedGitlabCredentialsProvider = config => {\n return new CustomSingleInstanceGitlabCredentialsProvider(config.token);\n };\n\n private constructor(private readonly token?: string) {}\n async getAllCredentials(_opts: {\n host: string;\n }): Promise<ExtendedGitlabCredentials[]> {\n const credentials: ExtendedGitlabCredentials[] = [];\n if (this.token) {\n credentials.push({\n headers: { Authorization: `Bearer ${this.token}` },\n token: this.token,\n });\n }\n return credentials;\n }\n getCredentials(_opts: { url: string }): Promise<GitlabCredentials> {\n throw new Error('Method not implemented.');\n }\n}\n\nexport class CustomGitlabCredentialsProvider implements ExtendedGitlabCredentialsProvider {\n static fromIntegrations(integrations: ScmIntegrationRegistry) {\n const credentialsProviders: Map<string, ExtendedGitlabCredentialsProvider> =\n new Map<string, ExtendedGitlabCredentialsProvider>();\n\n integrations.gitlab.list().forEach(integration => {\n const credtialsProvider =\n CustomSingleInstanceGitlabCredentialsProvider.create(\n integration.config,\n );\n credentialsProviders.set(integration.config.host, credtialsProvider);\n });\n\n return new CustomGitlabCredentialsProvider(credentialsProviders);\n }\n\n private constructor(\n private readonly providers: Map<string, ExtendedGitlabCredentialsProvider>,\n ) {}\n async getAllCredentials(opts: {\n host: string;\n }): Promise<ExtendedGitlabCredentials[]> {\n const provider = this.providers.get(opts.host);\n\n if (!provider) {\n throw new Error(\n `There is no GitLab integration that matches ${opts.host}. Please add a configuration for an integration.`,\n );\n }\n return provider.getAllCredentials(opts);\n }\n getCredentials(_opts: { url: string }): Promise<GitlabCredentials> {\n throw new Error('Method not implemented.');\n }\n}\n"],"names":[],"mappings":";;AA6BO,MAAM,
|
|
1
|
+
{"version":3,"file":"GitlabAppManager.cjs.js","sources":["../../src/gitlab/GitlabAppManager.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 */\nimport type {\n GitlabCredentials,\n GitLabIntegrationConfig,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\n\nimport {\n ExtendedGitlabCredentials,\n ExtendedGitlabCredentialsProvider,\n} from './types';\n\n// For reference\n// https://github.com/backstage/backstage/blob/master/packages/integration/src/gitlab/SingleInstanceGitlabCredentialsProvider.ts\n\nexport class CustomSingleInstanceGitlabCredentialsProvider implements ExtendedGitlabCredentialsProvider {\n static readonly create: (\n config: GitLabIntegrationConfig,\n ) => ExtendedGitlabCredentialsProvider = config => {\n return new CustomSingleInstanceGitlabCredentialsProvider(config.token);\n };\n\n private constructor(private readonly token?: string) {}\n async getAllCredentials(_opts: {\n host: string;\n }): Promise<ExtendedGitlabCredentials[]> {\n const credentials: ExtendedGitlabCredentials[] = [];\n if (this.token) {\n credentials.push({\n headers: { Authorization: `Bearer ${this.token}` },\n token: this.token,\n });\n }\n return credentials;\n }\n getCredentials(_opts: { url: string }): Promise<GitlabCredentials> {\n throw new Error('Method not implemented.');\n }\n}\n\nexport class CustomGitlabCredentialsProvider implements ExtendedGitlabCredentialsProvider {\n static fromIntegrations(integrations: ScmIntegrationRegistry) {\n const credentialsProviders: Map<string, ExtendedGitlabCredentialsProvider> =\n new Map<string, ExtendedGitlabCredentialsProvider>();\n\n integrations.gitlab.list().forEach(integration => {\n const credtialsProvider =\n CustomSingleInstanceGitlabCredentialsProvider.create(\n integration.config,\n );\n credentialsProviders.set(integration.config.host, credtialsProvider);\n });\n\n return new CustomGitlabCredentialsProvider(credentialsProviders);\n }\n\n private constructor(\n private readonly providers: Map<string, ExtendedGitlabCredentialsProvider>,\n ) {}\n async getAllCredentials(opts: {\n host: string;\n }): Promise<ExtendedGitlabCredentials[]> {\n const provider = this.providers.get(opts.host);\n\n if (!provider) {\n throw new Error(\n `There is no GitLab integration that matches ${opts.host}. Please add a configuration for an integration.`,\n );\n }\n return provider.getAllCredentials(opts);\n }\n getCredentials(_opts: { url: string }): Promise<GitlabCredentials> {\n throw new Error('Method not implemented.');\n }\n}\n"],"names":[],"mappings":";;AA6BO,MAAM,6CAAA,CAA2F;AAAA,EAO9F,YAA6B,KAAA,EAAgB;AAAhB,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAAA,EAAiB;AAAA,EANtD,OAAgB,SAEyB,CAAA,MAAA,KAAU;AACjD,IAAA,OAAO,IAAI,6CAAA,CAA8C,MAAA,CAAO,KAAK,CAAA;AAAA,EACvE,CAAA;AAAA,EAGA,MAAM,kBAAkB,KAAA,EAEiB;AACvC,IAAA,MAAM,cAA2C,EAAC;AAClD,IAAA,IAAI,KAAK,KAAA,EAAO;AACd,MAAA,WAAA,CAAY,IAAA,CAAK;AAAA,QACf,SAAS,EAAE,aAAA,EAAe,CAAA,OAAA,EAAU,IAAA,CAAK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itlabCredentialsProvider,
|
|
62
62
|
glConfig
|
|
63
63
|
);
|
|
64
|
-
let repository =
|
|
64
|
+
let repository = void 0;
|
|
65
65
|
for (const credential of credentials) {
|
|
66
66
|
const glKit = glUtils.buildGitlab(
|
|
67
67
|
{
|
|
@@ -297,7 +297,7 @@ class GitlabApiService {
|
|
|
297
297
|
logger: this.logger,
|
|
298
298
|
cache: this.cache
|
|
299
299
|
},
|
|
300
|
-
{ credential
|
|
300
|
+
{ credential},
|
|
301
301
|
glConfig.baseUrl
|
|
302
302
|
);
|
|
303
303
|
try {
|
|
@@ -470,14 +470,14 @@ class GitlabApiService {
|
|
|
470
470
|
input.fileName,
|
|
471
471
|
input.defaultBranch
|
|
472
472
|
);
|
|
473
|
-
if (exists ===
|
|
473
|
+
if (exists === void 0) {
|
|
474
474
|
return { successful: false };
|
|
475
475
|
}
|
|
476
476
|
return { successful: true, result: exists };
|
|
477
477
|
}
|
|
478
478
|
}
|
|
479
479
|
);
|
|
480
|
-
if (fileExists ===
|
|
480
|
+
if (fileExists === void 0) {
|
|
481
481
|
throw new Error(
|
|
482
482
|
`Could not determine if repo at ${input.repoUrl} already has a file named ${input.fileName} in its default branch (${input.defaultBranch})`
|
|
483
483
|
);
|
|
@@ -604,7 +604,7 @@ class GitlabApiService {
|
|
|
604
604
|
logger: this.logger,
|
|
605
605
|
cache: this.cache
|
|
606
606
|
},
|
|
607
|
-
{ credential
|
|
607
|
+
{ credential},
|
|
608
608
|
glConfig.baseUrl
|
|
609
609
|
);
|
|
610
610
|
try {
|
|
@@ -635,7 +635,7 @@ class GitlabApiService {
|
|
|
635
635
|
logger.error(
|
|
636
636
|
`No Gitlab integration config found for repo ${input.repoUrl}`
|
|
637
637
|
);
|
|
638
|
-
return
|
|
638
|
+
return void 0;
|
|
639
639
|
}
|
|
640
640
|
const gitUrl = gitUrlParse__default.default(input.repoUrl);
|
|
641
641
|
const owner = gitUrl.owner;
|
|
@@ -645,7 +645,7 @@ class GitlabApiService {
|
|
|
645
645
|
});
|
|
646
646
|
if (credentials.length === 0) {
|
|
647
647
|
logger.error(`No credentials for GL integration`);
|
|
648
|
-
return
|
|
648
|
+
return void 0;
|
|
649
649
|
}
|
|
650
650
|
for (const credential of credentials) {
|
|
651
651
|
const glKit = glUtils.buildGitlab(
|
|
@@ -653,7 +653,7 @@ class GitlabApiService {
|
|
|
653
653
|
logger: this.logger,
|
|
654
654
|
cache: this.cache
|
|
655
655
|
},
|
|
656
|
-
{ credential
|
|
656
|
+
{ credential},
|
|
657
657
|
glConfig.baseUrl
|
|
658
658
|
);
|
|
659
659
|
try {
|
|
@@ -671,16 +671,16 @@ class GitlabApiService {
|
|
|
671
671
|
logger.warn(
|
|
672
672
|
`catalog-info.yaml not found in PR ${input.prNumber} of ${input.repoUrl}`
|
|
673
673
|
);
|
|
674
|
-
return
|
|
674
|
+
return void 0;
|
|
675
675
|
}
|
|
676
676
|
logger.error(
|
|
677
677
|
`Error fetching catalog-info.yaml from PR ${input.prNumber} of ${input.repoUrl}`,
|
|
678
678
|
error
|
|
679
679
|
);
|
|
680
|
-
return
|
|
680
|
+
return void 0;
|
|
681
681
|
}
|
|
682
682
|
}
|
|
683
|
-
return
|
|
683
|
+
return void 0;
|
|
684
684
|
}
|
|
685
685
|
}
|
|
686
686
|
|
|
@@ -1 +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 DefaultGitlabCredentialsProvider,\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 getCredentials(repoUrl: string): Promise<{ token: string }> {\n const provider = DefaultGitlabCredentialsProvider.fromIntegrations(\n this.integrations,\n );\n const creds = await provider.getCredentials({\n url: repoUrl,\n });\n if (!creds || !creds.token) {\n throw new Error(`Token not configured for 'gitlab' provider`);\n }\n return {\n token: creds.token,\n };\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 try {\n const username = (await gitlab.Users.showCurrentUser()).username;\n if (username) {\n allAccessibleUsernames.add(username);\n }\n } catch (err) {\n logErrorIfNeeded(\n this.logger,\n 'failed to fetch gitlab current user',\n err,\n );\n }\n\n // ... along with orgs accessible from the token auth\n try {\n const allGroups = await gitlab.Groups.all<false, 'offset'>({\n allAvailable: false,\n });\n allGroups\n .map(org => org.path)\n ?.forEach((orgName: string) =>\n allAccessibleTokenOrgs.add(orgName),\n );\n } catch (err) {\n logErrorIfNeeded(this.logger, 'failed to fetch gitlab groups', err);\n }\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 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","DefaultGitlabCredentialsProvider","gitUrlParse","getCredentialsForConfig","buildGitlab","DefaultPageNumber","DefaultPageSize","fetchFromAllIntegrations","addGitlabTokenGroups","computeTotalCount","addGitlabTokenOrgRepositories","addGitlabTokenRepositories","extractLocationOwnerMap","logErrorIfNeeded","getBranchName","findOpenPRForBranch","getCatalogFilename","executeFunctionOnFirstSuccessfulIntegration","fileExistsInDefaultBranch","createOrUpdateFileInBranch","pullRequestResponse","closePRWithComment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiEO,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,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AA,QACpB,QAAS,CAAA;AAAA,OACX;AAEA,MAAI,IAAA;AACF,QAAM,MAAA,IAAA,GAAO,MAAM,KAAA,CAAM,eAAgB,CAAA,IAAA;AAAA,UACvC,CAAA,EAAG,KAAK,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA;AAAA,UAChBY,+BAAA,CAAmB,KAAK,MAAM,CAAA;AAAA,UAC9B,KAAM,CAAA;AAAA,SACR;AAEA,QAAA,IAAI,IAAM,EAAA;AACR,UAAM,MAAA,OAAA,GAAU,OAAO,IAAK,CAAA,IAAA,CAAK,SAAS,QAAQ,CAAA,CAAE,SAAS,OAAO,CAAA;AACpE,UAAO,OAAA,OAAA;AAAA;AACT,eACO,KAAY,EAAA;AACnB,QAAA,IAAI,KAAM,CAAA,KAAA,EAAO,QAAU,EAAA,MAAA,KAAW,GAAK,EAAA;AACzC,UAAO,MAAA,CAAA,IAAA;AAAA,YACL,CAAqC,kCAAA,EAAA,KAAA,CAAM,QAAQ,CAAA,IAAA,EAAO,MAAM,OAAO,CAAA;AAAA,WACzE;AACA,UAAO,OAAA,SAAA;AAAA;AAET,QAAO,MAAA,CAAA,KAAA;AAAA,UACL,CAA4C,yCAAA,EAAA,KAAA,CAAM,QAAQ,CAAA,IAAA,EAAO,MAAM,OAAO,CAAA,CAAA;AAAA,UAC9E;AAAA,SACF;AACA,QAAO,OAAA,SAAA;AAAA;AACT;AAGF,IAAO,OAAA,SAAA;AAAA;AAEX;;;;"}
|
|
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 DefaultGitlabCredentialsProvider,\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 getCredentials(repoUrl: string): Promise<{ token: string }> {\n const provider = DefaultGitlabCredentialsProvider.fromIntegrations(\n this.integrations,\n );\n const creds = await provider.getCredentials({\n url: repoUrl,\n });\n if (!creds || !creds.token) {\n throw new Error(`Token not configured for 'gitlab' provider`);\n }\n return {\n token: creds.token,\n };\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 try {\n const username = (await gitlab.Users.showCurrentUser()).username;\n if (username) {\n allAccessibleUsernames.add(username);\n }\n } catch (err) {\n logErrorIfNeeded(\n this.logger,\n 'failed to fetch gitlab current user',\n err,\n );\n }\n\n // ... along with orgs accessible from the token auth\n try {\n const allGroups = await gitlab.Groups.all<false, 'offset'>({\n allAvailable: false,\n });\n allGroups\n .map(org => org.path)\n ?.forEach((orgName: string) =>\n allAccessibleTokenOrgs.add(orgName),\n );\n } catch (err) {\n logErrorIfNeeded(this.logger, 'failed to fetch gitlab groups', err);\n }\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 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","DefaultGitlabCredentialsProvider","gitUrlParse","getCredentialsForConfig","buildGitlab","DefaultPageNumber","DefaultPageSize","fetchFromAllIntegrations","addGitlabTokenGroups","computeTotalCount","addGitlabTokenOrgRepositories","addGitlabTokenRepositories","extractLocationOwnerMap","logErrorIfNeeded","getBranchName","findOpenPRForBranch","getCatalogFilename","executeFunctionOnFirstSuccessfulIntegration","fileExistsInDefaultBranch","createOrUpdateFileInBranch","pullRequestResponse","closePRWithComment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiEO,MAAM,gBAAA,CAAiB;AAAA,EACX,MAAA;AAAA,EACA,YAAA;AAAA,EACA,yBAAA;AAAA,EACA,MAAA;AAAA;AAAA,EAEA,KAAA;AAAA,EACjB,WAAA,CACE,MAAA,EACA,MAAA,EACA,YAAA,EACA;AACA,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAC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AA;AAAA,UAC9E;AAAA,SACF;AACA,QAAA,OAAO,MAAA;AAAA,MACT;AAAA,IACF;AAEA,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;;"}
|
|
@@ -1 +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,
|
|
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,uBAAA,GAA0B,oBAAA;AAEzB,SAAS,WAAA,CACd,KAAA,EAIA,KAAA,EAKA,OAAA,GAAkB,uBAAA,EACkB;AACpC,EAAA,MAAM,QAAA,GAAW,IAAIA,WAAA,CAAO;AAAA,IAC1B,IAAA,EAAM,OAAA;AAAA,IACN,KAAA,EAAO,MAAM,UAAA,CAAW;AAAA,GACzB,CAAA;AACD,EAAA,OAAO,QAAA;AACT;;;;"}
|
|
@@ -48,7 +48,7 @@ async function addGitlabTokenGroups(deps, gitlab, credential, params) {
|
|
|
48
48
|
name: group.path,
|
|
49
49
|
description: group.description ?? void 0,
|
|
50
50
|
url: group.web_url,
|
|
51
|
-
avatar_url: group.avatar_url
|
|
51
|
+
avatar_url: group.avatar_url ?? void 0
|
|
52
52
|
// From here down gitlab doesn't really have while calling the group api
|
|
53
53
|
// public_repos: group?.data?.public_repos,
|
|
54
54
|
// total_private_repos: group?.data?.total_private_repos,
|
|
@@ -1 +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,
|
|
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 ?? undefined,\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,oBAAA,CACpB,IAAA,EAGA,MAAA,EACA,UAAA,EACA,MAAA,EAOkC;AAClC,EAAA,MAAM,SAAS,MAAA,CAAO,MAAA;AACtB,EAAA,MAAM,SAAS,MAAA,CAAO,MAAA;AACtB,EAAA,MAAM,SAAS,MAAA,CAAO,MAAA;AACtB,EAAA,MAAM,UAAA,GAAa,OAAO,UAAA,IAAcA,0BAAA;AACxC,EAAA,MAAM,QAAA,GAAW,OAAO,QAAA,IAAYC,wBAAA;AAEpC,EAAA,IAAI,UAAA;AACJ,EAAA,IAAI;AACF,IAAA,IAAI,cAAA;AACJ,IAAA,IAAI,MAAA,EAAQ;AAIV,MAAA,MAAM,EAAE,IAAA,EAAM,cAAA,KAAmB,MAAM,MAAA,CAAO,OAAO,GAAA,CAAoB;AAAA,QACvE,YAAA,EAAc,KAAA;AAAA,QACd,MAAA;AAAA,QACA,OAAA,EAAS,QAAA;AAAA,QACT,IAAA,EAAM,UAAA;AAAA,QACN,YAAA,EAAc;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,IACF,CAAA,MAAO;AAKL,MAAA,MAAM,EAAE,IAAA,EAAM,cAAA,KAAmB,MAAM,MAAA,CAAO,OAAO,GAAA,CAAoB;AAAA,QACvE,YAAA,EAAc,KAAA;AAAA,QACd,OAAA,EAAS,QAAA;AAAA,QACT,IAAA,EAAM,UAAA;AAAA,QACN,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