@backstage/integration 1.21.0-next.0 → 2.0.0-next.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/config.d.ts +3 -60
  3. package/dist/ScmIntegrations.cjs.js +1 -17
  4. package/dist/ScmIntegrations.cjs.js.map +1 -1
  5. package/dist/ScmIntegrations.esm.js +1 -17
  6. package/dist/ScmIntegrations.esm.js.map +1 -1
  7. package/dist/azure/config.cjs.js +14 -35
  8. package/dist/azure/config.cjs.js.map +1 -1
  9. package/dist/azure/config.esm.js +14 -35
  10. package/dist/azure/config.esm.js.map +1 -1
  11. package/dist/bitbucketCloud/core.cjs.js +3 -2
  12. package/dist/bitbucketCloud/core.cjs.js.map +1 -1
  13. package/dist/bitbucketCloud/core.esm.js +3 -2
  14. package/dist/bitbucketCloud/core.esm.js.map +1 -1
  15. package/dist/bitbucketServer/core.cjs.js +8 -2
  16. package/dist/bitbucketServer/core.cjs.js.map +1 -1
  17. package/dist/bitbucketServer/core.esm.js +8 -2
  18. package/dist/bitbucketServer/core.esm.js.map +1 -1
  19. package/dist/gerrit/core.cjs.js +6 -33
  20. package/dist/gerrit/core.cjs.js.map +1 -1
  21. package/dist/gerrit/core.esm.js +7 -32
  22. package/dist/gerrit/core.esm.js.map +1 -1
  23. package/dist/github/core.cjs.js +2 -17
  24. package/dist/github/core.cjs.js.map +1 -1
  25. package/dist/github/core.esm.js +3 -13
  26. package/dist/github/core.esm.js.map +1 -1
  27. package/dist/helpers.cjs.js +23 -1
  28. package/dist/helpers.cjs.js.map +1 -1
  29. package/dist/helpers.esm.js +23 -2
  30. package/dist/helpers.esm.js.map +1 -1
  31. package/dist/index.cjs.js +61 -76
  32. package/dist/index.cjs.js.map +1 -1
  33. package/dist/index.d.ts +2 -222
  34. package/dist/index.esm.js +2 -6
  35. package/dist/index.esm.js.map +1 -1
  36. package/package.json +2 -2
  37. package/dist/azure/deprecated.cjs.js +0 -26
  38. package/dist/azure/deprecated.cjs.js.map +0 -1
  39. package/dist/azure/deprecated.esm.js +0 -24
  40. package/dist/azure/deprecated.esm.js.map +0 -1
  41. package/dist/bitbucket/BitbucketIntegration.cjs.js +0 -65
  42. package/dist/bitbucket/BitbucketIntegration.cjs.js.map +0 -1
  43. package/dist/bitbucket/BitbucketIntegration.esm.js +0 -59
  44. package/dist/bitbucket/BitbucketIntegration.esm.js.map +0 -1
  45. package/dist/bitbucket/config.cjs.js +0 -48
  46. package/dist/bitbucket/config.cjs.js.map +0 -1
  47. package/dist/bitbucket/config.esm.js +0 -45
  48. package/dist/bitbucket/config.esm.js.map +0 -1
  49. package/dist/bitbucket/core.cjs.js +0 -95
  50. package/dist/bitbucket/core.cjs.js.map +0 -1
  51. package/dist/bitbucket/core.esm.js +0 -85
  52. package/dist/bitbucket/core.esm.js.map +0 -1
