@backstage/integration 1.16.2-next.0 → 1.16.2
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 +10 -0
- package/dist/gerrit/core.cjs.js.map +1 -1
- package/dist/gerrit/core.esm.js.map +1 -1
- package/dist/index.cjs.js +1 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.esm.js +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @backstage/integration
|
|
2
2
|
|
|
3
|
+
## 1.16.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 89db8b8: Gerrit integration now exports `getGitilesAuthenticationUrl`. This enables its usage by the `GerritUrlReader`.
|
|
8
|
+
- 4f8b5b6: Allow signing git commits using configured private PGP key in scaffolder
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
- @backstage/config@1.3.2
|
|
11
|
+
- @backstage/errors@1.2.7
|
|
12
|
+
|
|
3
13
|
## 1.16.2-next.0
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs.js","sources":["../../src/gerrit/core.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\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 { join, takeWhile, trimEnd, trimStart } from 'lodash';\nimport { GerritIntegrationConfig } from './config';\n\nconst GERRIT_BODY_PREFIX = \")]}'\";\n\n/**\n * Parse a Gitiles URL and return branch, file path and project.\n *\n * @remarks\n *\n * Gerrit only handles code reviews so it does not have a native way to browse\n * or showing the content of gits. Image if Github only had the \"pull requests\"\n * tab.\n *\n * Any source code browsing is instead handled by optional services outside\n * Gerrit. The url format chosen for the Gerrit url reader is the one used by\n * the Gitiles project. Gerrit will work perfectly with Backstage without\n * having Gitiles installed but there are some places in the Backstage GUI\n * with links to the url used by the url reader. These will not work unless\n * the urls point to an actual Gitiles installation.\n *\n * Gitiles url:\n * https://g.com/optional_path/\\{project\\}/+/refs/heads/\\{branch\\}/\\{filePath\\}\n * https://g.com/a/optional_path/\\{project\\}/+/refs/heads/\\{branch\\}/\\{filePath\\}\n *\n *\n * @param url - An URL pointing to a file stored in git.\n * @public\n * @deprecated `parseGerritGitilesUrl` is deprecated. Use\n * {@link parseGitilesUrlRef} instead.\n */\nexport function parseGerritGitilesUrl(\n config: GerritIntegrationConfig,\n url: string,\n): { branch: string; filePath: string; project: string } {\n const baseUrlParse = new URL(config.gitilesBaseUrl!);\n const urlParse = new URL(url);\n\n // Remove the gerrit authentication prefix '/a/' from the url\n // In case of the gitilesBaseUrl is https://review.gerrit.com/plugins/gitiles\n // and the url provided is https://review.gerrit.com/a/plugins/gitiles/...\n // remove the prefix only if the pathname start with '/a/'\n const urlPath = urlParse.pathname\n .substring(urlParse.pathname.startsWith('/a/') ? 2 : 0)\n .replace(baseUrlParse.pathname, '');\n\n const parts = urlPath.split('/').filter(p => !!p);\n\n const projectEndIndex = parts.indexOf('+');\n\n if (projectEndIndex <= 0) {\n throw new Error(`Unable to parse project from url: ${url}`);\n }\n const project = trimStart(parts.slice(0, projectEndIndex).join('/'), '/');\n\n const branchIndex = parts.indexOf('heads');\n if (branchIndex <= 0) {\n throw new Error(`Unable to parse branch from url: ${url}`);\n }\n const branch = parts[branchIndex + 1];\n const filePath = parts.slice(branchIndex + 2).join('/');\n\n return {\n branch,\n filePath: filePath === '' ? '/' : filePath,\n project,\n };\n}\n\n/**\n * Parses Gitiles urls and returns the following:\n *\n * - The project\n * - The type of ref. I.e: branch name, SHA, HEAD or tag.\n * - The file path from the repo root.\n * - The base path as the path that points to the repo root.\n *\n * Supported types of gitiles urls that point to:\n *\n * - Branches\n * - Tags\n * - A commit SHA\n * - HEAD\n *\n * @param config - A Gerrit provider config.\n * @param url - An url to a file or folder in Gitiles.\n * @public\n */\nexport function parseGitilesUrlRef(\n config: GerritIntegrationConfig,\n url: string,\n): {\n project: string;\n path: string;\n ref: string;\n refType: 'sha' | 'branch' | 'tag' | 'head';\n basePath: string;\n} {\n const baseUrlParse = new URL(config.gitilesBaseUrl!);\n const urlParse = new URL(url);\n // Remove the gerrit authentication prefix '/a/' from the url\n // In case of the gitilesBaseUrl is https://review.gerrit.com/plugins/gitiles\n // and the url provided is https://review.gerrit.com/a/plugins/gitiles/...\n // remove the prefix only if the pathname start with '/a/'\n const urlPath = trimStart(\n urlParse.pathname\n .substring(urlParse.pathname.startsWith('/a/') ? 2 : 0)\n .replace(baseUrlParse.pathname, ''),\n '/',\n );\n\n // Find the project by taking everything up to \"/+/\".\n const parts = urlPath.split('/').filter(p => !!p);\n const projectParts = takeWhile(parts, p => p !== '+');\n if (projectParts.length === 0) {\n throw new Error(`Unable to parse gitiles url: ${url}`);\n }\n // Also remove the \"+\" after the project.\n const rest = parts.slice(projectParts.length + 1);\n const project = join(projectParts, '/');\n\n // match <project>/+/HEAD/<path>\n if (rest.length > 0 && rest[0] === 'HEAD') {\n const ref = rest.shift()!;\n const path = join(rest, '/');\n return {\n project,\n ref,\n refType: 'head' as const,\n path: path || '/',\n basePath: trimEnd(url.replace(path, ''), '/'),\n };\n }\n // match <project>/+/<sha>/<path>\n if (rest.length > 0 && rest[0].length === 40) {\n const ref = rest.shift()!;\n const path = join(rest, '/');\n return {\n project,\n ref,\n refType: 'sha' as const,\n path: path || '/',\n basePath: trimEnd(url.replace(path, ''), '/'),\n };\n }\n const remainingPath = join(rest, '/');\n // Regexp for matching \"refs/tags/<tag>\" or \"refs/heads/<branch>/\"\n const refsRegexp = /^refs\\/(?<refsReference>heads|tags)\\/(?<ref>.*?)(\\/|$)/;\n const result = refsRegexp.exec(remainingPath);\n if (result) {\n const matchString = result[0];\n let refType;\n const { refsReference, ref } = result.groups || {};\n const path = remainingPath.replace(matchString, '');\n switch (refsReference) {\n case 'heads':\n refType = 'branch' as const;\n break;\n case 'tags':\n refType = 'tag' as const;\n break;\n default:\n throw new Error(`Unable to parse gitiles url: ${url}`);\n }\n return {\n project,\n ref,\n refType,\n path: path || '/',\n basePath: trimEnd(url.replace(path, ''), '/'),\n };\n }\n throw new Error(`Unable to parse gitiles : ${url}`);\n}\n\n/**\n * Build a Gerrit Gitiles url that targets a specific path.\n *\n * @param config - A Gerrit provider config.\n * @param project - The name of the git project\n * @param branch - The branch we will target.\n * @param filePath - The absolute file path.\n * @public\n */\nexport function buildGerritGitilesUrl(\n config: GerritIntegrationConfig,\n project: string,\n branch: string,\n filePath: string,\n): string {\n return `${\n config.gitilesBaseUrl\n }/${project}/+/refs/heads/${branch}/${trimStart(filePath, '/')}`;\n}\n\n/**\n * Build a Gerrit Gitiles archive url that targets a specific branch and path\n *\n * @param config - A Gerrit provider config.\n * @param project - The name of the git project\n * @param branch - The branch we will target.\n * @param filePath - The absolute file path.\n * @public\n * @deprecated `buildGerritGitilesArchiveUrl` is deprecated. Use\n * {@link buildGerritGitilesArchiveUrlFromLocation} instead.\n */\nexport function buildGerritGitilesArchiveUrl(\n config: GerritIntegrationConfig,\n project: string,\n branch: string,\n filePath: string,\n): string {\n const archiveName =\n filePath === '/' || filePath === '' ? '.tar.gz' : `/${filePath}.tar.gz`;\n return `${getGitilesAuthenticationUrl(\n config,\n )}/${project}/+archive/refs/heads/${branch}${archiveName}`;\n}\n\n/**\n * Build a Gerrit Gitiles archive url from a Gitiles url.\n *\n * @param config - A Gerrit provider config.\n * @param url - The gitiles url\n * @public\n */\nexport function buildGerritGitilesArchiveUrlFromLocation(\n config: GerritIntegrationConfig,\n url: string,\n): string {\n const {\n path: filePath,\n ref,\n project,\n refType,\n } = parseGitilesUrlRef(config, url);\n const archiveName =\n filePath === '/' || filePath === '' ? '.tar.gz' : `/${filePath}.tar.gz`;\n if (refType === 'branch') {\n return `${getGitilesAuthenticationUrl(\n config,\n )}/${project}/+archive/refs/heads/${ref}${archiveName}`;\n }\n if (refType === 'sha') {\n return `${getGitilesAuthenticationUrl(\n config,\n )}/${project}/+archive/${ref}${archiveName}`;\n }\n throw new Error(`Unsupported gitiles ref type: ${refType}`);\n}\n\n/**\n * Return the authentication prefix.\n *\n * @remarks\n *\n * To authenticate with a password the API url must be prefixed with \"/a/\".\n * If no password is set anonymous access (without the prefix) will\n * be used.\n *\n * @param config - A Gerrit provider config.\n * @public\n */\nexport function getAuthenticationPrefix(\n config: GerritIntegrationConfig,\n): string {\n return config.password ? '/a/' : '/';\n}\n\n/**\n * Return the authentication gitiles url.\n *\n * @remarks\n *\n * To authenticate with a password the API url must be prefixed with \"/a/\".\n * If no password is set anonymous access (without the prefix) will\n * be used.\n *\n * @param config - A Gerrit provider config.\n */\nexport function getGitilesAuthenticationUrl(\n config: GerritIntegrationConfig,\n): string {\n if (!config.baseUrl || !config.gitilesBaseUrl) {\n throw new Error(\n 'Unexpected Gerrit config values. baseUrl or gitilesBaseUrl not set.',\n );\n }\n if (config.gitilesBaseUrl.startsWith(config.baseUrl)) {\n return config.gitilesBaseUrl.replace(\n config.baseUrl.concat('/'),\n config.baseUrl.concat(getAuthenticationPrefix(config)),\n );\n }\n if (config.password) {\n throw new Error(\n 'Since the baseUrl (Gerrit) is not part of the gitilesBaseUrl, an authentication URL could not be constructed.',\n );\n }\n return config.gitilesBaseUrl!;\n}\n\n/**\n * Return the url to get branch info from the Gerrit API.\n *\n * @param config - A Gerrit provider config.\n * @param url - An url pointing to a file in git.\n * @public\n */\nexport function getGerritBranchApiUrl(\n config: GerritIntegrationConfig,\n url: string,\n) {\n const { branch, project } = parseGerritGitilesUrl(config, url);\n\n return `${config.baseUrl}${getAuthenticationPrefix(\n config,\n )}projects/${encodeURIComponent(project)}/branches/${branch}`;\n}\n\n/**\n * Return the url to clone the repo that is referenced by the url.\n *\n * @param url - An url pointing to a file in git.\n * @public\n */\nexport function getGerritCloneRepoUrl(\n config: GerritIntegrationConfig,\n url: string,\n) {\n const { project } = parseGerritGitilesUrl(config, url);\n\n return `${config.cloneUrl}${getAuthenticationPrefix(config)}${project}`;\n}\n\n/**\n * Return the url to fetch the contents of a file using the Gerrit API.\n *\n * @param config - A Gerrit provider config.\n * @param url - An url pointing to a file in git.\n * @public\n */\nexport function getGerritFileContentsApiUrl(\n config: GerritIntegrationConfig,\n url: string,\n) {\n const { ref, refType, path, project } = parseGitilesUrlRef(config, url);\n\n // https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#get-content\n if (refType === 'branch') {\n return `${config.baseUrl}${getAuthenticationPrefix(\n config,\n )}projects/${encodeURIComponent(\n project,\n )}/branches/${ref}/files/${encodeURIComponent(path)}/content`;\n }\n // https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#get-content-from-commit\n if (refType === 'sha') {\n return `${config.baseUrl}${getAuthenticationPrefix(\n config,\n )}projects/${encodeURIComponent(\n project,\n )}/commits/${ref}/files/${encodeURIComponent(path)}/content`;\n }\n throw new Error(`Unsupported gitiles ref type: ${refType}`);\n}\n\n/**\n * Return the url to query available projects using the Gerrit API.\n *\n * @param config - A Gerrit provider config.\n * @public\n */\nexport function getGerritProjectsApiUrl(config: GerritIntegrationConfig) {\n return `${config.baseUrl}${getAuthenticationPrefix(config)}projects/`;\n}\n\n/**\n * Return request headers for a Gerrit provider.\n *\n * @param config - A Gerrit provider config\n * @public\n */\nexport function getGerritRequestOptions(config: GerritIntegrationConfig): {\n headers?: Record<string, string>;\n} {\n const headers: Record<string, string> = {};\n\n if (!config.password) {\n return headers;\n }\n const buffer = Buffer.from(`${config.username}:${config.password}`, 'utf8');\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n return {\n headers,\n };\n}\n\n/**\n * Parse the json response from Gerrit and strip the magic prefix.\n *\n * @remarks\n *\n * To prevent against XSSI attacks the JSON response body from Gerrit starts\n * with a magic prefix that must be stripped before it can be fed to a JSON\n * parser.\n *\n * @param response - An API response.\n * @public\n */\nexport async function parseGerritJsonResponse(\n response: Response,\n): Promise<unknown> {\n const responseBody = await response.text();\n if (responseBody.startsWith(GERRIT_BODY_PREFIX)) {\n try {\n return JSON.parse(responseBody.slice(GERRIT_BODY_PREFIX.length));\n } catch (ex) {\n throw new Error(\n `Invalid response from Gerrit: ${responseBody.slice(0, 10)} - ${ex}`,\n );\n }\n }\n throw new Error(\n `Gerrit JSON body prefix missing. Found: ${responseBody.slice(0, 10)}`,\n );\n}\n"],"names":["trimStart","takeWhile","join","trimEnd"],"mappings":";;;;AAkBA,MAAM,kBAAqB,GAAA,MAAA;AA4BX,SAAA,qBAAA,CACd,QACA,GACuD,EAAA;AACvD,EAAA,MAAM,YAAe,GAAA,IAAI,GAAI,CAAA,MAAA,CAAO,cAAe,CAAA;AACnD,EAAM,MAAA,QAAA,GAAW,IAAI,GAAA,CAAI,GAAG,CAAA;AAM5B,EAAA,MAAM,OAAU,GAAA,QAAA,CAAS,QACtB,CAAA,SAAA,CAAU,SAAS,QAAS,CAAA,UAAA,CAAW,KAAK,CAAA,GAAI,IAAI,CAAC,CAAA,CACrD,OAAQ,CAAA,YAAA,CAAa,UAAU,EAAE,CAAA;AAEpC,EAAM,MAAA,KAAA,GAAQ,QAAQ,KAAM,CAAA,GAAG,EAAE,MAAO,CAAA,CAAA,CAAA,KAAK,CAAC,CAAC,CAAC,CAAA;AAEhD,EAAM,MAAA,eAAA,GAAkB,KAAM,CAAA,OAAA,CAAQ,GAAG,CAAA;AAEzC,EAAA,IAAI,mBAAmB,CAAG,EAAA;AACxB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAqC,kCAAA,EAAA,GAAG,CAAE,CAAA,CAAA;AAAA;AAE5D,EAAM,MAAA,OAAA,GAAUA,gBAAU,CAAA,KAAA,C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,EAAE,CAAC,CAAA;AAAA,GACtE;AACF;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"core.cjs.js","sources":["../../src/gerrit/core.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\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 { join, takeWhile, trimEnd, trimStart } from 'lodash';\nimport { GerritIntegrationConfig } from './config';\n\nconst GERRIT_BODY_PREFIX = \")]}'\";\n\n/**\n * Parse a Gitiles URL and return branch, file path and project.\n *\n * @remarks\n *\n * Gerrit only handles code reviews so it does not have a native way to browse\n * or showing the content of gits. Image if Github only had the \"pull requests\"\n * tab.\n *\n * Any source code browsing is instead handled by optional services outside\n * Gerrit. The url format chosen for the Gerrit url reader is the one used by\n * the Gitiles project. Gerrit will work perfectly with Backstage without\n * having Gitiles installed but there are some places in the Backstage GUI\n * with links to the url used by the url reader. These will not work unless\n * the urls point to an actual Gitiles installation.\n *\n * Gitiles url:\n * https://g.com/optional_path/\\{project\\}/+/refs/heads/\\{branch\\}/\\{filePath\\}\n * https://g.com/a/optional_path/\\{project\\}/+/refs/heads/\\{branch\\}/\\{filePath\\}\n *\n *\n * @param url - An URL pointing to a file stored in git.\n * @public\n * @deprecated `parseGerritGitilesUrl` is deprecated. Use\n * {@link parseGitilesUrlRef} instead.\n */\nexport function parseGerritGitilesUrl(\n config: GerritIntegrationConfig,\n url: string,\n): { branch: string; filePath: string; project: string } {\n const baseUrlParse = new URL(config.gitilesBaseUrl!);\n const urlParse = new URL(url);\n\n // Remove the gerrit authentication prefix '/a/' from the url\n // In case of the gitilesBaseUrl is https://review.gerrit.com/plugins/gitiles\n // and the url provided is https://review.gerrit.com/a/plugins/gitiles/...\n // remove the prefix only if the pathname start with '/a/'\n const urlPath = urlParse.pathname\n .substring(urlParse.pathname.startsWith('/a/') ? 2 : 0)\n .replace(baseUrlParse.pathname, '');\n\n const parts = urlPath.split('/').filter(p => !!p);\n\n const projectEndIndex = parts.indexOf('+');\n\n if (projectEndIndex <= 0) {\n throw new Error(`Unable to parse project from url: ${url}`);\n }\n const project = trimStart(parts.slice(0, projectEndIndex).join('/'), '/');\n\n const branchIndex = parts.indexOf('heads');\n if (branchIndex <= 0) {\n throw new Error(`Unable to parse branch from url: ${url}`);\n }\n const branch = parts[branchIndex + 1];\n const filePath = parts.slice(branchIndex + 2).join('/');\n\n return {\n branch,\n filePath: filePath === '' ? '/' : filePath,\n project,\n };\n}\n\n/**\n * Parses Gitiles urls and returns the following:\n *\n * - The project\n * - The type of ref. I.e: branch name, SHA, HEAD or tag.\n * - The file path from the repo root.\n * - The base path as the path that points to the repo root.\n *\n * Supported types of gitiles urls that point to:\n *\n * - Branches\n * - Tags\n * - A commit SHA\n * - HEAD\n *\n * @param config - A Gerrit provider config.\n * @param url - An url to a file or folder in Gitiles.\n * @public\n */\nexport function parseGitilesUrlRef(\n config: GerritIntegrationConfig,\n url: string,\n): {\n project: string;\n path: string;\n ref: string;\n refType: 'sha' | 'branch' | 'tag' | 'head';\n basePath: string;\n} {\n const baseUrlParse = new URL(config.gitilesBaseUrl!);\n const urlParse = new URL(url);\n // Remove the gerrit authentication prefix '/a/' from the url\n // In case of the gitilesBaseUrl is https://review.gerrit.com/plugins/gitiles\n // and the url provided is https://review.gerrit.com/a/plugins/gitiles/...\n // remove the prefix only if the pathname start with '/a/'\n const urlPath = trimStart(\n urlParse.pathname\n .substring(urlParse.pathname.startsWith('/a/') ? 2 : 0)\n .replace(baseUrlParse.pathname, ''),\n '/',\n );\n\n // Find the project by taking everything up to \"/+/\".\n const parts = urlPath.split('/').filter(p => !!p);\n const projectParts = takeWhile(parts, p => p !== '+');\n if (projectParts.length === 0) {\n throw new Error(`Unable to parse gitiles url: ${url}`);\n }\n // Also remove the \"+\" after the project.\n const rest = parts.slice(projectParts.length + 1);\n const project = join(projectParts, '/');\n\n // match <project>/+/HEAD/<path>\n if (rest.length > 0 && rest[0] === 'HEAD') {\n const ref = rest.shift()!;\n const path = join(rest, '/');\n return {\n project,\n ref,\n refType: 'head' as const,\n path: path || '/',\n basePath: trimEnd(url.replace(path, ''), '/'),\n };\n }\n // match <project>/+/<sha>/<path>\n if (rest.length > 0 && rest[0].length === 40) {\n const ref = rest.shift()!;\n const path = join(rest, '/');\n return {\n project,\n ref,\n refType: 'sha' as const,\n path: path || '/',\n basePath: trimEnd(url.replace(path, ''), '/'),\n };\n }\n const remainingPath = join(rest, '/');\n // Regexp for matching \"refs/tags/<tag>\" or \"refs/heads/<branch>/\"\n const refsRegexp = /^refs\\/(?<refsReference>heads|tags)\\/(?<ref>.*?)(\\/|$)/;\n const result = refsRegexp.exec(remainingPath);\n if (result) {\n const matchString = result[0];\n let refType;\n const { refsReference, ref } = result.groups || {};\n const path = remainingPath.replace(matchString, '');\n switch (refsReference) {\n case 'heads':\n refType = 'branch' as const;\n break;\n case 'tags':\n refType = 'tag' as const;\n break;\n default:\n throw new Error(`Unable to parse gitiles url: ${url}`);\n }\n return {\n project,\n ref,\n refType,\n path: path || '/',\n basePath: trimEnd(url.replace(path, ''), '/'),\n };\n }\n throw new Error(`Unable to parse gitiles : ${url}`);\n}\n\n/**\n * Build a Gerrit Gitiles url that targets a specific path.\n *\n * @param config - A Gerrit provider config.\n * @param project - The name of the git project\n * @param branch - The branch we will target.\n * @param filePath - The absolute file path.\n * @public\n */\nexport function buildGerritGitilesUrl(\n config: GerritIntegrationConfig,\n project: string,\n branch: string,\n filePath: string,\n): string {\n return `${\n config.gitilesBaseUrl\n }/${project}/+/refs/heads/${branch}/${trimStart(filePath, '/')}`;\n}\n\n/**\n * Build a Gerrit Gitiles archive url that targets a specific branch and path\n *\n * @param config - A Gerrit provider config.\n * @param project - The name of the git project\n * @param branch - The branch we will target.\n * @param filePath - The absolute file path.\n * @public\n * @deprecated `buildGerritGitilesArchiveUrl` is deprecated. Use\n * {@link buildGerritGitilesArchiveUrlFromLocation} instead.\n */\nexport function buildGerritGitilesArchiveUrl(\n config: GerritIntegrationConfig,\n project: string,\n branch: string,\n filePath: string,\n): string {\n const archiveName =\n filePath === '/' || filePath === '' ? '.tar.gz' : `/${filePath}.tar.gz`;\n return `${getGitilesAuthenticationUrl(\n config,\n )}/${project}/+archive/refs/heads/${branch}${archiveName}`;\n}\n\n/**\n * Build a Gerrit Gitiles archive url from a Gitiles url.\n *\n * @param config - A Gerrit provider config.\n * @param url - The gitiles url\n * @public\n */\nexport function buildGerritGitilesArchiveUrlFromLocation(\n config: GerritIntegrationConfig,\n url: string,\n): string {\n const {\n path: filePath,\n ref,\n project,\n refType,\n } = parseGitilesUrlRef(config, url);\n const archiveName =\n filePath === '/' || filePath === '' ? '.tar.gz' : `/${filePath}.tar.gz`;\n if (refType === 'branch') {\n return `${getGitilesAuthenticationUrl(\n config,\n )}/${project}/+archive/refs/heads/${ref}${archiveName}`;\n }\n if (refType === 'sha') {\n return `${getGitilesAuthenticationUrl(\n config,\n )}/${project}/+archive/${ref}${archiveName}`;\n }\n throw new Error(`Unsupported gitiles ref type: ${refType}`);\n}\n\n/**\n * Return the authentication prefix.\n *\n * @remarks\n *\n * To authenticate with a password the API url must be prefixed with \"/a/\".\n * If no password is set anonymous access (without the prefix) will\n * be used.\n *\n * @param config - A Gerrit provider config.\n * @public\n */\nexport function getAuthenticationPrefix(\n config: GerritIntegrationConfig,\n): string {\n return config.password ? '/a/' : '/';\n}\n\n/**\n * Return the authentication gitiles url.\n *\n * @remarks\n *\n * To authenticate with a password the API url must be prefixed with \"/a/\".\n * If no password is set anonymous access (without the prefix) will\n * be used.\n *\n * @param config - A Gerrit provider config.\n * @public\n */\nexport function getGitilesAuthenticationUrl(\n config: GerritIntegrationConfig,\n): string {\n if (!config.baseUrl || !config.gitilesBaseUrl) {\n throw new Error(\n 'Unexpected Gerrit config values. baseUrl or gitilesBaseUrl not set.',\n );\n }\n if (config.gitilesBaseUrl.startsWith(config.baseUrl)) {\n return config.gitilesBaseUrl.replace(\n config.baseUrl.concat('/'),\n config.baseUrl.concat(getAuthenticationPrefix(config)),\n );\n }\n if (config.password) {\n throw new Error(\n 'Since the baseUrl (Gerrit) is not part of the gitilesBaseUrl, an authentication URL could not be constructed.',\n );\n }\n return config.gitilesBaseUrl!;\n}\n\n/**\n * Return the url to get branch info from the Gerrit API.\n *\n * @param config - A Gerrit provider config.\n * @param url - An url pointing to a file in git.\n * @public\n */\nexport function getGerritBranchApiUrl(\n config: GerritIntegrationConfig,\n url: string,\n) {\n const { branch, project } = parseGerritGitilesUrl(config, url);\n\n return `${config.baseUrl}${getAuthenticationPrefix(\n config,\n )}projects/${encodeURIComponent(project)}/branches/${branch}`;\n}\n\n/**\n * Return the url to clone the repo that is referenced by the url.\n *\n * @param url - An url pointing to a file in git.\n * @public\n */\nexport function getGerritCloneRepoUrl(\n config: GerritIntegrationConfig,\n url: string,\n) {\n const { project } = parseGerritGitilesUrl(config, url);\n\n return `${config.cloneUrl}${getAuthenticationPrefix(config)}${project}`;\n}\n\n/**\n * Return the url to fetch the contents of a file using the Gerrit API.\n *\n * @param config - A Gerrit provider config.\n * @param url - An url pointing to a file in git.\n * @public\n */\nexport function getGerritFileContentsApiUrl(\n config: GerritIntegrationConfig,\n url: string,\n) {\n const { ref, refType, path, project } = parseGitilesUrlRef(config, url);\n\n // https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#get-content\n if (refType === 'branch') {\n return `${config.baseUrl}${getAuthenticationPrefix(\n config,\n )}projects/${encodeURIComponent(\n project,\n )}/branches/${ref}/files/${encodeURIComponent(path)}/content`;\n }\n // https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#get-content-from-commit\n if (refType === 'sha') {\n return `${config.baseUrl}${getAuthenticationPrefix(\n config,\n )}projects/${encodeURIComponent(\n project,\n )}/commits/${ref}/files/${encodeURIComponent(path)}/content`;\n }\n throw new Error(`Unsupported gitiles ref type: ${refType}`);\n}\n\n/**\n * Return the url to query available projects using the Gerrit API.\n *\n * @param config - A Gerrit provider config.\n * @public\n */\nexport function getGerritProjectsApiUrl(config: GerritIntegrationConfig) {\n return `${config.baseUrl}${getAuthenticationPrefix(config)}projects/`;\n}\n\n/**\n * Return request headers for a Gerrit provider.\n *\n * @param config - A Gerrit provider config\n * @public\n */\nexport function getGerritRequestOptions(config: GerritIntegrationConfig): {\n headers?: Record<string, string>;\n} {\n const headers: Record<string, string> = {};\n\n if (!config.password) {\n return headers;\n }\n const buffer = Buffer.from(`${config.username}:${config.password}`, 'utf8');\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n return {\n headers,\n };\n}\n\n/**\n * Parse the json response from Gerrit and strip the magic prefix.\n *\n * @remarks\n *\n * To prevent against XSSI attacks the JSON response body from Gerrit starts\n * with a magic prefix that must be stripped before it can be fed to a JSON\n * parser.\n *\n * @param response - An API response.\n * @public\n */\nexport async function parseGerritJsonResponse(\n response: Response,\n): Promise<unknown> {\n const responseBody = await response.text();\n if (responseBody.startsWith(GERRIT_BODY_PREFIX)) {\n try {\n return JSON.parse(responseBody.slice(GERRIT_BODY_PREFIX.length));\n } catch (ex) {\n throw new Error(\n `Invalid response from Gerrit: ${responseBody.slice(0, 10)} - ${ex}`,\n );\n }\n }\n throw new Error(\n `Gerrit JSON body prefix missing. Found: ${responseBody.slice(0, 10)}`,\n );\n}\n"],"names":["trimStart","takeWhile","join","trimEnd"],"mappings":";;;;AAkBA,MAAM,kBAAqB,GAAA,MAAA;AA4BX,SAAA,qBAAA,CACd,QACA,GACuD,EAAA;AACvD,EAAA,MAAM,YAAe,GAAA,IAAI,GAAI,CAAA,MAAA,CAAO,cAAe,CAAA;AACnD,EAAM,MAAA,QAAA,GAAW,IAAI,GAAA,CAAI,GAAG,CAAA;AAM5B,EAAA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IACL;AAAA,GACF;AACF;AAcA,eAAsB,wBACpB,QACkB,EAAA;AAClB,EAAM,MAAA,YAAA,GAAe,MAAM,QAAA,CAAS,IAAK,EAAA;AACzC,EAAI,IAAA,YAAA,CAAa,UAAW,CAAA,kBAAkB,CAAG,EAAA;AAC/C,IAAI,IAAA;AACF,MAAA,OAAO,KAAK,KAAM,CAAA,YAAA,CAAa,KAAM,CAAA,kBAAA,CAAmB,MAAM,CAAC,CAAA;AAAA,aACxD,EAAI,EAAA;AACX,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,iCAAiC,YAAa,CAAA,KAAA,CAAM,GAAG,EAAE,CAAC,MAAM,EAAE,CAAA;AAAA,OACpE;AAAA;AACF;AAEF,EAAA,MAAM,IAAI,KAAA;AAAA,IACR,CAA2C,wCAAA,EAAA,YAAA,CAAa,KAAM,CAAA,CAAA,EAAG,EAAE,CAAC,CAAA;AAAA,GACtE;AACF;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.esm.js","sources":["../../src/gerrit/core.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\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 { join, takeWhile, trimEnd, trimStart } from 'lodash';\nimport { GerritIntegrationConfig } from './config';\n\nconst GERRIT_BODY_PREFIX = \")]}'\";\n\n/**\n * Parse a Gitiles URL and return branch, file path and project.\n *\n * @remarks\n *\n * Gerrit only handles code reviews so it does not have a native way to browse\n * or showing the content of gits. Image if Github only had the \"pull requests\"\n * tab.\n *\n * Any source code browsing is instead handled by optional services outside\n * Gerrit. The url format chosen for the Gerrit url reader is the one used by\n * the Gitiles project. Gerrit will work perfectly with Backstage without\n * having Gitiles installed but there are some places in the Backstage GUI\n * with links to the url used by the url reader. These will not work unless\n * the urls point to an actual Gitiles installation.\n *\n * Gitiles url:\n * https://g.com/optional_path/\\{project\\}/+/refs/heads/\\{branch\\}/\\{filePath\\}\n * https://g.com/a/optional_path/\\{project\\}/+/refs/heads/\\{branch\\}/\\{filePath\\}\n *\n *\n * @param url - An URL pointing to a file stored in git.\n * @public\n * @deprecated `parseGerritGitilesUrl` is deprecated. Use\n * {@link parseGitilesUrlRef} instead.\n */\nexport function parseGerritGitilesUrl(\n config: GerritIntegrationConfig,\n url: string,\n): { branch: string; filePath: string; project: string } {\n const baseUrlParse = new URL(config.gitilesBaseUrl!);\n const urlParse = new URL(url);\n\n // Remove the gerrit authentication prefix '/a/' from the url\n // In case of the gitilesBaseUrl is https://review.gerrit.com/plugins/gitiles\n // and the url provided is https://review.gerrit.com/a/plugins/gitiles/...\n // remove the prefix only if the pathname start with '/a/'\n const urlPath = urlParse.pathname\n .substring(urlParse.pathname.startsWith('/a/') ? 2 : 0)\n .replace(baseUrlParse.pathname, '');\n\n const parts = urlPath.split('/').filter(p => !!p);\n\n const projectEndIndex = parts.indexOf('+');\n\n if (projectEndIndex <= 0) {\n throw new Error(`Unable to parse project from url: ${url}`);\n }\n const project = trimStart(parts.slice(0, projectEndIndex).join('/'), '/');\n\n const branchIndex = parts.indexOf('heads');\n if (branchIndex <= 0) {\n throw new Error(`Unable to parse branch from url: ${url}`);\n }\n const branch = parts[branchIndex + 1];\n const filePath = parts.slice(branchIndex + 2).join('/');\n\n return {\n branch,\n filePath: filePath === '' ? '/' : filePath,\n project,\n };\n}\n\n/**\n * Parses Gitiles urls and returns the following:\n *\n * - The project\n * - The type of ref. I.e: branch name, SHA, HEAD or tag.\n * - The file path from the repo root.\n * - The base path as the path that points to the repo root.\n *\n * Supported types of gitiles urls that point to:\n *\n * - Branches\n * - Tags\n * - A commit SHA\n * - HEAD\n *\n * @param config - A Gerrit provider config.\n * @param url - An url to a file or folder in Gitiles.\n * @public\n */\nexport function parseGitilesUrlRef(\n config: GerritIntegrationConfig,\n url: string,\n): {\n project: string;\n path: string;\n ref: string;\n refType: 'sha' | 'branch' | 'tag' | 'head';\n basePath: string;\n} {\n const baseUrlParse = new URL(config.gitilesBaseUrl!);\n const urlParse = new URL(url);\n // Remove the gerrit authentication prefix '/a/' from the url\n // In case of the gitilesBaseUrl is https://review.gerrit.com/plugins/gitiles\n // and the url provided is https://review.gerrit.com/a/plugins/gitiles/...\n // remove the prefix only if the pathname start with '/a/'\n const urlPath = trimStart(\n urlParse.pathname\n .substring(urlParse.pathname.startsWith('/a/') ? 2 : 0)\n .replace(baseUrlParse.pathname, ''),\n '/',\n );\n\n // Find the project by taking everything up to \"/+/\".\n const parts = urlPath.split('/').filter(p => !!p);\n const projectParts = takeWhile(parts, p => p !== '+');\n if (projectParts.length === 0) {\n throw new Error(`Unable to parse gitiles url: ${url}`);\n }\n // Also remove the \"+\" after the project.\n const rest = parts.slice(projectParts.length + 1);\n const project = join(projectParts, '/');\n\n // match <project>/+/HEAD/<path>\n if (rest.length > 0 && rest[0] === 'HEAD') {\n const ref = rest.shift()!;\n const path = join(rest, '/');\n return {\n project,\n ref,\n refType: 'head' as const,\n path: path || '/',\n basePath: trimEnd(url.replace(path, ''), '/'),\n };\n }\n // match <project>/+/<sha>/<path>\n if (rest.length > 0 && rest[0].length === 40) {\n const ref = rest.shift()!;\n const path = join(rest, '/');\n return {\n project,\n ref,\n refType: 'sha' as const,\n path: path || '/',\n basePath: trimEnd(url.replace(path, ''), '/'),\n };\n }\n const remainingPath = join(rest, '/');\n // Regexp for matching \"refs/tags/<tag>\" or \"refs/heads/<branch>/\"\n const refsRegexp = /^refs\\/(?<refsReference>heads|tags)\\/(?<ref>.*?)(\\/|$)/;\n const result = refsRegexp.exec(remainingPath);\n if (result) {\n const matchString = result[0];\n let refType;\n const { refsReference, ref } = result.groups || {};\n const path = remainingPath.replace(matchString, '');\n switch (refsReference) {\n case 'heads':\n refType = 'branch' as const;\n break;\n case 'tags':\n refType = 'tag' as const;\n break;\n default:\n throw new Error(`Unable to parse gitiles url: ${url}`);\n }\n return {\n project,\n ref,\n refType,\n path: path || '/',\n basePath: trimEnd(url.replace(path, ''), '/'),\n };\n }\n throw new Error(`Unable to parse gitiles : ${url}`);\n}\n\n/**\n * Build a Gerrit Gitiles url that targets a specific path.\n *\n * @param config - A Gerrit provider config.\n * @param project - The name of the git project\n * @param branch - The branch we will target.\n * @param filePath - The absolute file path.\n * @public\n */\nexport function buildGerritGitilesUrl(\n config: GerritIntegrationConfig,\n project: string,\n branch: string,\n filePath: string,\n): string {\n return `${\n config.gitilesBaseUrl\n }/${project}/+/refs/heads/${branch}/${trimStart(filePath, '/')}`;\n}\n\n/**\n * Build a Gerrit Gitiles archive url that targets a specific branch and path\n *\n * @param config - A Gerrit provider config.\n * @param project - The name of the git project\n * @param branch - The branch we will target.\n * @param filePath - The absolute file path.\n * @public\n * @deprecated `buildGerritGitilesArchiveUrl` is deprecated. Use\n * {@link buildGerritGitilesArchiveUrlFromLocation} instead.\n */\nexport function buildGerritGitilesArchiveUrl(\n config: GerritIntegrationConfig,\n project: string,\n branch: string,\n filePath: string,\n): string {\n const archiveName =\n filePath === '/' || filePath === '' ? '.tar.gz' : `/${filePath}.tar.gz`;\n return `${getGitilesAuthenticationUrl(\n config,\n )}/${project}/+archive/refs/heads/${branch}${archiveName}`;\n}\n\n/**\n * Build a Gerrit Gitiles archive url from a Gitiles url.\n *\n * @param config - A Gerrit provider config.\n * @param url - The gitiles url\n * @public\n */\nexport function buildGerritGitilesArchiveUrlFromLocation(\n config: GerritIntegrationConfig,\n url: string,\n): string {\n const {\n path: filePath,\n ref,\n project,\n refType,\n } = parseGitilesUrlRef(config, url);\n const archiveName =\n filePath === '/' || filePath === '' ? '.tar.gz' : `/${filePath}.tar.gz`;\n if (refType === 'branch') {\n return `${getGitilesAuthenticationUrl(\n config,\n )}/${project}/+archive/refs/heads/${ref}${archiveName}`;\n }\n if (refType === 'sha') {\n return `${getGitilesAuthenticationUrl(\n config,\n )}/${project}/+archive/${ref}${archiveName}`;\n }\n throw new Error(`Unsupported gitiles ref type: ${refType}`);\n}\n\n/**\n * Return the authentication prefix.\n *\n * @remarks\n *\n * To authenticate with a password the API url must be prefixed with \"/a/\".\n * If no password is set anonymous access (without the prefix) will\n * be used.\n *\n * @param config - A Gerrit provider config.\n * @public\n */\nexport function getAuthenticationPrefix(\n config: GerritIntegrationConfig,\n): string {\n return config.password ? '/a/' : '/';\n}\n\n/**\n * Return the authentication gitiles url.\n *\n * @remarks\n *\n * To authenticate with a password the API url must be prefixed with \"/a/\".\n * If no password is set anonymous access (without the prefix) will\n * be used.\n *\n * @param config - A Gerrit provider config.\n */\nexport function getGitilesAuthenticationUrl(\n config: GerritIntegrationConfig,\n): string {\n if (!config.baseUrl || !config.gitilesBaseUrl) {\n throw new Error(\n 'Unexpected Gerrit config values. baseUrl or gitilesBaseUrl not set.',\n );\n }\n if (config.gitilesBaseUrl.startsWith(config.baseUrl)) {\n return config.gitilesBaseUrl.replace(\n config.baseUrl.concat('/'),\n config.baseUrl.concat(getAuthenticationPrefix(config)),\n );\n }\n if (config.password) {\n throw new Error(\n 'Since the baseUrl (Gerrit) is not part of the gitilesBaseUrl, an authentication URL could not be constructed.',\n );\n }\n return config.gitilesBaseUrl!;\n}\n\n/**\n * Return the url to get branch info from the Gerrit API.\n *\n * @param config - A Gerrit provider config.\n * @param url - An url pointing to a file in git.\n * @public\n */\nexport function getGerritBranchApiUrl(\n config: GerritIntegrationConfig,\n url: string,\n) {\n const { branch, project } = parseGerritGitilesUrl(config, url);\n\n return `${config.baseUrl}${getAuthenticationPrefix(\n config,\n )}projects/${encodeURIComponent(project)}/branches/${branch}`;\n}\n\n/**\n * Return the url to clone the repo that is referenced by the url.\n *\n * @param url - An url pointing to a file in git.\n * @public\n */\nexport function getGerritCloneRepoUrl(\n config: GerritIntegrationConfig,\n url: string,\n) {\n const { project } = parseGerritGitilesUrl(config, url);\n\n return `${config.cloneUrl}${getAuthenticationPrefix(config)}${project}`;\n}\n\n/**\n * Return the url to fetch the contents of a file using the Gerrit API.\n *\n * @param config - A Gerrit provider config.\n * @param url - An url pointing to a file in git.\n * @public\n */\nexport function getGerritFileContentsApiUrl(\n config: GerritIntegrationConfig,\n url: string,\n) {\n const { ref, refType, path, project } = parseGitilesUrlRef(config, url);\n\n // https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#get-content\n if (refType === 'branch') {\n return `${config.baseUrl}${getAuthenticationPrefix(\n config,\n )}projects/${encodeURIComponent(\n project,\n )}/branches/${ref}/files/${encodeURIComponent(path)}/content`;\n }\n // https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#get-content-from-commit\n if (refType === 'sha') {\n return `${config.baseUrl}${getAuthenticationPrefix(\n config,\n )}projects/${encodeURIComponent(\n project,\n )}/commits/${ref}/files/${encodeURIComponent(path)}/content`;\n }\n throw new Error(`Unsupported gitiles ref type: ${refType}`);\n}\n\n/**\n * Return the url to query available projects using the Gerrit API.\n *\n * @param config - A Gerrit provider config.\n * @public\n */\nexport function getGerritProjectsApiUrl(config: GerritIntegrationConfig) {\n return `${config.baseUrl}${getAuthenticationPrefix(config)}projects/`;\n}\n\n/**\n * Return request headers for a Gerrit provider.\n *\n * @param config - A Gerrit provider config\n * @public\n */\nexport function getGerritRequestOptions(config: GerritIntegrationConfig): {\n headers?: Record<string, string>;\n} {\n const headers: Record<string, string> = {};\n\n if (!config.password) {\n return headers;\n }\n const buffer = Buffer.from(`${config.username}:${config.password}`, 'utf8');\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n return {\n headers,\n };\n}\n\n/**\n * Parse the json response from Gerrit and strip the magic prefix.\n *\n * @remarks\n *\n * To prevent against XSSI attacks the JSON response body from Gerrit starts\n * with a magic prefix that must be stripped before it can be fed to a JSON\n * parser.\n *\n * @param response - An API response.\n * @public\n */\nexport async function parseGerritJsonResponse(\n response: Response,\n): Promise<unknown> {\n const responseBody = await response.text();\n if (responseBody.startsWith(GERRIT_BODY_PREFIX)) {\n try {\n return JSON.parse(responseBody.slice(GERRIT_BODY_PREFIX.length));\n } catch (ex) {\n throw new Error(\n `Invalid response from Gerrit: ${responseBody.slice(0, 10)} - ${ex}`,\n );\n }\n }\n throw new Error(\n `Gerrit JSON body prefix missing. Found: ${responseBody.slice(0, 10)}`,\n );\n}\n"],"names":[],"mappings":";;AAkBA,MAAM,kBAAqB,GAAA,MAAA;AA4BX,SAAA,qBAAA,CACd,QACA,GACuD,EAAA;AACvD,EAAA,MAAM,YAAe,GAAA,IAAI,GAAI,CAAA,MAAA,CAAO,cAAe,CAAA;AACnD,EAAM,MAAA,QAAA,GAAW,IAAI,GAAA,CAAI,GAAG,CAAA;AAM5B,EAAA,MAAM,OAAU,GAAA,QAAA,CAAS,QACtB,CAAA,SAAA,CAAU,SAAS,QAAS,CAAA,UAAA,CAAW,KAAK,CAAA,GAAI,IAAI,CAAC,CAAA,CACrD,OAAQ,CAAA,YAAA,CAAa,UAAU,EAAE,CAAA;AAEpC,EAAM,MAAA,KAAA,GAAQ,QAAQ,KAAM,CAAA,GAAG,EAAE,MAAO,CAAA,CAAA,CAAA,KAAK,CAAC,CAAC,CAAC,CAAA;AAEhD,EAAM,MAAA,eAAA,GAAkB,KAAM,CAAA,OAAA,CAAQ,GAAG,CAAA;AAEzC,EAAA,IAAI,mBAAmB,CAAG,EAAA;AACxB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAqC,kCAAA,EAAA,GAAG,CAAE,CAAA,CAAA;AAAA;AAE5D,EAAM,MAAA,OAAA,GAAU,SAAU,CAAA,KAAA,CAAM,KAAM,CAAA,CAAA,EAAG,eAAe,CAAE,CAAA,IAAA,CAAK,GAAG,CAAA,EAAG,GAAG,CAAA;AAExE,EAAM,MAAA,WAAA,GAAc,KAAM,CAAA,OAAA,CAAQ,OAAO,CAAA;AACzC,EAAA,I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O,GAAG,MAAO,CAAA,OAAO,CAAG,EAAA,uBAAA,CAAwB,MAAM,CAAC,CAAA,SAAA,CAAA;AAC5D;AAQO,SAAS,wBAAwB,MAEtC,EAAA;AACA,EAAA,MAAM,UAAkC,EAAC;AAEzC,EAAI,IAAA,CAAC,OAAO,QAAU,EAAA;AACpB,IAAO,OAAA,OAAA;AAAA;AAET,EAAM,MAAA,MAAA,GAAS,MAAO,CAAA,IAAA,CAAK,CAAG,EAAA,MAAA,CAAO,QAAQ,CAAI,CAAA,EAAA,MAAA,CAAO,QAAQ,CAAA,CAAA,EAAI,MAAM,CAAA;AAC1E,EAAA,OAAA,CAAQ,aAAgB,GAAA,CAAA,MAAA,EAAS,MAAO,CAAA,QAAA,CAAS,QAAQ,CAAC,CAAA,CAAA;AAC1D,EAAO,OAAA;AAAA,IACL;AAAA,GACF;AACF;AAcA,eAAsB,wBACpB,QACkB,EAAA;AAClB,EAAM,MAAA,YAAA,GAAe,MAAM,QAAA,CAAS,IAAK,EAAA;AACzC,EAAI,IAAA,YAAA,CAAa,UAAW,CAAA,kBAAkB,CAAG,EAAA;AAC/C,IAAI,IAAA;AACF,MAAA,OAAO,KAAK,KAAM,CAAA,YAAA,CAAa,KAAM,CAAA,kBAAA,CAAmB,MAAM,CAAC,CAAA;AAAA,aACxD,EAAI,EAAA;AACX,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,iCAAiC,YAAa,CAAA,KAAA,CAAM,GAAG,EAAE,CAAC,MAAM,EAAE,CAAA;AAAA,OACpE;AAAA;AACF;AAEF,EAAA,MAAM,IAAI,KAAA;AAAA,IACR,CAA2C,wCAAA,EAAA,YAAA,CAAa,KAAM,CAAA,CAAA,EAAG,EAAE,CAAC,CAAA;AAAA,GACtE;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"core.esm.js","sources":["../../src/gerrit/core.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\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 { join, takeWhile, trimEnd, trimStart } from 'lodash';\nimport { GerritIntegrationConfig } from './config';\n\nconst GERRIT_BODY_PREFIX = \")]}'\";\n\n/**\n * Parse a Gitiles URL and return branch, file path and project.\n *\n * @remarks\n *\n * Gerrit only handles code reviews so it does not have a native way to browse\n * or showing the content of gits. Image if Github only had the \"pull requests\"\n * tab.\n *\n * Any source code browsing is instead handled by optional services outside\n * Gerrit. The url format chosen for the Gerrit url reader is the one used by\n * the Gitiles project. Gerrit will work perfectly with Backstage without\n * having Gitiles installed but there are some places in the Backstage GUI\n * with links to the url used by the url reader. These will not work unless\n * the urls point to an actual Gitiles installation.\n *\n * Gitiles url:\n * https://g.com/optional_path/\\{project\\}/+/refs/heads/\\{branch\\}/\\{filePath\\}\n * https://g.com/a/optional_path/\\{project\\}/+/refs/heads/\\{branch\\}/\\{filePath\\}\n *\n *\n * @param url - An URL pointing to a file stored in git.\n * @public\n * @deprecated `parseGerritGitilesUrl` is deprecated. Use\n * {@link parseGitilesUrlRef} instead.\n */\nexport function parseGerritGitilesUrl(\n config: GerritIntegrationConfig,\n url: string,\n): { branch: string; filePath: string; project: string } {\n const baseUrlParse = new URL(config.gitilesBaseUrl!);\n const urlParse = new URL(url);\n\n // Remove the gerrit authentication prefix '/a/' from the url\n // In case of the gitilesBaseUrl is https://review.gerrit.com/plugins/gitiles\n // and the url provided is https://review.gerrit.com/a/plugins/gitiles/...\n // remove the prefix only if the pathname start with '/a/'\n const urlPath = urlParse.pathname\n .substring(urlParse.pathname.startsWith('/a/') ? 2 : 0)\n .replace(baseUrlParse.pathname, '');\n\n const parts = urlPath.split('/').filter(p => !!p);\n\n const projectEndIndex = parts.indexOf('+');\n\n if (projectEndIndex <= 0) {\n throw new Error(`Unable to parse project from url: ${url}`);\n }\n const project = trimStart(parts.slice(0, projectEndIndex).join('/'), '/');\n\n const branchIndex = parts.indexOf('heads');\n if (branchIndex <= 0) {\n throw new Error(`Unable to parse branch from url: ${url}`);\n }\n const branch = parts[branchIndex + 1];\n const filePath = parts.slice(branchIndex + 2).join('/');\n\n return {\n branch,\n filePath: filePath === '' ? '/' : filePath,\n project,\n };\n}\n\n/**\n * Parses Gitiles urls and returns the following:\n *\n * - The project\n * - The type of ref. I.e: branch name, SHA, HEAD or tag.\n * - The file path from the repo root.\n * - The base path as the path that points to the repo root.\n *\n * Supported types of gitiles urls that point to:\n *\n * - Branches\n * - Tags\n * - A commit SHA\n * - HEAD\n *\n * @param config - A Gerrit provider config.\n * @param url - An url to a file or folder in Gitiles.\n * @public\n */\nexport function parseGitilesUrlRef(\n config: GerritIntegrationConfig,\n url: string,\n): {\n project: string;\n path: string;\n ref: string;\n refType: 'sha' | 'branch' | 'tag' | 'head';\n basePath: string;\n} {\n const baseUrlParse = new URL(config.gitilesBaseUrl!);\n const urlParse = new URL(url);\n // Remove the gerrit authentication prefix '/a/' from the url\n // In case of the gitilesBaseUrl is https://review.gerrit.com/plugins/gitiles\n // and the url provided is https://review.gerrit.com/a/plugins/gitiles/...\n // remove the prefix only if the pathname start with '/a/'\n const urlPath = trimStart(\n urlParse.pathname\n .substring(urlParse.pathname.startsWith('/a/') ? 2 : 0)\n .replace(baseUrlParse.pathname, ''),\n '/',\n );\n\n // Find the project by taking everything up to \"/+/\".\n const parts = urlPath.split('/').filter(p => !!p);\n const projectParts = takeWhile(parts, p => p !== '+');\n if (projectParts.length === 0) {\n throw new Error(`Unable to parse gitiles url: ${url}`);\n }\n // Also remove the \"+\" after the project.\n const rest = parts.slice(projectParts.length + 1);\n const project = join(projectParts, '/');\n\n // match <project>/+/HEAD/<path>\n if (rest.length > 0 && rest[0] === 'HEAD') {\n const ref = rest.shift()!;\n const path = join(rest, '/');\n return {\n project,\n ref,\n refType: 'head' as const,\n path: path || '/',\n basePath: trimEnd(url.replace(path, ''), '/'),\n };\n }\n // match <project>/+/<sha>/<path>\n if (rest.length > 0 && rest[0].length === 40) {\n const ref = rest.shift()!;\n const path = join(rest, '/');\n return {\n project,\n ref,\n refType: 'sha' as const,\n path: path || '/',\n basePath: trimEnd(url.replace(path, ''), '/'),\n };\n }\n const remainingPath = join(rest, '/');\n // Regexp for matching \"refs/tags/<tag>\" or \"refs/heads/<branch>/\"\n const refsRegexp = /^refs\\/(?<refsReference>heads|tags)\\/(?<ref>.*?)(\\/|$)/;\n const result = refsRegexp.exec(remainingPath);\n if (result) {\n const matchString = result[0];\n let refType;\n const { refsReference, ref } = result.groups || {};\n const path = remainingPath.replace(matchString, '');\n switch (refsReference) {\n case 'heads':\n refType = 'branch' as const;\n break;\n case 'tags':\n refType = 'tag' as const;\n break;\n default:\n throw new Error(`Unable to parse gitiles url: ${url}`);\n }\n return {\n project,\n ref,\n refType,\n path: path || '/',\n basePath: trimEnd(url.replace(path, ''), '/'),\n };\n }\n throw new Error(`Unable to parse gitiles : ${url}`);\n}\n\n/**\n * Build a Gerrit Gitiles url that targets a specific path.\n *\n * @param config - A Gerrit provider config.\n * @param project - The name of the git project\n * @param branch - The branch we will target.\n * @param filePath - The absolute file path.\n * @public\n */\nexport function buildGerritGitilesUrl(\n config: GerritIntegrationConfig,\n project: string,\n branch: string,\n filePath: string,\n): string {\n return `${\n config.gitilesBaseUrl\n }/${project}/+/refs/heads/${branch}/${trimStart(filePath, '/')}`;\n}\n\n/**\n * Build a Gerrit Gitiles archive url that targets a specific branch and path\n *\n * @param config - A Gerrit provider config.\n * @param project - The name of the git project\n * @param branch - The branch we will target.\n * @param filePath - The absolute file path.\n * @public\n * @deprecated `buildGerritGitilesArchiveUrl` is deprecated. Use\n * {@link buildGerritGitilesArchiveUrlFromLocation} instead.\n */\nexport function buildGerritGitilesArchiveUrl(\n config: GerritIntegrationConfig,\n project: string,\n branch: string,\n filePath: string,\n): string {\n const archiveName =\n filePath === '/' || filePath === '' ? '.tar.gz' : `/${filePath}.tar.gz`;\n return `${getGitilesAuthenticationUrl(\n config,\n )}/${project}/+archive/refs/heads/${branch}${archiveName}`;\n}\n\n/**\n * Build a Gerrit Gitiles archive url from a Gitiles url.\n *\n * @param config - A Gerrit provider config.\n * @param url - The gitiles url\n * @public\n */\nexport function buildGerritGitilesArchiveUrlFromLocation(\n config: GerritIntegrationConfig,\n url: string,\n): string {\n const {\n path: filePath,\n ref,\n project,\n refType,\n } = parseGitilesUrlRef(config, url);\n const archiveName =\n filePath === '/' || filePath === '' ? '.tar.gz' : `/${filePath}.tar.gz`;\n if (refType === 'branch') {\n return `${getGitilesAuthenticationUrl(\n config,\n )}/${project}/+archive/refs/heads/${ref}${archiveName}`;\n }\n if (refType === 'sha') {\n return `${getGitilesAuthenticationUrl(\n config,\n )}/${project}/+archive/${ref}${archiveName}`;\n }\n throw new Error(`Unsupported gitiles ref type: ${refType}`);\n}\n\n/**\n * Return the authentication prefix.\n *\n * @remarks\n *\n * To authenticate with a password the API url must be prefixed with \"/a/\".\n * If no password is set anonymous access (without the prefix) will\n * be used.\n *\n * @param config - A Gerrit provider config.\n * @public\n */\nexport function getAuthenticationPrefix(\n config: GerritIntegrationConfig,\n): string {\n return config.password ? '/a/' : '/';\n}\n\n/**\n * Return the authentication gitiles url.\n *\n * @remarks\n *\n * To authenticate with a password the API url must be prefixed with \"/a/\".\n * If no password is set anonymous access (without the prefix) will\n * be used.\n *\n * @param config - A Gerrit provider config.\n * @public\n */\nexport function getGitilesAuthenticationUrl(\n config: GerritIntegrationConfig,\n): string {\n if (!config.baseUrl || !config.gitilesBaseUrl) {\n throw new Error(\n 'Unexpected Gerrit config values. baseUrl or gitilesBaseUrl not set.',\n );\n }\n if (config.gitilesBaseUrl.startsWith(config.baseUrl)) {\n return config.gitilesBaseUrl.replace(\n config.baseUrl.concat('/'),\n config.baseUrl.concat(getAuthenticationPrefix(config)),\n );\n }\n if (config.password) {\n throw new Error(\n 'Since the baseUrl (Gerrit) is not part of the gitilesBaseUrl, an authentication URL could not be constructed.',\n );\n }\n return config.gitilesBaseUrl!;\n}\n\n/**\n * Return the url to get branch info from the Gerrit API.\n *\n * @param config - A Gerrit provider config.\n * @param url - An url pointing to a file in git.\n * @public\n */\nexport function getGerritBranchApiUrl(\n config: GerritIntegrationConfig,\n url: string,\n) {\n const { branch, project } = parseGerritGitilesUrl(config, url);\n\n return `${config.baseUrl}${getAuthenticationPrefix(\n config,\n )}projects/${encodeURIComponent(project)}/branches/${branch}`;\n}\n\n/**\n * Return the url to clone the repo that is referenced by the url.\n *\n * @param url - An url pointing to a file in git.\n * @public\n */\nexport function getGerritCloneRepoUrl(\n config: GerritIntegrationConfig,\n url: string,\n) {\n const { project } = parseGerritGitilesUrl(config, url);\n\n return `${config.cloneUrl}${getAuthenticationPrefix(config)}${project}`;\n}\n\n/**\n * Return the url to fetch the contents of a file using the Gerrit API.\n *\n * @param config - A Gerrit provider config.\n * @param url - An url pointing to a file in git.\n * @public\n */\nexport function getGerritFileContentsApiUrl(\n config: GerritIntegrationConfig,\n url: string,\n) {\n const { ref, refType, path, project } = parseGitilesUrlRef(config, url);\n\n // https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#get-content\n if (refType === 'branch') {\n return `${config.baseUrl}${getAuthenticationPrefix(\n config,\n )}projects/${encodeURIComponent(\n project,\n )}/branches/${ref}/files/${encodeURIComponent(path)}/content`;\n }\n // https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#get-content-from-commit\n if (refType === 'sha') {\n return `${config.baseUrl}${getAuthenticationPrefix(\n config,\n )}projects/${encodeURIComponent(\n project,\n )}/commits/${ref}/files/${encodeURIComponent(path)}/content`;\n }\n throw new Error(`Unsupported gitiles ref type: ${refType}`);\n}\n\n/**\n * Return the url to query available projects using the Gerrit API.\n *\n * @param config - A Gerrit provider config.\n * @public\n */\nexport function getGerritProjectsApiUrl(config: GerritIntegrationConfig) {\n return `${config.baseUrl}${getAuthenticationPrefix(config)}projects/`;\n}\n\n/**\n * Return request headers for a Gerrit provider.\n *\n * @param config - A Gerrit provider config\n * @public\n */\nexport function getGerritRequestOptions(config: GerritIntegrationConfig): {\n headers?: Record<string, string>;\n} {\n const headers: Record<string, string> = {};\n\n if (!config.password) {\n return headers;\n }\n const buffer = Buffer.from(`${config.username}:${config.password}`, 'utf8');\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n return {\n headers,\n };\n}\n\n/**\n * Parse the json response from Gerrit and strip the magic prefix.\n *\n * @remarks\n *\n * To prevent against XSSI attacks the JSON response body from Gerrit starts\n * with a magic prefix that must be stripped before it can be fed to a JSON\n * parser.\n *\n * @param response - An API response.\n * @public\n */\nexport async function parseGerritJsonResponse(\n response: Response,\n): Promise<unknown> {\n const responseBody = await response.text();\n if (responseBody.startsWith(GERRIT_BODY_PREFIX)) {\n try {\n return JSON.parse(responseBody.slice(GERRIT_BODY_PREFIX.length));\n } catch (ex) {\n throw new Error(\n `Invalid response from Gerrit: ${responseBody.slice(0, 10)} - ${ex}`,\n );\n }\n }\n throw new Error(\n `Gerrit JSON body prefix missing. Found: ${responseBody.slice(0, 10)}`,\n );\n}\n"],"names":[],"mappings":";;AAkBA,MAAM,kBAAqB,GAAA,MAAA;AA4BX,SAAA,qBAAA,CACd,QACA,GACuD,EAAA;AACvD,EAAA,MAAM,YAAe,GAAA,IAAI,GAAI,CAAA,MAAA,CAAO,cAAe,CAAA;AACnD,EAAM,MAAA,QAAA,GAAW,IAAI,GAAA,CAAI,GAAG,CAAA;AAM5B,EAAA,MAAM,OAAU,GAAA,QAAA,CAAS,QACtB,CAAA,SAAA,CAAU,SAAS,QAAS,CAAA,UAAA,CAAW,KAAK,CAAA,GAAI,IAAI,CAAC,CAAA,CACrD,OAAQ,CAAA,YAAA,CAAa,UAAU,EAAE,CAAA;AAEpC,EAAM,MAAA,KAAA,GAAQ,QAAQ,KAAM,CAAA,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Aa,KAAM,CAAA,kBAAA,CAAmB,MAAM,CAAC,CAAA;AAAA,aACxD,EAAI,EAAA;AACX,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,iCAAiC,YAAa,CAAA,KAAA,CAAM,GAAG,EAAE,CAAC,MAAM,EAAE,CAAA;AAAA,OACpE;AAAA;AACF;AAEF,EAAA,MAAM,IAAI,KAAA;AAAA,IACR,CAA2C,wCAAA,EAAA,YAAA,CAAa,KAAM,CAAA,CAAA,EAAG,EAAE,CAAC,CAAA;AAAA,GACtE;AACF;;;;"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -94,6 +94,7 @@ exports.getGerritCloneRepoUrl = core$4.getGerritCloneRepoUrl;
|
|
|
94
94
|
exports.getGerritFileContentsApiUrl = core$4.getGerritFileContentsApiUrl;
|
|
95
95
|
exports.getGerritProjectsApiUrl = core$4.getGerritProjectsApiUrl;
|
|
96
96
|
exports.getGerritRequestOptions = core$4.getGerritRequestOptions;
|
|
97
|
+
exports.getGitilesAuthenticationUrl = core$4.getGitilesAuthenticationUrl;
|
|
97
98
|
exports.parseGerritGitilesUrl = core$4.parseGerritGitilesUrl;
|
|
98
99
|
exports.parseGerritJsonResponse = core$4.parseGerritJsonResponse;
|
|
99
100
|
exports.parseGitilesUrlRef = core$4.parseGitilesUrlRef;
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1479,6 +1479,19 @@ declare function buildGerritGitilesArchiveUrl(config: GerritIntegrationConfig, p
|
|
|
1479
1479
|
* @public
|
|
1480
1480
|
*/
|
|
1481
1481
|
declare function buildGerritGitilesArchiveUrlFromLocation(config: GerritIntegrationConfig, url: string): string;
|
|
1482
|
+
/**
|
|
1483
|
+
* Return the authentication gitiles url.
|
|
1484
|
+
*
|
|
1485
|
+
* @remarks
|
|
1486
|
+
*
|
|
1487
|
+
* To authenticate with a password the API url must be prefixed with "/a/".
|
|
1488
|
+
* If no password is set anonymous access (without the prefix) will
|
|
1489
|
+
* be used.
|
|
1490
|
+
*
|
|
1491
|
+
* @param config - A Gerrit provider config.
|
|
1492
|
+
* @public
|
|
1493
|
+
*/
|
|
1494
|
+
declare function getGitilesAuthenticationUrl(config: GerritIntegrationConfig): string;
|
|
1482
1495
|
/**
|
|
1483
1496
|
* Return the url to get branch info from the Gerrit API.
|
|
1484
1497
|
*
|
|
@@ -1988,4 +2001,4 @@ declare class ScmIntegrations implements ScmIntegrationRegistry {
|
|
|
1988
2001
|
resolveEditUrl(url: string): string;
|
|
1989
2002
|
}
|
|
1990
2003
|
|
|
1991
|
-
export { AwsCodeCommitIntegration, type AwsCodeCommitIntegrationConfig, AwsS3Integration, type AwsS3IntegrationConfig, type AzureBlobStorageIntegrationConfig, AzureBlobStorageIntergation, type AzureClientSecretCredential, type AzureCredentialBase, type AzureCredentialsManager, type AzureDevOpsCredential, type AzureDevOpsCredentialKind, type AzureDevOpsCredentialLike, type AzureDevOpsCredentialType, type AzureDevOpsCredentials, type AzureDevOpsCredentialsProvider, AzureIntegration, type AzureIntegrationConfig, type AzureManagedIdentityCredential, BitbucketCloudIntegration, type BitbucketCloudIntegrationConfig, BitbucketIntegration, type BitbucketIntegrationConfig, BitbucketServerIntegration, type BitbucketServerIntegrationConfig, DefaultAzureCredentialsManager, DefaultAzureDevOpsCredentialsProvider, DefaultGithubCredentialsProvider, DefaultGitlabCredentialsProvider, GerritIntegration, type GerritIntegrationConfig, GitLabIntegration, type GitLabIntegrationConfig, GiteaIntegration, type GiteaIntegrationConfig, type GithubAppConfig, GithubAppCredentialsMux, type GithubCredentialType, type GithubCredentials, type GithubCredentialsProvider, GithubIntegration, type GithubIntegrationConfig, type GitlabCredentials, type GitlabCredentialsProvider, type GoogleGcsIntegrationConfig, HarnessIntegration, type HarnessIntegrationConfig, type IntegrationsByType, type PersonalAccessTokenCredential, type RateLimitInfo, type ScmIntegration, type ScmIntegrationRegistry, ScmIntegrations, type ScmIntegrationsFactory, type ScmIntegrationsGroup, SingleInstanceGithubCredentialsProvider, buildGerritGitilesArchiveUrl, buildGerritGitilesArchiveUrlFromLocation, defaultScmResolveUrl, getAzureCommitsUrl, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketCloudDefaultBranch, getBitbucketCloudDownloadUrl, getBitbucketCloudFileFetchUrl, getBitbucketCloudRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getBitbucketServerDefaultBranch, getBitbucketServerDownloadUrl, getBitbucketServerFileFetchUrl, getBitbucketServerRequestOptions, getGerritBranchApiUrl, getGerritCloneRepoUrl, getGerritFileContentsApiUrl, getGerritProjectsApiUrl, getGerritRequestOptions, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabIntegrationRelativePath, getGitLabRequestOptions, getGiteaArchiveUrl, getGiteaEditContentsUrl, getGiteaFileContentsUrl, getGiteaLatestCommitUrl, getGiteaRequestOptions, getGithubFileFetchUrl, getHarnessArchiveUrl, getHarnessFileContentsUrl, getHarnessLatestCommitUrl, getHarnessRequestOptions, parseGerritGitilesUrl, parseGerritJsonResponse, parseGiteaUrl, parseGitilesUrlRef, parseHarnessUrl, readAwsCodeCommitIntegrationConfig, readAwsCodeCommitIntegrationConfigs, readAwsS3IntegrationConfig, readAwsS3IntegrationConfigs, readAzureBlobStorageIntegrationConfig, readAzureBlobStorageIntegrationConfigs, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketCloudIntegrationConfig, readBitbucketCloudIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readBitbucketServerIntegrationConfig, readBitbucketServerIntegrationConfigs, readGerritIntegrationConfig, readGerritIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs, readGiteaConfig, readGithubIntegrationConfig, readGithubIntegrationConfigs, readGoogleGcsIntegrationConfig, readHarnessConfig, replaceGitLabUrlType, replaceGithubUrlType };
|
|
2004
|
+
export { AwsCodeCommitIntegration, type AwsCodeCommitIntegrationConfig, AwsS3Integration, type AwsS3IntegrationConfig, type AzureBlobStorageIntegrationConfig, AzureBlobStorageIntergation, type AzureClientSecretCredential, type AzureCredentialBase, type AzureCredentialsManager, type AzureDevOpsCredential, type AzureDevOpsCredentialKind, type AzureDevOpsCredentialLike, type AzureDevOpsCredentialType, type AzureDevOpsCredentials, type AzureDevOpsCredentialsProvider, AzureIntegration, type AzureIntegrationConfig, type AzureManagedIdentityCredential, BitbucketCloudIntegration, type BitbucketCloudIntegrationConfig, BitbucketIntegration, type BitbucketIntegrationConfig, BitbucketServerIntegration, type BitbucketServerIntegrationConfig, DefaultAzureCredentialsManager, DefaultAzureDevOpsCredentialsProvider, DefaultGithubCredentialsProvider, DefaultGitlabCredentialsProvider, GerritIntegration, type GerritIntegrationConfig, GitLabIntegration, type GitLabIntegrationConfig, GiteaIntegration, type GiteaIntegrationConfig, type GithubAppConfig, GithubAppCredentialsMux, type GithubCredentialType, type GithubCredentials, type GithubCredentialsProvider, GithubIntegration, type GithubIntegrationConfig, type GitlabCredentials, type GitlabCredentialsProvider, type GoogleGcsIntegrationConfig, HarnessIntegration, type HarnessIntegrationConfig, type IntegrationsByType, type PersonalAccessTokenCredential, type RateLimitInfo, type ScmIntegration, type ScmIntegrationRegistry, ScmIntegrations, type ScmIntegrationsFactory, type ScmIntegrationsGroup, SingleInstanceGithubCredentialsProvider, buildGerritGitilesArchiveUrl, buildGerritGitilesArchiveUrlFromLocation, defaultScmResolveUrl, getAzureCommitsUrl, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketCloudDefaultBranch, getBitbucketCloudDownloadUrl, getBitbucketCloudFileFetchUrl, getBitbucketCloudRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getBitbucketServerDefaultBranch, getBitbucketServerDownloadUrl, getBitbucketServerFileFetchUrl, getBitbucketServerRequestOptions, getGerritBranchApiUrl, getGerritCloneRepoUrl, getGerritFileContentsApiUrl, getGerritProjectsApiUrl, getGerritRequestOptions, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabIntegrationRelativePath, getGitLabRequestOptions, getGiteaArchiveUrl, getGiteaEditContentsUrl, getGiteaFileContentsUrl, getGiteaLatestCommitUrl, getGiteaRequestOptions, getGithubFileFetchUrl, getGitilesAuthenticationUrl, getHarnessArchiveUrl, getHarnessFileContentsUrl, getHarnessLatestCommitUrl, getHarnessRequestOptions, parseGerritGitilesUrl, parseGerritJsonResponse, parseGiteaUrl, parseGitilesUrlRef, parseHarnessUrl, readAwsCodeCommitIntegrationConfig, readAwsCodeCommitIntegrationConfigs, readAwsS3IntegrationConfig, readAwsS3IntegrationConfigs, readAzureBlobStorageIntegrationConfig, readAzureBlobStorageIntegrationConfigs, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketCloudIntegrationConfig, readBitbucketCloudIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readBitbucketServerIntegrationConfig, readBitbucketServerIntegrationConfigs, readGerritIntegrationConfig, readGerritIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs, readGiteaConfig, readGithubIntegrationConfig, readGithubIntegrationConfigs, readGoogleGcsIntegrationConfig, readHarnessConfig, replaceGitLabUrlType, replaceGithubUrlType };
|
package/dist/index.esm.js
CHANGED
|
@@ -21,7 +21,7 @@ export { readBitbucketServerIntegrationConfig, readBitbucketServerIntegrationCon
|
|
|
21
21
|
export { getBitbucketServerDefaultBranch, getBitbucketServerDownloadUrl, getBitbucketServerFileFetchUrl, getBitbucketServerRequestOptions } from './bitbucketServer/core.esm.js';
|
|
22
22
|
export { GerritIntegration } from './gerrit/GerritIntegration.esm.js';
|
|
23
23
|
export { readGerritIntegrationConfig, readGerritIntegrationConfigs } from './gerrit/config.esm.js';
|
|
24
|
-
export { buildGerritGitilesArchiveUrl, buildGerritGitilesArchiveUrlFromLocation, getGerritBranchApiUrl, getGerritCloneRepoUrl, getGerritFileContentsApiUrl, getGerritProjectsApiUrl, getGerritRequestOptions, parseGerritGitilesUrl, parseGerritJsonResponse, parseGitilesUrlRef } from './gerrit/core.esm.js';
|
|
24
|
+
export { buildGerritGitilesArchiveUrl, buildGerritGitilesArchiveUrlFromLocation, getGerritBranchApiUrl, getGerritCloneRepoUrl, getGerritFileContentsApiUrl, getGerritProjectsApiUrl, getGerritRequestOptions, getGitilesAuthenticationUrl, parseGerritGitilesUrl, parseGerritJsonResponse, parseGitilesUrlRef } from './gerrit/core.esm.js';
|
|
25
25
|
export { GiteaIntegration } from './gitea/GiteaIntegration.esm.js';
|
|
26
26
|
export { getGiteaArchiveUrl, getGiteaEditContentsUrl, getGiteaFileContentsUrl, getGiteaLatestCommitUrl, getGiteaRequestOptions, parseGiteaUrl } from './gitea/core.esm.js';
|
|
27
27
|
export { readGiteaConfig } from './gitea/config.esm.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/integration",
|
|
3
|
-
"version": "1.16.2
|
|
3
|
+
"version": "1.16.2",
|
|
4
4
|
"description": "Helpers for managing integrations towards external systems",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "common-library"
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@azure/identity": "^4.0.0",
|
|
41
41
|
"@azure/storage-blob": "^12.5.0",
|
|
42
|
-
"@backstage/config": "1.3.2",
|
|
43
|
-
"@backstage/errors": "1.2.7",
|
|
42
|
+
"@backstage/config": "^1.3.2",
|
|
43
|
+
"@backstage/errors": "^1.2.7",
|
|
44
44
|
"@octokit/auth-app": "^4.0.0",
|
|
45
45
|
"@octokit/rest": "^19.0.3",
|
|
46
46
|
"cross-fetch": "^4.0.0",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"luxon": "^3.0.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@backstage/cli": "0.31.0
|
|
53
|
-
"@backstage/config-loader": "1.10.0
|
|
52
|
+
"@backstage/cli": "^0.31.0",
|
|
53
|
+
"@backstage/config-loader": "^1.10.0",
|
|
54
54
|
"@types/luxon": "^3.0.0",
|
|
55
55
|
"msw": "^1.0.0"
|
|
56
56
|
},
|