@@ -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 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 buildGerritEditUrl(\n config: GerritIntegrationConfig,\n project: string,\n branch: string,\n filePath: string,\n): string {\n return `${\n config.baseUrl\n }/admin/repos/edit/repo/${project}/branch/refs/heads/${branch}/file/${trimStart(\n filePath,\n '/',\n )}`;\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,kBAAA,GAAqB,MAAA;AA4BpB,SAAS,qBAAA,CACd,QACA,GAAA,EACuD;AACvD,EAAA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,MAAA,CAAO,cAAe,CAAA;AACnD,EAAA,MAAM,QAAA,GAAW,IAAI,GAAA,CAAI,GAAG,CAAA;AAM5B,EAAA,MAAM,OAAA,GAAU,QAAA,CAAS,QAAA,CACtB,SAAA,CAAU,SAAS,QAAA,CAAS,UAAA,CAAW,KAAK,CAAA,GAAI,IAAI,CAAC,CAAA,CACrD,OAAA,CAAQ,YAAA,CAAa,UAAU,EAAE,CAAA;AAEpC,EAAA,MAAM,KAAA,GAAQ,QAAQ,KAAA,CAAM,GAAG,EAAE,MAAA,CAAO,CAAA,CAAA,KAAK,CAAC,CAAC,CAAC,CAAA;AAEhD,EAAA,MAAM,eAAA,GAAkB,KAAA,CAAM,OAAA,CAAQ,GAAG,CAAA;AAEzC,EAAA,IAAI,mBAAmB,CAAA,EAAG;AACxB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kCAAA,EAAqC,GAAG,CAAA,C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MAAA,OAAO,KAAK,KAAA,CAAM,YAAA,CAAa,KAAA,CAAM,kBAAA,CAAmB,MAAM,CAAC,CAAA;AAAA,IACjE,SAAS,EAAA,EAAI;AACX,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,iCAAiC,YAAA,CAAa,KAAA,CAAM,GAAG,EAAE,CAAC,MAAM,EAAE,CAAA;AAAA,OACpE;AAAA,IACF;AAAA,EACF;AACA,EAAA,MAAM,IAAI,KAAA;AAAA,IACR,CAAA,wCAAA,EAA2C,YAAA,CAAa,KAAA,CAAM,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 * 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 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 buildGerritEditUrl(\n config: GerritIntegrationConfig,\n project: string,\n branch: string,\n filePath: string,\n): string {\n return `${\n config.baseUrl\n }/admin/repos/edit/repo/${project}/branch/refs/heads/${branch}/file/${trimStart(\n filePath,\n '/',\n )}`;\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 { ref, refType, project } = parseGitilesUrlRef(config, url);\n\n if (refType !== 'branch') {\n throw new Error(`Unsupported gitiles ref type: ${refType}`);\n }\n\n return `${config.baseUrl}${getAuthenticationPrefix(\n config,\n )}projects/${encodeURIComponent(project)}/branches/${ref}`;\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 } = parseGitilesUrlRef(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 );\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A,GAAS,MAAA,CAAO,IAAA,CAAK,CAAA,EAAG,MAAA,CAAO,QAAQ,CAAA,CAAA,EAAI,MAAA,CAAO,QAAQ,CAAA,CAAA,EAAI,MAAM,CAAA;AAC1E,EAAA,OAAA,CAAQ,aAAA,GAAgB,CAAA,MAAA,EAAS,MAAA,CAAO,QAAA,CAAS,QAAQ,CAAC,CAAA,CAAA;AAC1D,EAAA,OAAO;AAAA,IACL;AAAA,GACF;AACF;AAcA,eAAsB,wBACpB,QAAA,EACkB;AAClB,EAAA,MAAM,YAAA,GAAe,MAAM,QAAA,CAAS,IAAA,EAAK;AACzC,EAAA,IAAI,YAAA,CAAa,UAAA,CAAW,kBAAkB,CAAA,EAAG;AAC/C,IAAA,IAAI;AACF,MAAA,OAAO,KAAK,KAAA,CAAM,YAAA,CAAa,KAAA,CAAM,kBAAA,CAAmB,MAAM,CAAC,CAAA;AAAA,IACjE,SAAS,EAAA,EAAI;AACX,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,iCAAiC,YAAA,CAAa,KAAA,CAAM,GAAG,EAAE,CAAC,MAAM,EAAE,CAAA;AAAA,OACpE;AAAA,IACF;AAAA,EACF;AACA,EAAA,MAAM,IAAI,KAAA;AAAA,IACR,CAAA,wCAAA,EAA2C,YAAA,CAAa,KAAA,CAAM,CAAA,EAAG,EAAE,CAAC,CAAA;AAAA,GACtE;AACF;;;;"}
@@ -1,14 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var parseGitUrl = require('git-url-parse');
4
-
5
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
6
-
7
- var parseGitUrl__default = /*#__PURE__*/_interopDefaultCompat(parseGitUrl);
3
+ var helpers = require('../helpers.cjs.js');
8
4
 
9
5
  function getGithubFileFetchUrl(url, config, credentials) {
10
6
  try {
11
- const { owner, name, ref, filepathtype, filepath } = parseGitUrl__default.default(url);
7
+ const { owner, name, ref, filepathtype, filepath } = helpers.parseGitUrlSafe(url);
12
8
  if (!owner || !name || !ref || // GitHub is automatically redirecting tree urls to blob urls so it's
13
9
  // fine to pass a tree url.
14
10
  filepathtype !== "blob" && filepathtype !== "raw" && filepathtype !== "tree") {
@@ -23,16 +19,6 @@ function getGithubFileFetchUrl(url, config, credentials) {
23
19
  throw new Error(`Incorrect URL: ${url}, ${e}`);
24
20
  }
25
21
  }
26
- function getGitHubRequestOptions(config, credentials) {
27
- const headers = {};
28
- if (chooseEndpoint(config, credentials) === "api") {
29
- headers.Accept = "application/vnd.github.v3.raw";
30
- }
31
- if (credentials.token) {
32
- headers.Authorization = `token ${credentials.token}`;
33
- }
34
- return { headers };
35
- }
36
22
  function chooseEndpoint(config, credentials) {
37
23
  if (config.apiBaseUrl && (credentials.token || !config.rawBaseUrl)) {
38
24
  return "api";
@@ -41,6 +27,5 @@ function chooseEndpoint(config, credentials) {
41
27
  }
42
28
 
43
29
  exports.chooseEndpoint = chooseEndpoint;
44
- exports.getGitHubRequestOptions = getGitHubRequestOptions;
45
30
  exports.getGithubFileFetchUrl = getGithubFileFetchUrl;
46
31
  //# sourceMappingURL=core.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"core.cjs.js","sources":["../../src/github/core.ts"],"sourcesContent":["/*\n * Copyright 2020 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 */\n\nimport parseGitUrl from 'git-url-parse';\nimport { GithubIntegrationConfig } from './config';\nimport { GithubCredentials } from './types';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://github.com/a/b/blob/branchname/path/to/c.yaml\n * to: https://api.github.com/repos/a/b/contents/path/to/c.yaml?ref=branchname\n * or: https://raw.githubusercontent.com/a/b/branchname/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getGithubFileFetchUrl(\n url: string,\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrl(url);\n if (\n !owner ||\n !name ||\n !ref ||\n // GitHub is automatically redirecting tree urls to blob urls so it's\n // fine to pass a tree url.\n (filepathtype !== 'blob' &&\n filepathtype !== 'raw' &&\n filepathtype !== 'tree')\n ) {\n throw new Error('Invalid GitHub URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n if (chooseEndpoint(config, credentials) === 'api') {\n return `${config.apiBaseUrl}/repos/${owner}/${name}/contents/${pathWithoutSlash}?ref=${ref}`;\n }\n return `${config.rawBaseUrl}/${owner}/${name}/${ref}/${pathWithoutSlash}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n *\n * @deprecated This function is no longer used internally\n * @param config - The relevant provider config\n * @public\n */\nexport function getGitHubRequestOptions(\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): { headers: Record<string, string> } {\n const headers: Record<string, string> = {};\n\n if (chooseEndpoint(config, credentials) === 'api') {\n headers.Accept = 'application/vnd.github.v3.raw';\n }\n\n if (credentials.token) {\n headers.Authorization = `token ${credentials.token}`;\n }\n\n return { headers };\n}\n\nexport function chooseEndpoint(\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): 'api' | 'raw' {\n if (config.apiBaseUrl && (credentials.token || !config.rawBaseUrl)) {\n return 'api';\n }\n return 'raw';\n}\n"],"names":["parseGitUrl"],"mappings":";;;;;;;;AAmCO,SAAS,qBAAA,CACd,GAAA,EACA,MAAA,EACA,WAAA,EACQ;AACR,EAAA,IAAI;AACF,IAAA,MAAM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EACpD;AAEA,EAAA,OAAO,EAAE,OAAA,EAAQ;AACnB;AAEO,SAAS,cAAA,CACd,QACA,WAAA,EACe;AACf,EAAA,IAAI,OAAO,UAAA,KAAe,WAAA,CAAY,KAAA,IAAS,CAAC,OAAO,UAAA,CAAA,EAAa;AAClE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA;AACT;;;;;;"}
1
+ {"version":3,"file":"core.cjs.js","sources":["../../src/github/core.ts"],"sourcesContent":["/*\n * Copyright 2020 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 */\n\nimport { GithubIntegrationConfig } from './config';\nimport { parseGitUrlSafe } from '../helpers';\nimport { GithubCredentials } from './types';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://github.com/a/b/blob/branchname/path/to/c.yaml\n * to: https://api.github.com/repos/a/b/contents/path/to/c.yaml?ref=branchname\n * or: https://raw.githubusercontent.com/a/b/branchname/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getGithubFileFetchUrl(\n url: string,\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);\n if (\n !owner ||\n !name ||\n !ref ||\n // GitHub is automatically redirecting tree urls to blob urls so it's\n // fine to pass a tree url.\n (filepathtype !== 'blob' &&\n filepathtype !== 'raw' &&\n filepathtype !== 'tree')\n ) {\n throw new Error('Invalid GitHub URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n if (chooseEndpoint(config, credentials) === 'api') {\n return `${config.apiBaseUrl}/repos/${owner}/${name}/contents/${pathWithoutSlash}?ref=${ref}`;\n }\n return `${config.rawBaseUrl}/${owner}/${name}/${ref}/${pathWithoutSlash}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n\nexport function chooseEndpoint(\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): 'api' | 'raw' {\n if (config.apiBaseUrl && (credentials.token || !config.rawBaseUrl)) {\n return 'api';\n }\n return 'raw';\n}\n"],"names":["parseGitUrlSafe"],"mappings":";;;;AAmCO,SAAS,qBAAA,CACd,GAAA,EACA,MAAA,EACA,WAAA,EACQ;AACR,EAAA,IAAI;AACF,IAAA,MAAM,EAAE,OAAO,IAAA,EAAM,GAAA,EAAK,cAAc,QAAA,EAAS,GAAIA,wBAAgB,GAAG,CAAA;AACxE,IAAA,IACE,CAAC,KAAA,IACD,CAAC,IAAA,IACD,CAAC,GAAA;AAAA;AAAA,IAGA,YAAA,KAAiB,MAAA,IAChB,YAAA,KAAiB,KAAA,IACjB,iBAAiB,MAAA,EACnB;AACA,MAAA,MAAM,IAAI,MAAM,iCAAiC,CAAA;AAAA,IACnD;AAEA,IAAA,MAAM,gBAAA,GAAmB,QAAA,CAAS,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AACnD,IAAA,IAAI,cAAA,CAAe,MAAA,EAAQ,WAAW,CAAA,KAAM,KAAA,EAAO;AACjD,MAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,OAAA,EAAU,KAAK,IAAI,IAAI,CAAA,UAAA,EAAa,gBAAgB,CAAA,KAAA,EAAQ,GAAG,CAAA,CAAA;AAAA,IAC5F;AACA,IAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,CAAA,EAAI,KAAK,IAAI,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,EAAI,gBAAgB,CAAA,CAAA;AAAA,EACzE,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAC/C;AACF;AAEO,SAAS,cAAA,CACd,QACA,WAAA,EACe;AACf,EAAA,IAAI,OAAO,UAAA,KAAe,WAAA,CAAY,KAAA,IAAS,CAAC,OAAO,UAAA,CAAA,EAAa;AAClE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA;AACT;;;;;"}
@@ -1,8 +1,8 @@
1
- import parseGitUrl from 'git-url-parse';
1
+ import { parseGitUrlSafe } from '../helpers.esm.js';
2
2
 
3
3
  function getGithubFileFetchUrl(url, config, credentials) {
4
4
  try {
5
- const { owner, name, ref, filepathtype, filepath } = parseGitUrl(url);
5
+ const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);
6
6
  if (!owner || !name || !ref || // GitHub is automatically redirecting tree urls to blob urls so it's
7
7
  // fine to pass a tree url.
8
8
  filepathtype !== "blob" && filepathtype !== "raw" && filepathtype !== "tree") {
@@ -17,16 +17,6 @@ function getGithubFileFetchUrl(url, config, credentials) {
17
17
  throw new Error(`Incorrect URL: ${url}, ${e}`);
18
18
  }
19
19
  }
20
- function getGitHubRequestOptions(config, credentials) {
21
- const headers = {};
22
- if (chooseEndpoint(config, credentials) === "api") {
23
- headers.Accept = "application/vnd.github.v3.raw";
24
- }
25
- if (credentials.token) {
26
- headers.Authorization = `token ${credentials.token}`;
27
- }
28
- return { headers };
29
- }
30
20
  function chooseEndpoint(config, credentials) {
31
21
  if (config.apiBaseUrl && (credentials.token || !config.rawBaseUrl)) {
32
22
  return "api";
@@ -34,5 +24,5 @@ function chooseEndpoint(config, credentials) {
34
24
  return "raw";
35
25
  }
36
26
 
37
- export { chooseEndpoint, getGitHubRequestOptions, getGithubFileFetchUrl };
27
+ export { chooseEndpoint, getGithubFileFetchUrl };
38
28
  //# sourceMappingURL=core.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"core.esm.js","sources":["../../src/github/core.ts"],"sourcesContent":["/*\n * Copyright 2020 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 */\n\nimport parseGitUrl from 'git-url-parse';\nimport { GithubIntegrationConfig } from './config';\nimport { GithubCredentials } from './types';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://github.com/a/b/blob/branchname/path/to/c.yaml\n * to: https://api.github.com/repos/a/b/contents/path/to/c.yaml?ref=branchname\n * or: https://raw.githubusercontent.com/a/b/branchname/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getGithubFileFetchUrl(\n url: string,\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrl(url);\n if (\n !owner ||\n !name ||\n !ref ||\n // GitHub is automatically redirecting tree urls to blob urls so it's\n // fine to pass a tree url.\n (filepathtype !== 'blob' &&\n filepathtype !== 'raw' &&\n filepathtype !== 'tree')\n ) {\n throw new Error('Invalid GitHub URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n if (chooseEndpoint(config, credentials) === 'api') {\n return `${config.apiBaseUrl}/repos/${owner}/${name}/contents/${pathWithoutSlash}?ref=${ref}`;\n }\n return `${config.rawBaseUrl}/${owner}/${name}/${ref}/${pathWithoutSlash}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n *\n * @deprecated This function is no longer used internally\n * @param config - The relevant provider config\n * @public\n */\nexport function getGitHubRequestOptions(\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): { headers: Record<string, string> } {\n const headers: Record<string, string> = {};\n\n if (chooseEndpoint(config, credentials) === 'api') {\n headers.Accept = 'application/vnd.github.v3.raw';\n }\n\n if (credentials.token) {\n headers.Authorization = `token ${credentials.token}`;\n }\n\n return { headers };\n}\n\nexport function chooseEndpoint(\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): 'api' | 'raw' {\n if (config.apiBaseUrl && (credentials.token || !config.rawBaseUrl)) {\n return 'api';\n }\n return 'raw';\n}\n"],"names":[],"mappings":";;AAmCO,SAAS,qBAAA,CACd,GAAA,EACA,MAAA,EACA,WAAA,EACQ;AACR,EAAA,IAAI;AACF,IAAA,MAAM,EAAE,OAAO,IAAA,EAAM,GAAA,EAAK,cAAc,QAAA,EAAS,GAAI,YAAY,GAAG,CAAA;AACpE,IAAA,IACE,CAAC,KAAA,IACD,CAAC,IAAA,IACD,CAAC,GAAA;AAAA;AAAA,IAGA,YAAA,KAAiB,MAAA,IAChB,YAAA,KAAiB,KAAA,IACjB,iBAAiB,MAAA,EACnB;AACA,MAAA,MAAM,IAAI,MAAM,iCAAiC,CAAA;AAAA,IACnD;AAEA,IAAA,MAAM,gBAAA,GAAmB,QAAA,CAAS,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AACnD,IAAA,IAAI,cAAA,CAAe,MAAA,EAAQ,WAAW,CAAA,KAAM,KAAA,EAAO;AACjD,MAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,OAAA,EAAU,KAAK,IAAI,IAAI,CAAA,UAAA,EAAa,gBAAgB,CAAA,KAAA,EAAQ,GAAG,CAAA,CAAA;AAAA,IAC5F;AACA,IAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,CAAA,EAAI,KAAK,IAAI,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,EAAI,gBAAgB,CAAA,CAAA;AAAA,EACzE,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAC/C;AACF;AASO,SAAS,uBAAA,CACd,QACA,WAAA,EACqC;AACrC,EAAA,MAAM,UAAkC,EAAC;AAEzC,EAAA,IAAI,cAAA,CAAe,MAAA,EAAQ,WAAW,CAAA,KAAM,KAAA,EAAO;AACjD,IAAA,OAAA,CAAQ,MAAA,GAAS,+BAAA;AAAA,EACnB;AAEA,EAAA,IAAI,YAAY,KAAA,EAAO;AACrB,IAAA,OAAA,CAAQ,aAAA,GAAgB,CAAA,MAAA,EAAS,WAAA,CAAY,KAAK,CAAA,CAAA;AAAA,EACpD;AAEA,EAAA,OAAO,EAAE,OAAA,EAAQ;AACnB;AAEO,SAAS,cAAA,CACd,QACA,WAAA,EACe;AACf,EAAA,IAAI,OAAO,UAAA,KAAe,WAAA,CAAY,KAAA,IAAS,CAAC,OAAO,UAAA,CAAA,EAAa;AAClE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA;AACT;;;;"}
1
+ {"version":3,"file":"core.esm.js","sources":["../../src/github/core.ts"],"sourcesContent":["/*\n * Copyright 2020 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 */\n\nimport { GithubIntegrationConfig } from './config';\nimport { parseGitUrlSafe } from '../helpers';\nimport { GithubCredentials } from './types';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://github.com/a/b/blob/branchname/path/to/c.yaml\n * to: https://api.github.com/repos/a/b/contents/path/to/c.yaml?ref=branchname\n * or: https://raw.githubusercontent.com/a/b/branchname/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getGithubFileFetchUrl(\n url: string,\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrlSafe(url);\n if (\n !owner ||\n !name ||\n !ref ||\n // GitHub is automatically redirecting tree urls to blob urls so it's\n // fine to pass a tree url.\n (filepathtype !== 'blob' &&\n filepathtype !== 'raw' &&\n filepathtype !== 'tree')\n ) {\n throw new Error('Invalid GitHub URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n if (chooseEndpoint(config, credentials) === 'api') {\n return `${config.apiBaseUrl}/repos/${owner}/${name}/contents/${pathWithoutSlash}?ref=${ref}`;\n }\n return `${config.rawBaseUrl}/${owner}/${name}/${ref}/${pathWithoutSlash}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n\nexport function chooseEndpoint(\n config: GithubIntegrationConfig,\n credentials: GithubCredentials,\n): 'api' | 'raw' {\n if (config.apiBaseUrl && (credentials.token || !config.rawBaseUrl)) {\n return 'api';\n }\n return 'raw';\n}\n"],"names":[],"mappings":";;AAmCO,SAAS,qBAAA,CACd,GAAA,EACA,MAAA,EACA,WAAA,EACQ;AACR,EAAA,IAAI;AACF,IAAA,MAAM,EAAE,OAAO,IAAA,EAAM,GAAA,EAAK,cAAc,QAAA,EAAS,GAAI,gBAAgB,GAAG,CAAA;AACxE,IAAA,IACE,CAAC,KAAA,IACD,CAAC,IAAA,IACD,CAAC,GAAA;AAAA;AAAA,IAGA,YAAA,KAAiB,MAAA,IAChB,YAAA,KAAiB,KAAA,IACjB,iBAAiB,MAAA,EACnB;AACA,MAAA,MAAM,IAAI,MAAM,iCAAiC,CAAA;AAAA,IACnD;AAEA,IAAA,MAAM,gBAAA,GAAmB,QAAA,CAAS,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AACnD,IAAA,IAAI,cAAA,CAAe,MAAA,EAAQ,WAAW,CAAA,KAAM,KAAA,EAAO;AACjD,MAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,OAAA,EAAU,KAAK,IAAI,IAAI,CAAA,UAAA,EAAa,gBAAgB,CAAA,KAAA,EAAQ,GAAG,CAAA,CAAA;AAAA,IAC5F;AACA,IAAA,OAAO,CAAA,EAAG,MAAA,CAAO,UAAU,CAAA,CAAA,EAAI,KAAK,IAAI,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,EAAI,gBAAgB,CAAA,CAAA;AAAA,EACzE,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAC/C;AACF;AAEO,SAAS,cAAA,CACd,QACA,WAAA,EACe;AACf,EAAA,IAAI,OAAO,UAAA,KAAe,WAAA,CAAY,KAAA,IAAS,CAAC,OAAO,UAAA,CAAA,EAAa;AAClE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA;AACT;;;;"}
@@ -7,6 +7,27 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
7
7
 
8
8
  var parseGitUrl__default = /*#__PURE__*/_interopDefaultCompat(parseGitUrl);
9
9
 
10
+ function parseGitUrlSafe(url) {
11
+ const parsed = parseGitUrl__default.default(url);
12
+ if (parsed.filepath) {
13
+ let decoded = parsed.filepath;
14
+ let previous;
15
+ do {
16
+ previous = decoded;
17
+ try {
18
+ decoded = decodeURIComponent(decoded);
19
+ } catch {
20
+ break;
21
+ }
22
+ } while (decoded !== previous);
23
+ if (decoded.split("/").some((segment) => segment === ".." || segment === ".")) {
24
+ throw new Error(
25
+ "Invalid SCM URL: path traversal is not allowed in the URL"
26
+ );
27
+ }
28
+ }
29
+ return parsed;
30
+ }
10
31
  function isValidHost(host) {
11
32
  const check = new URL("http://example.com");
12
33
  check.host = host;
@@ -47,7 +68,7 @@ function defaultScmResolveUrl(options) {
47
68
  }
48
69
  let updated;
49
70
  if (url.startsWith("/")) {
50
- const { href, filepath } = parseGitUrl__default.default(base);
71
+ const { href, filepath } = parseGitUrlSafe(base);
51
72
  updated = new URL(href);
52
73
  const repoRootPath = lodash.trimEnd(
53
74
  updated.pathname.substring(0, updated.pathname.length - filepath.length),
@@ -68,4 +89,5 @@ exports.basicIntegrations = basicIntegrations;
68
89
  exports.defaultScmResolveUrl = defaultScmResolveUrl;
69
90
  exports.isValidHost = isValidHost;
70
91
  exports.isValidUrl = isValidUrl;
92
+ exports.parseGitUrlSafe = parseGitUrlSafe;
71
93
  //# sourceMappingURL=helpers.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs.js","sources":["../src/helpers.ts"],"sourcesContent":["/*\n * Copyright 2020 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 */\n\nimport parseGitUrl from 'git-url-parse';\nimport { trimEnd } from 'lodash';\nimport { ScmIntegration, ScmIntegrationsGroup } from './types';\n\n/** Checks whether the given argument is a valid URL hostname */\nexport function isValidHost(host: string): boolean {\n const check = new URL('http://example.com');\n check.host = host;\n return check.host === host;\n}\n\n/** Checks whether the given argument is a valid URL */\nexport function isValidUrl(url: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function basicIntegrations<T extends ScmIntegration>(\n integrations: T[],\n getHost: (integration: T) => string,\n): ScmIntegrationsGroup<T> {\n return {\n list(): T[] {\n return integrations;\n },\n byUrl(url: string | URL): T | undefined {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n return integrations.find(i => getHost(i) === parsed.host);\n } catch {\n return undefined;\n }\n },\n byHost(host: string): T | undefined {\n return integrations.find(i => getHost(i) === host);\n },\n };\n}\n\n/**\n * Default implementation of {@link ScmIntegration} `resolveUrl`, that only\n * works with URL pathname based providers.\n *\n * @public\n */\nexport function defaultScmResolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n}): string {\n const { url, base, lineNumber } = options;\n\n // If it is a fully qualified URL - then return it verbatim\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return url;\n } catch {\n // ignore intentionally\n }\n\n let updated: URL;\n\n if (url.startsWith('/')) {\n // If it is an absolute path, move relative to the repo root\n const { href, filepath } = parseGitUrl(base);\n\n updated = new URL(href);\n\n const repoRootPath = trimEnd(\n updated.pathname.substring(0, updated.pathname.length - filepath.length),\n '/',\n );\n updated.pathname = `${repoRootPath}${url}`;\n } else {\n // For relative URLs, just let the default URL constructor handle the\n // resolving. Note that this essentially will treat the last segment of the\n // base as a file - NOT a folder - unless the url ends in a slash.\n updated = new URL(url, base);\n }\n\n updated.search = new URL(base).search;\n if (lineNumber) {\n updated.hash = `L${lineNumber}`;\n }\n return updated.toString();\n}\n\n/**\n * Sets up handlers for request mocking\n *\n * Copied from test-utils, as that is a frontend-only package\n *\n * @param worker - service worker\n */\nexport function registerMswTestHooks(worker: {\n listen: (t: any) => void;\n close: () => void;\n resetHandlers: () => void;\n}) {\n beforeAll(() => worker.listen({ onUnhandledRequest: 'error' }));\n afterAll(() => worker.close());\n afterEach(() => worker.resetHandlers());\n}\n"],"names":["parseGitUrl","trimEnd"],"mappings":";;;;;;;;;AAqBO,SAAS,YAAY,IAAA,EAAuB;AACjD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,IAAA,MAAM,EAAE,IAAA,EAAM,QAAA,EAAS,GAAIA,6BAAY,IAAI,CAAA;AAE3C,IAAA,OAAA,GAAU,IAAI,IAAI,IAAI,CAAA;AAEtB,IAAA,MAAM,YAAA,GAAeC,cAAA;AAAA,MACnB,OAAA,CAAQ,SAAS,SAAA,CAAU,CAAA,EAAG,QAAQ,QAAA,CAAS,MAAA,GAAS,SAAS,MAAM,CAAA;AAAA,MACvE;AAAA,KACF;AACA,IAAA,OAAA,CAAQ,QAAA,GAAW,CAAA,EAAG,YAAY,CAAA,EAAG,GAAG,CAAA,CAAA;AAAA,EAC1C,CAAA,MAAO;AAIL,IAAA,OAAA,GAAU,IAAI,GAAA,CAAI,GAAA,EAAK,IAAI,CAAA;AAAA,EAC7B;AAEA,EAAA,OAAA,CAAQ,MAAA,GAAS,IAAI,GAAA,CAAI,IAAI,CAAA,CAAE,MAAA;AAC/B,EAAA,IAAI,UAAA,EAAY;AACd,IAAA,OAAA,CAAQ,IAAA,GAAO,IAAI,UAAU,CAAA,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,QAAQ,QAAA,EAAS;AAC1B;;;;;;;"}
1
+ {"version":3,"file":"helpers.cjs.js","sources":["../src/helpers.ts"],"sourcesContent":["/*\n * Copyright 2020 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 */\n\nimport parseGitUrl from 'git-url-parse';\nimport { trimEnd } from 'lodash';\nimport { ScmIntegration, ScmIntegrationsGroup } from './types';\n\n/**\n * Wraps git-url-parse and rejects URLs whose filepath contains path traversal\n * segments. Without this check, a URL like\n * `https://github.com/o/r/blob/main/%2e%2e%2f%2e%2e%2fuser/repos` would be\n * decoded to `../../user/repos` and could escape the expected API path when\n * interpolated into provider API URLs.\n */\nexport function parseGitUrlSafe(url: string) {\n const parsed = parseGitUrl(url);\n if (parsed.filepath) {\n let decoded = parsed.filepath;\n let previous;\n do {\n previous = decoded;\n try {\n decoded = decodeURIComponent(decoded);\n } catch {\n break;\n }\n } while (decoded !== previous);\n\n if (\n decoded.split('/').some(segment => segment === '..' || segment === '.')\n ) {\n throw new Error(\n 'Invalid SCM URL: path traversal is not allowed in the URL',\n );\n }\n }\n return parsed;\n}\n\n/** Checks whether the given argument is a valid URL hostname */\nexport function isValidHost(host: string): boolean {\n const check = new URL('http://example.com');\n check.host = host;\n return check.host === host;\n}\n\n/** Checks whether the given argument is a valid URL */\nexport function isValidUrl(url: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function basicIntegrations<T extends ScmIntegration>(\n integrations: T[],\n getHost: (integration: T) => string,\n): ScmIntegrationsGroup<T> {\n return {\n list(): T[] {\n return integrations;\n },\n byUrl(url: string | URL): T | undefined {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n return integrations.find(i => getHost(i) === parsed.host);\n } catch {\n return undefined;\n }\n },\n byHost(host: string): T | undefined {\n return integrations.find(i => getHost(i) === host);\n },\n };\n}\n\n/**\n * Default implementation of {@link ScmIntegration} `resolveUrl`, that only\n * works with URL pathname based providers.\n *\n * @public\n */\nexport function defaultScmResolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n}): string {\n const { url, base, lineNumber } = options;\n\n // If it is a fully qualified URL - then return it verbatim\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return url;\n } catch {\n // ignore intentionally\n }\n\n let updated: URL;\n\n if (url.startsWith('/')) {\n // If it is an absolute path, move relative to the repo root\n const { href, filepath } = parseGitUrlSafe(base);\n\n updated = new URL(href);\n\n const repoRootPath = trimEnd(\n updated.pathname.substring(0, updated.pathname.length - filepath.length),\n '/',\n );\n updated.pathname = `${repoRootPath}${url}`;\n } else {\n // For relative URLs, just let the default URL constructor handle the\n // resolving. Note that this essentially will treat the last segment of the\n // base as a file - NOT a folder - unless the url ends in a slash.\n updated = new URL(url, base);\n }\n\n updated.search = new URL(base).search;\n if (lineNumber) {\n updated.hash = `L${lineNumber}`;\n }\n return updated.toString();\n}\n\n/**\n * Sets up handlers for request mocking\n *\n * Copied from test-utils, as that is a frontend-only package\n *\n * @param worker - service worker\n */\nexport function registerMswTestHooks(worker: {\n listen: (t: any) => void;\n close: () => void;\n resetHandlers: () => void;\n}) {\n beforeAll(() => worker.listen({ onUnhandledRequest: 'error' }));\n afterAll(() => worker.close());\n afterEach(() => worker.resetHandlers());\n}\n"],"names":["parseGitUrl","trimEnd"],"mappings":";;;;;;;;;AA2BO,SAAS,gBAAgB,GAAA,EAAa;AAC3C,EAAA,MAAM,MAAA,GAASA,6BAAY,GAAG,CAAA;AAC9B,EAAA,IAAI,OAAO,QAAA,EAAU;AACnB,IAAA,IAAI,UAAU,MAAA,CAAO,QAAA;AACrB,IAAA,IAAI,QAAA;AACJ,IAAA,GAAG;AACD,MAAA,QAAA,GAAW,OAAA;AACX,MAAA,IAAI;AACF,QAAA,OAAA,GAAU,mBAAmB,OAAO,CAAA;AAAA,MACtC,CAAA,CAAA,MAAQ;AACN,QAAA;AAAA,MACF;AAAA,IACF,SAAS,OAAA,KAAY,QAAA;AAErB,IAAA,IACE,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,CAAE,IAAA,CAAK,aAAW,OAAA,KAAY,IAAA,IAAQ,OAAA,KAAY,GAAG,CAAA,EACtE;AACA,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAGO,SAAS,YAAY,IAAA,EAAuB;AACjD,EAAA,MAAM,KAAA,GAAQ,IAAI,GAAA,CAAI,oBAAoB,CAAA;AAC1C,EAAA,KAAA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IAAA,OAAA,GAAU,IAAI,IAAI,IAAI,CAAA;AAEtB,IAAA,MAAM,YAAA,GAAeC,cAAA;AAAA,MACnB,OAAA,CAAQ,SAAS,SAAA,CAAU,CAAA,EAAG,QAAQ,QAAA,CAAS,MAAA,GAAS,SAAS,MAAM,CAAA;AAAA,MACvE;AAAA,KACF;AACA,IAAA,OAAA,CAAQ,QAAA,GAAW,CAAA,EAAG,YAAY,CAAA,EAAG,GAAG,CAAA,CAAA;AAAA,EAC1C,CAAA,MAAO;AAIL,IAAA,OAAA,GAAU,IAAI,GAAA,CAAI,GAAA,EAAK,IAAI,CAAA;AAAA,EAC7B;AAEA,EAAA,OAAA,CAAQ,MAAA,GAAS,IAAI,GAAA,CAAI,IAAI,CAAA,CAAE,MAAA;AAC/B,EAAA,IAAI,UAAA,EAAY;AACd,IAAA,OAAA,CAAQ,IAAA,GAAO,IAAI,UAAU,CAAA,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,QAAQ,QAAA,EAAS;AAC1B;;;;;;;;"}
@@ -1,6 +1,27 @@
1
1
  import parseGitUrl from 'git-url-parse';
2
2
  import { trimEnd } from 'lodash';
3
3
 
4
+ function parseGitUrlSafe(url) {
5
+ const parsed = parseGitUrl(url);
6
+ if (parsed.filepath) {
7
+ let decoded = parsed.filepath;
8
+ let previous;
9
+ do {
10
+ previous = decoded;
11
+ try {
12
+ decoded = decodeURIComponent(decoded);
13
+ } catch {
14
+ break;
15
+ }
16
+ } while (decoded !== previous);
17
+ if (decoded.split("/").some((segment) => segment === ".." || segment === ".")) {
18
+ throw new Error(
19
+ "Invalid SCM URL: path traversal is not allowed in the URL"
20
+ );
21
+ }
22
+ }
23
+ return parsed;
24
+ }
4
25
  function isValidHost(host) {
5
26
  const check = new URL("http://example.com");
6
27
  check.host = host;
@@ -41,7 +62,7 @@ function defaultScmResolveUrl(options) {
41
62
  }
42
63
  let updated;
43
64
  if (url.startsWith("/")) {
44
- const { href, filepath } = parseGitUrl(base);
65
+ const { href, filepath } = parseGitUrlSafe(base);
45
66
  updated = new URL(href);
46
67
  const repoRootPath = trimEnd(
47
68
  updated.pathname.substring(0, updated.pathname.length - filepath.length),
@@ -58,5 +79,5 @@ function defaultScmResolveUrl(options) {
58
79
  return updated.toString();
59
80
  }
60
81
 
61
- export { basicIntegrations, defaultScmResolveUrl, isValidHost, isValidUrl };
82
+ export { basicIntegrations, defaultScmResolveUrl, isValidHost, isValidUrl, parseGitUrlSafe };
62
83
  //# sourceMappingURL=helpers.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.esm.js","sources":["../src/helpers.ts"],"sourcesContent":["/*\n * Copyright 2020 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 */\n\nimport parseGitUrl from 'git-url-parse';\nimport { trimEnd } from 'lodash';\nimport { ScmIntegration, ScmIntegrationsGroup } from './types';\n\n/** Checks whether the given argument is a valid URL hostname */\nexport function isValidHost(host: string): boolean {\n const check = new URL('http://example.com');\n check.host = host;\n return check.host === host;\n}\n\n/** Checks whether the given argument is a valid URL */\nexport function isValidUrl(url: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function basicIntegrations<T extends ScmIntegration>(\n integrations: T[],\n getHost: (integration: T) => string,\n): ScmIntegrationsGroup<T> {\n return {\n list(): T[] {\n return integrations;\n },\n byUrl(url: string | URL): T | undefined {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n return integrations.find(i => getHost(i) === parsed.host);\n } catch {\n return undefined;\n }\n },\n byHost(host: string): T | undefined {\n return integrations.find(i => getHost(i) === host);\n },\n };\n}\n\n/**\n * Default implementation of {@link ScmIntegration} `resolveUrl`, that only\n * works with URL pathname based providers.\n *\n * @public\n */\nexport function defaultScmResolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n}): string {\n const { url, base, lineNumber } = options;\n\n // If it is a fully qualified URL - then return it verbatim\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return url;\n } catch {\n // ignore intentionally\n }\n\n let updated: URL;\n\n if (url.startsWith('/')) {\n // If it is an absolute path, move relative to the repo root\n const { href, filepath } = parseGitUrl(base);\n\n updated = new URL(href);\n\n const repoRootPath = trimEnd(\n updated.pathname.substring(0, updated.pathname.length - filepath.length),\n '/',\n );\n updated.pathname = `${repoRootPath}${url}`;\n } else {\n // For relative URLs, just let the default URL constructor handle the\n // resolving. Note that this essentially will treat the last segment of the\n // base as a file - NOT a folder - unless the url ends in a slash.\n updated = new URL(url, base);\n }\n\n updated.search = new URL(base).search;\n if (lineNumber) {\n updated.hash = `L${lineNumber}`;\n }\n return updated.toString();\n}\n\n/**\n * Sets up handlers for request mocking\n *\n * Copied from test-utils, as that is a frontend-only package\n *\n * @param worker - service worker\n */\nexport function registerMswTestHooks(worker: {\n listen: (t: any) => void;\n close: () => void;\n resetHandlers: () => void;\n}) {\n beforeAll(() => worker.listen({ onUnhandledRequest: 'error' }));\n afterAll(() => worker.close());\n afterEach(() => worker.resetHandlers());\n}\n"],"names":[],"mappings":";;;AAqBO,SAAS,YAAY,IAAA,EAAuB;AACjD,EAAA,MAAM,KAAA,GAAQ,IAAI,GAAA,CAAI,oBAAoB,CAAA;AAC1C,EAAA,KAAA,CAAM,IAAA,GAAO,IAAA;AACb,EAAA,OAAO,MAAM,IAAA,KAAS,IAAA;AACxB;AAGO,SAAS,WAAW,GAAA,EAAsB;AAC/C,EAAA,IAAI;AAEF,IAAA,IAAI,IAAI,GAAG,CAAA;AACX,IAAA,OAAO,IAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAA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W,CAAA,EAAG,YAAY,CAAA,EAAG,GAAG,CAAA,CAAA;AAAA,EAC1C,CAAA,MAAO;AAIL,IAAA,OAAA,GAAU,IAAI,GAAA,CAAI,GAAA,EAAK,IAAI,CAAA;AAAA,EAC7B;AAEA,EAAA,OAAA,CAAQ,MAAA,GAAS,IAAI,GAAA,CAAI,IAAI,CAAA,CAAE,MAAA;AAC/B,EAAA,IAAI,UAAA,EAAY;AACd,IAAA,OAAA,CAAQ,IAAA,GAAO,IAAI,UAAU,CAAA,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,QAAQ,QAAA,EAAS;AAC1B;;;;"}
1
+ {"version":3,"file":"helpers.esm.js","sources":["../src/helpers.ts"],"sourcesContent":["/*\n * Copyright 2020 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 */\n\nimport parseGitUrl from 'git-url-parse';\nimport { trimEnd } from 'lodash';\nimport { ScmIntegration, ScmIntegrationsGroup } from './types';\n\n/**\n * Wraps git-url-parse and rejects URLs whose filepath contains path traversal\n * segments. Without this check, a URL like\n * `https://github.com/o/r/blob/main/%2e%2e%2f%2e%2e%2fuser/repos` would be\n * decoded to `../../user/repos` and could escape the expected API path when\n * interpolated into provider API URLs.\n */\nexport function parseGitUrlSafe(url: string) {\n const parsed = parseGitUrl(url);\n if (parsed.filepath) {\n let decoded = parsed.filepath;\n let previous;\n do {\n previous = decoded;\n try {\n decoded = decodeURIComponent(decoded);\n } catch {\n break;\n }\n } while (decoded !== previous);\n\n if (\n decoded.split('/').some(segment => segment === '..' || segment === '.')\n ) {\n throw new Error(\n 'Invalid SCM URL: path traversal is not allowed in the URL',\n );\n }\n }\n return parsed;\n}\n\n/** Checks whether the given argument is a valid URL hostname */\nexport function isValidHost(host: string): boolean {\n const check = new URL('http://example.com');\n check.host = host;\n return check.host === host;\n}\n\n/** Checks whether the given argument is a valid URL */\nexport function isValidUrl(url: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function basicIntegrations<T extends ScmIntegration>(\n integrations: T[],\n getHost: (integration: T) => string,\n): ScmIntegrationsGroup<T> {\n return {\n list(): T[] {\n return integrations;\n },\n byUrl(url: string | URL): T | undefined {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n return integrations.find(i => getHost(i) === parsed.host);\n } catch {\n return undefined;\n }\n },\n byHost(host: string): T | undefined {\n return integrations.find(i => getHost(i) === host);\n },\n };\n}\n\n/**\n * Default implementation of {@link ScmIntegration} `resolveUrl`, that only\n * works with URL pathname based providers.\n *\n * @public\n */\nexport function defaultScmResolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n}): string {\n const { url, base, lineNumber } = options;\n\n // If it is a fully qualified URL - then return it verbatim\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return url;\n } catch {\n // ignore intentionally\n }\n\n let updated: URL;\n\n if (url.startsWith('/')) {\n // If it is an absolute path, move relative to the repo root\n const { href, filepath } = parseGitUrlSafe(base);\n\n updated = new URL(href);\n\n const repoRootPath = trimEnd(\n updated.pathname.substring(0, updated.pathname.length - filepath.length),\n '/',\n );\n updated.pathname = `${repoRootPath}${url}`;\n } else {\n // For relative URLs, just let the default URL constructor handle the\n // resolving. Note that this essentially will treat the last segment of the\n // base as a file - NOT a folder - unless the url ends in a slash.\n updated = new URL(url, base);\n }\n\n updated.search = new URL(base).search;\n if (lineNumber) {\n updated.hash = `L${lineNumber}`;\n }\n return updated.toString();\n}\n\n/**\n * Sets up handlers for request mocking\n *\n * Copied from test-utils, as that is a frontend-only package\n *\n * @param worker - service worker\n */\nexport function registerMswTestHooks(worker: {\n listen: (t: any) => void;\n close: () => void;\n resetHandlers: () => void;\n}) {\n beforeAll(() => worker.listen({ onUnhandledRequest: 'error' }));\n afterAll(() => worker.close());\n afterEach(() => worker.resetHandlers());\n}\n"],"names":[],"mappings":";;;AA2BO,SAAS,gBAAgB,GAAA,EAAa;AAC3C,EAAA,MAAM,MAAA,GAAS,YAAY,GAAG,CAAA;AAC9B,EAAA,IAAI,OAAO,QAAA,EAAU;AACnB,IAAA,IAAI,UAAU,MAAA,CAAO,QAAA;AACrB,IAAA,IAAI,QAAA;AACJ,IAAA,GAAG;AACD,MAAA,QAAA,GAAW,OAAA;AACX,MAAA,IAAI;AACF,QAAA,OAAA,GAAU,mBAAmB,OAAO,CAAA;AAAA,MACtC,CAAA,CAAA,MAAQ;AACN,QAAA;AAAA,MACF;AAAA,IACF,SAAS,OAAA,KAAY,QAAA;AAErB,IAAA,IACE,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,CAAE,IAAA,CAAK,aAAW,OAAA,KAAY,IAAA,IAAQ,OAAA,KAAY,GAAG,CAAA,EACtE;AACA,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAGO,SAAS,YAAY,IAAA,EAAuB;AACjD,EAAA,MAAM,KAAA,GAAQ,IAAI,GAAA,CAAI,oBAAoB,CAAA;AAC1C,EAAA,KAAA,CAAM,IAAA,GAAO,IAAA;AACb,EAAA,OAAO,MAAM,IAAA,KAAS,IAAA;AACxB;AAGO,SAAS,WAAW,GAAA,EAAsB;AAC/C,EAAA,IAAI;AAEF,IAAA,IAAI,IAAI,GAAG,CAAA;AACX,IAAA,OAAO,IAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT;AACF;AAEO,SAAS,iBAAA,CACd,cACA,OAAA,EACyB;AACzB,EAAA,OAAO;AAAA,IACL,IAAA,GAAY;AACV,MAAA,OAAO,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AA,CAAI,GAAA,EAAK,IAAI,CAAA;AAAA,EAC7B;AAEA,EAAA,OAAA,CAAQ,MAAA,GAAS,IAAI,GAAA,CAAI,IAAI,CAAA,CAAE,MAAA;AAC/B,EAAA,IAAI,UAAA,EAAY;AACd,IAAA,OAAA,CAAQ,IAAA,GAAO,IAAI,UAAU,CAAA,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,QAAQ,QAAA,EAAS;AAC1B;;;;"}
package/dist/index.cjs.js CHANGED
@@ -11,36 +11,32 @@ var AzureIntegration = require('./azure/AzureIntegration.cjs.js');
11
11
  var config$3 = require('./azure/config.cjs.js');
12
12
  var core = require('./azure/core.cjs.js');
13
13
  var DefaultAzureDevOpsCredentialsProvider = require('./azure/DefaultAzureDevOpsCredentialsProvider.cjs.js');
14
- var deprecated = require('./azure/deprecated.cjs.js');
15
- var BitbucketIntegration = require('./bitbucket/BitbucketIntegration.cjs.js');
16
- var config$4 = require('./bitbucket/config.cjs.js');
17
- var core$1 = require('./bitbucket/core.cjs.js');
18
14
  var BitbucketCloudIntegration = require('./bitbucketCloud/BitbucketCloudIntegration.cjs.js');
19
- var config$5 = require('./bitbucketCloud/config.cjs.js');
20
- var core$2 = require('./bitbucketCloud/core.cjs.js');
15
+ var config$4 = require('./bitbucketCloud/config.cjs.js');
16
+ var core$1 = require('./bitbucketCloud/core.cjs.js');
21
17
  var BitbucketServerIntegration = require('./bitbucketServer/BitbucketServerIntegration.cjs.js');
22
- var config$6 = require('./bitbucketServer/config.cjs.js');
23
- var core$3 = require('./bitbucketServer/core.cjs.js');
18
+ var config$5 = require('./bitbucketServer/config.cjs.js');
19
+ var core$2 = require('./bitbucketServer/core.cjs.js');
24
20
  var GerritIntegration = require('./gerrit/GerritIntegration.cjs.js');
25
- var config$7 = require('./gerrit/config.cjs.js');
26
- var core$4 = require('./gerrit/core.cjs.js');
21
+ var config$6 = require('./gerrit/config.cjs.js');
22
+ var core$3 = require('./gerrit/core.cjs.js');
27
23
  var GiteaIntegration = require('./gitea/GiteaIntegration.cjs.js');
28
- var core$5 = require('./gitea/core.cjs.js');
29
- var config$8 = require('./gitea/config.cjs.js');
30
- var config$9 = require('./github/config.cjs.js');
31
- var core$6 = require('./github/core.cjs.js');
24
+ var core$4 = require('./gitea/core.cjs.js');
25
+ var config$7 = require('./gitea/config.cjs.js');
26
+ var config$8 = require('./github/config.cjs.js');
27
+ var core$5 = require('./github/core.cjs.js');
32
28
  var DefaultGithubCredentialsProvider = require('./github/DefaultGithubCredentialsProvider.cjs.js');
33
29
  var SingleInstanceGithubCredentialsProvider = require('./github/SingleInstanceGithubCredentialsProvider.cjs.js');
34
30
  var GithubIntegration = require('./github/GithubIntegration.cjs.js');
35
- var config$a = require('./gitlab/config.cjs.js');
36
- var core$7 = require('./gitlab/core.cjs.js');
31
+ var config$9 = require('./gitlab/config.cjs.js');
32
+ var core$6 = require('./gitlab/core.cjs.js');
37
33
  var GitLabIntegration = require('./gitlab/GitLabIntegration.cjs.js');
38
34
  var DefaultGitlabCredentialsProvider = require('./gitlab/DefaultGitlabCredentialsProvider.cjs.js');
39
- var config$b = require('./googleGcs/config.cjs.js');
35
+ var config$a = require('./googleGcs/config.cjs.js');
40
36
  var GoogleGcsIntegration = require('./googleGcs/GoogleGcsIntegration.cjs.js');
41
37
  var HarnessIntegration = require('./harness/HarnessIntegration.cjs.js');
42
- var core$8 = require('./harness/core.cjs.js');
43
- var config$c = require('./harness/config.cjs.js');
38
+ var core$7 = require('./harness/core.cjs.js');
39
+ var config$b = require('./harness/config.cjs.js');
44
40
  var helpers = require('./helpers.cjs.js');
45
41
  var ScmIntegrations = require('./ScmIntegrations.cjs.js');
46
42
 
@@ -63,77 +59,66 @@ exports.getAzureCommitsUrl = core.getAzureCommitsUrl;
63
59
  exports.getAzureDownloadUrl = core.getAzureDownloadUrl;
64
60
  exports.getAzureFileFetchUrl = core.getAzureFileFetchUrl;
65
61
  exports.DefaultAzureDevOpsCredentialsProvider = DefaultAzureDevOpsCredentialsProvider.DefaultAzureDevOpsCredentialsProvider;
66
- exports.getAzureRequestOptions = deprecated.getAzureRequestOptions;
67
- exports.BitbucketIntegration = BitbucketIntegration.BitbucketIntegration;
68
- exports.readBitbucketIntegrationConfig = config$4.readBitbucketIntegrationConfig;
69
- exports.readBitbucketIntegrationConfigs = config$4.readBitbucketIntegrationConfigs;
70
- exports.getBitbucketDefaultBranch = core$1.getBitbucketDefaultBranch;
71
- exports.getBitbucketDownloadUrl = core$1.getBitbucketDownloadUrl;
72
- exports.getBitbucketFileFetchUrl = core$1.getBitbucketFileFetchUrl;
73
- exports.getBitbucketRequestOptions = core$1.getBitbucketRequestOptions;
74
62
  exports.BitbucketCloudIntegration = BitbucketCloudIntegration.BitbucketCloudIntegration;
75
- exports.readBitbucketCloudIntegrationConfig = config$5.readBitbucketCloudIntegrationConfig;
76
- exports.readBitbucketCloudIntegrationConfigs = config$5.readBitbucketCloudIntegrationConfigs;
77
- exports.getBitbucketCloudDefaultBranch = core$2.getBitbucketCloudDefaultBranch;
78
- exports.getBitbucketCloudDownloadUrl = core$2.getBitbucketCloudDownloadUrl;
79
- exports.getBitbucketCloudFileFetchUrl = core$2.getBitbucketCloudFileFetchUrl;
80
- exports.getBitbucketCloudOAuthToken = core$2.getBitbucketCloudOAuthToken;
81
- exports.getBitbucketCloudRequestOptions = core$2.getBitbucketCloudRequestOptions;
63
+ exports.readBitbucketCloudIntegrationConfig = config$4.readBitbucketCloudIntegrationConfig;
64
+ exports.readBitbucketCloudIntegrationConfigs = config$4.readBitbucketCloudIntegrationConfigs;
65
+ exports.getBitbucketCloudDefaultBranch = core$1.getBitbucketCloudDefaultBranch;
66
+ exports.getBitbucketCloudDownloadUrl = core$1.getBitbucketCloudDownloadUrl;
67
+ exports.getBitbucketCloudFileFetchUrl = core$1.getBitbucketCloudFileFetchUrl;
68
+ exports.getBitbucketCloudOAuthToken = core$1.getBitbucketCloudOAuthToken;
69
+ exports.getBitbucketCloudRequestOptions = core$1.getBitbucketCloudRequestOptions;
82
70
  exports.BitbucketServerIntegration = BitbucketServerIntegration.BitbucketServerIntegration;
83
- exports.readBitbucketServerIntegrationConfig = config$6.readBitbucketServerIntegrationConfig;
84
- exports.readBitbucketServerIntegrationConfigs = config$6.readBitbucketServerIntegrationConfigs;
85
- exports.getBitbucketServerDefaultBranch = core$3.getBitbucketServerDefaultBranch;
86
- exports.getBitbucketServerDownloadUrl = core$3.getBitbucketServerDownloadUrl;
87
- exports.getBitbucketServerFileFetchUrl = core$3.getBitbucketServerFileFetchUrl;
88
- exports.getBitbucketServerRequestOptions = core$3.getBitbucketServerRequestOptions;
71
+ exports.readBitbucketServerIntegrationConfig = config$5.readBitbucketServerIntegrationConfig;
72
+ exports.readBitbucketServerIntegrationConfigs = config$5.readBitbucketServerIntegrationConfigs;
73
+ exports.getBitbucketServerDefaultBranch = core$2.getBitbucketServerDefaultBranch;
74
+ exports.getBitbucketServerDownloadUrl = core$2.getBitbucketServerDownloadUrl;
75
+ exports.getBitbucketServerFileFetchUrl = core$2.getBitbucketServerFileFetchUrl;
76
+ exports.getBitbucketServerRequestOptions = core$2.getBitbucketServerRequestOptions;
89
77
  exports.GerritIntegration = GerritIntegration.GerritIntegration;
90
- exports.readGerritIntegrationConfig = config$7.readGerritIntegrationConfig;
91
- exports.readGerritIntegrationConfigs = config$7.readGerritIntegrationConfigs;
92
- exports.buildGerritGitilesArchiveUrl = core$4.buildGerritGitilesArchiveUrl;
93
- exports.buildGerritGitilesArchiveUrlFromLocation = core$4.buildGerritGitilesArchiveUrlFromLocation;
94
- exports.getGerritBranchApiUrl = core$4.getGerritBranchApiUrl;
95
- exports.getGerritCloneRepoUrl = core$4.getGerritCloneRepoUrl;
96
- exports.getGerritFileContentsApiUrl = core$4.getGerritFileContentsApiUrl;
97
- exports.getGerritProjectsApiUrl = core$4.getGerritProjectsApiUrl;
98
- exports.getGerritRequestOptions = core$4.getGerritRequestOptions;
99
- exports.getGitilesAuthenticationUrl = core$4.getGitilesAuthenticationUrl;
100
- exports.parseGerritGitilesUrl = core$4.parseGerritGitilesUrl;
101
- exports.parseGerritJsonResponse = core$4.parseGerritJsonResponse;
102
- exports.parseGitilesUrlRef = core$4.parseGitilesUrlRef;
78
+ exports.readGerritIntegrationConfig = config$6.readGerritIntegrationConfig;
79
+ exports.readGerritIntegrationConfigs = config$6.readGerritIntegrationConfigs;
80
+ exports.buildGerritGitilesArchiveUrlFromLocation = core$3.buildGerritGitilesArchiveUrlFromLocation;
81
+ exports.getGerritBranchApiUrl = core$3.getGerritBranchApiUrl;
82
+ exports.getGerritCloneRepoUrl = core$3.getGerritCloneRepoUrl;
83
+ exports.getGerritFileContentsApiUrl = core$3.getGerritFileContentsApiUrl;
84
+ exports.getGerritProjectsApiUrl = core$3.getGerritProjectsApiUrl;
85
+ exports.getGerritRequestOptions = core$3.getGerritRequestOptions;
86
+ exports.getGitilesAuthenticationUrl = core$3.getGitilesAuthenticationUrl;
87
+ exports.parseGerritJsonResponse = core$3.parseGerritJsonResponse;
88
+ exports.parseGitilesUrlRef = core$3.parseGitilesUrlRef;
103
89
  exports.GiteaIntegration = GiteaIntegration.GiteaIntegration;
104
- exports.getGiteaArchiveUrl = core$5.getGiteaArchiveUrl;
105
- exports.getGiteaEditContentsUrl = core$5.getGiteaEditContentsUrl;
106
- exports.getGiteaFileContentsUrl = core$5.getGiteaFileContentsUrl;
107
- exports.getGiteaLatestCommitUrl = core$5.getGiteaLatestCommitUrl;
108
- exports.getGiteaRequestOptions = core$5.getGiteaRequestOptions;
109
- exports.parseGiteaUrl = core$5.parseGiteaUrl;
110
- exports.readGiteaConfig = config$8.readGiteaConfig;
111
- exports.readGithubIntegrationConfig = config$9.readGithubIntegrationConfig;
112
- exports.readGithubIntegrationConfigs = config$9.readGithubIntegrationConfigs;
113
- exports.getGitHubRequestOptions = core$6.getGitHubRequestOptions;
114
- exports.getGithubFileFetchUrl = core$6.getGithubFileFetchUrl;
90
+ exports.getGiteaArchiveUrl = core$4.getGiteaArchiveUrl;
91
+ exports.getGiteaEditContentsUrl = core$4.getGiteaEditContentsUrl;
92
+ exports.getGiteaFileContentsUrl = core$4.getGiteaFileContentsUrl;
93
+ exports.getGiteaLatestCommitUrl = core$4.getGiteaLatestCommitUrl;
94
+ exports.getGiteaRequestOptions = core$4.getGiteaRequestOptions;
95
+ exports.parseGiteaUrl = core$4.parseGiteaUrl;
96
+ exports.readGiteaConfig = config$7.readGiteaConfig;
97
+ exports.readGithubIntegrationConfig = config$8.readGithubIntegrationConfig;
98
+ exports.readGithubIntegrationConfigs = config$8.readGithubIntegrationConfigs;
99
+ exports.getGithubFileFetchUrl = core$5.getGithubFileFetchUrl;
115
100
  exports.DefaultGithubCredentialsProvider = DefaultGithubCredentialsProvider.DefaultGithubCredentialsProvider;
116
101
  exports.GithubAppCredentialsMux = SingleInstanceGithubCredentialsProvider.GithubAppCredentialsMux;
117
102
  exports.SingleInstanceGithubCredentialsProvider = SingleInstanceGithubCredentialsProvider.SingleInstanceGithubCredentialsProvider;
118
103
  exports.GithubIntegration = GithubIntegration.GithubIntegration;
119
104
  exports.replaceGithubUrlType = GithubIntegration.replaceGithubUrlType;
120
- exports.getGitLabIntegrationRelativePath = config$a.getGitLabIntegrationRelativePath;
121
- exports.readGitLabIntegrationConfig = config$a.readGitLabIntegrationConfig;
122
- exports.readGitLabIntegrationConfigs = config$a.readGitLabIntegrationConfigs;
123
- exports.getGitLabFileFetchUrl = core$7.getGitLabFileFetchUrl;
124
- exports.getGitLabRequestOptions = core$7.getGitLabRequestOptions;
105
+ exports.getGitLabIntegrationRelativePath = config$9.getGitLabIntegrationRelativePath;
106
+ exports.readGitLabIntegrationConfig = config$9.readGitLabIntegrationConfig;
107
+ exports.readGitLabIntegrationConfigs = config$9.readGitLabIntegrationConfigs;
108
+ exports.getGitLabFileFetchUrl = core$6.getGitLabFileFetchUrl;
109
+ exports.getGitLabRequestOptions = core$6.getGitLabRequestOptions;
125
110
  exports.GitLabIntegration = GitLabIntegration.GitLabIntegration;
126
111
  exports.replaceGitLabUrlType = GitLabIntegration.replaceGitLabUrlType;
127
112
  exports.DefaultGitlabCredentialsProvider = DefaultGitlabCredentialsProvider.DefaultGitlabCredentialsProvider;
128
- exports.readGoogleGcsIntegrationConfig = config$b.readGoogleGcsIntegrationConfig;
113
+ exports.readGoogleGcsIntegrationConfig = config$a.readGoogleGcsIntegrationConfig;
129
114
  exports.GoogleGcsIntegration = GoogleGcsIntegration.GoogleGcsIntegration;
130
115
  exports.HarnessIntegration = HarnessIntegration.HarnessIntegration;
131
- exports.getHarnessArchiveUrl = core$8.getHarnessArchiveUrl;
132
- exports.getHarnessFileContentsUrl = core$8.getHarnessFileContentsUrl;
133
- exports.getHarnessLatestCommitUrl = core$8.getHarnessLatestCommitUrl;
134
- exports.getHarnessRequestOptions = core$8.getHarnessRequestOptions;
135
- exports.parseHarnessUrl = core$8.parseHarnessUrl;
136
- exports.readHarnessConfig = config$c.readHarnessConfig;
116
+ exports.getHarnessArchiveUrl = core$7.getHarnessArchiveUrl;
117
+ exports.getHarnessFileContentsUrl = core$7.getHarnessFileContentsUrl;
118
+ exports.getHarnessLatestCommitUrl = core$7.getHarnessLatestCommitUrl;
119
+ exports.getHarnessRequestOptions = core$7.getHarnessRequestOptions;
120
+ exports.parseHarnessUrl = core$7.parseHarnessUrl;
121
+ exports.readHarnessConfig = config$b.readHarnessConfig;
137
122
  exports.defaultScmResolveUrl = helpers.defaultScmResolveUrl;
138
123
  exports.ScmIntegrations = ScmIntegrations.ScmIntegrations;
139
124
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}