@backstage/integration 1.20.0 → 2.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/config.d.ts +25 -60
- package/dist/ScmIntegrations.cjs.js +1 -17
- package/dist/ScmIntegrations.cjs.js.map +1 -1
- package/dist/ScmIntegrations.esm.js +1 -17
- package/dist/ScmIntegrations.esm.js.map +1 -1
- package/dist/azure/config.cjs.js +14 -35
- package/dist/azure/config.cjs.js.map +1 -1
- package/dist/azure/config.esm.js +14 -35
- package/dist/azure/config.esm.js.map +1 -1
- package/dist/gerrit/core.cjs.js +6 -33
- package/dist/gerrit/core.cjs.js.map +1 -1
- package/dist/gerrit/core.esm.js +7 -32
- package/dist/gerrit/core.esm.js.map +1 -1
- package/dist/github/core.cjs.js +0 -11
- package/dist/github/core.cjs.js.map +1 -1
- package/dist/github/core.esm.js +1 -11
- package/dist/github/core.esm.js.map +1 -1
- package/dist/gitlab/GitLabIntegration.cjs.js +69 -0
- package/dist/gitlab/GitLabIntegration.cjs.js.map +1 -1
- package/dist/gitlab/GitLabIntegration.esm.js +65 -1
- package/dist/gitlab/GitLabIntegration.esm.js.map +1 -1
- package/dist/gitlab/config.cjs.js +27 -1
- package/dist/gitlab/config.cjs.js.map +1 -1
- package/dist/gitlab/config.esm.js +27 -1
- package/dist/gitlab/config.esm.js.map +1 -1
- package/dist/gitlab/core.cjs.js +14 -42
- package/dist/gitlab/core.cjs.js.map +1 -1
- package/dist/gitlab/core.esm.js +14 -38
- package/dist/gitlab/core.esm.js.map +1 -1
- package/dist/index.cjs.js +61 -76
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +30 -225
- package/dist/index.esm.js +2 -6
- package/dist/index.esm.js.map +1 -1
- package/package.json +7 -6
- package/dist/azure/deprecated.cjs.js +0 -26
- package/dist/azure/deprecated.cjs.js.map +0 -1
- package/dist/azure/deprecated.esm.js +0 -24
- package/dist/azure/deprecated.esm.js.map +0 -1
- package/dist/bitbucket/BitbucketIntegration.cjs.js +0 -65
- package/dist/bitbucket/BitbucketIntegration.cjs.js.map +0 -1
- package/dist/bitbucket/BitbucketIntegration.esm.js +0 -59
- package/dist/bitbucket/BitbucketIntegration.esm.js.map +0 -1
- package/dist/bitbucket/config.cjs.js +0 -48
- package/dist/bitbucket/config.cjs.js.map +0 -1
- package/dist/bitbucket/config.esm.js +0 -45
- package/dist/bitbucket/config.esm.js.map +0 -1
- package/dist/bitbucket/core.cjs.js +0 -95
- package/dist/bitbucket/core.cjs.js.map +0 -1
- package/dist/bitbucket/core.esm.js +0 -85
- package/dist/bitbucket/core.esm.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.esm.js","sources":["../../src/azure/config.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 { Config } from '@backstage/config';\nimport { isValidHost } from '../helpers';\n\nconst AZURE_HOST = 'dev.azure.com';\n\n/**\n * The configuration parameters for a single Azure provider.\n *\n * @public\n */\nexport type AzureIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. \"dev.azure.com\".\n *\n * Currently only \"dev.azure.com\" is supported.\n */\n host: string;\n\n /**\n * The authorization token to use for requests.\n *\n * If no token is specified, anonymous access is used.\n *\n * @deprecated Use `credentials` instead.\n */\n token?: string;\n\n /**\n * The credential to use for requests.\n *\n * If no credential is specified anonymous access is used.\n *\n * @deprecated Use `credentials` instead.\n */\n credential?: AzureDevOpsCredential;\n\n /**\n * The credentials to use for requests. If multiple credentials are specified the first one that matches the organization is used.\n * If not organization matches the first credential without an organization is used.\n *\n * If no credentials are specified at all, either a default credential (for Azure DevOps) or anonymous access (for Azure DevOps Server) is used.\n */\n credentials?: AzureDevOpsCredential[];\n\n /**\n * Signing key for commits\n */\n commitSigningKey?: string;\n};\n\n/**\n * The kind of Azure DevOps credential.\n * @public\n */\nexport type AzureDevOpsCredentialKind =\n | 'PersonalAccessToken'\n | 'ClientSecret'\n | 'ManagedIdentity'\n | 'ManagedIdentityClientAssertion';\n\n/**\n * Common fields for the Azure DevOps credentials.\n * @public\n */\nexport type AzureCredentialBase = {\n /**\n * The kind of credential.\n */\n kind: AzureDevOpsCredentialKind;\n /**\n * The Azure DevOps organizations for which to use this credential.\n */\n organizations?: string[];\n};\n\n/**\n * A client secret credential that was generated for an App Registration.\n * @public\n */\nexport type AzureClientSecretCredential = AzureCredentialBase & {\n kind: 'ClientSecret';\n /**\n * The Entra ID tenant\n */\n tenantId: string;\n /**\n * The client id\n */\n clientId: string;\n\n /**\n * The client secret\n */\n clientSecret: string;\n};\n\n/**\n * A client assertion credential that uses a managed identity to generate a client assertion (JWT).\n * @public\n */\nexport type AzureManagedIdentityClientAssertionCredential =\n AzureCredentialBase & {\n kind: 'ManagedIdentityClientAssertion';\n /**\n * The Entra ID tenant\n */\n tenantId: string;\n\n /**\n * The client ID of the app registration you want to authenticate as.\n */\n clientId: string;\n\n /**\n * The client ID of the managed identity used to generate a client assertion (JWT).\n * Set to \"system-assigned\" to automatically use the system-assigned managed identity.\n * For user-assigned managed identities, specify the client ID of the managed identity you want to use.\n */\n managedIdentityClientId: 'system-assigned' | string;\n };\n\n/**\n * A managed identity credential.\n * @public\n */\nexport type AzureManagedIdentityCredential = AzureCredentialBase & {\n kind: 'ManagedIdentity';\n /**\n * The clientId\n */\n clientId: 'system-assigned' | string;\n};\n\n/**\n * A personal access token credential.\n * @public\n */\nexport type PersonalAccessTokenCredential = AzureCredentialBase & {\n kind: 'PersonalAccessToken';\n personalAccessToken: string;\n};\n\n/**\n * The general shape of a credential that can be used to authenticate to Azure DevOps.\n * @public\n */\nexport type AzureDevOpsCredentialLike = Omit<\n Partial<AzureClientSecretCredential> &\n Partial<AzureManagedIdentityClientAssertionCredential> &\n Partial<AzureManagedIdentityCredential> &\n Partial<PersonalAccessTokenCredential>,\n 'kind'\n>;\n\n/**\n * Credential used to authenticate to Azure DevOps.\n * @public\n */\nexport type AzureDevOpsCredential =\n | AzureClientSecretCredential\n | AzureManagedIdentityClientAssertionCredential\n | AzureManagedIdentityCredential\n | PersonalAccessTokenCredential;\n\nconst AzureDevOpsCredentialFields = [\n 'clientId',\n 'clientSecret',\n 'managedIdentityClientId',\n 'tenantId',\n 'personalAccessToken',\n] as const;\ntype AzureDevOpsCredentialField = (typeof AzureDevOpsCredentialFields)[number];\n\nconst AzureDevopsCredentialFieldMap = new Map<\n AzureDevOpsCredentialKind,\n AzureDevOpsCredentialField[]\n>([\n ['ClientSecret', ['clientId', 'clientSecret', 'tenantId']],\n ['ManagedIdentity', ['clientId']],\n [\n 'ManagedIdentityClientAssertion',\n ['clientId', 'managedIdentityClientId', 'tenantId'],\n ],\n ['PersonalAccessToken', ['personalAccessToken']],\n]);\n\nfunction asAzureDevOpsCredential(\n credential: AzureDevOpsCredentialLike,\n): AzureDevOpsCredential {\n for (const entry of AzureDevopsCredentialFieldMap.entries()) {\n const [kind, requiredFields] = entry;\n\n const forbiddenFields = AzureDevOpsCredentialFields.filter(\n field => !requiredFields.includes(field as AzureDevOpsCredentialField),\n );\n\n if (\n requiredFields.every(field => credential[field] !== undefined) &&\n forbiddenFields.every(field => credential[field] === undefined)\n ) {\n return {\n kind,\n organizations: credential.organizations,\n ...requiredFields.reduce((acc, field) => {\n acc[field] = credential[field];\n return acc;\n }, {} as Record<string, any>),\n } as AzureDevOpsCredential;\n }\n }\n throw new Error('is not a valid credential');\n}\n\n/**\n * Reads a single Azure integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readAzureIntegrationConfig(\n config: Config,\n): AzureIntegrationConfig {\n const host = config.getOptionalString('host') ?? AZURE_HOST;\n\n let credentialConfigs = config\n .getOptionalConfigArray('credentials')\n ?.map(credential => {\n const result: Partial<AzureDevOpsCredentialLike> = {\n organizations: credential.getOptionalStringArray('organizations'),\n personalAccessToken: credential\n .getOptionalString('personalAccessToken')\n ?.trim(),\n tenantId: credential.getOptionalString('tenantId')?.trim(),\n clientId: credential.getOptionalString('clientId')?.trim(),\n clientSecret: credential.getOptionalString('clientSecret')?.trim(),\n managedIdentityClientId: credential\n .getOptionalString('managedIdentityClientId')\n ?.trim(),\n };\n\n return result;\n });\n\n const token = config.getOptionalString('token')?.trim();\n\n if (\n config.getOptional('credential') !== undefined &&\n config.getOptional('credentials') !== undefined\n ) {\n throw new Error(\n `Invalid Azure integration config, 'credential' and 'credentials' cannot be used together. Use 'credentials' instead.`,\n );\n }\n\n if (\n config.getOptional('token') !== undefined &&\n config.getOptional('credentials') !== undefined\n ) {\n throw new Error(\n `Invalid Azure integration config, 'token' and 'credentials' cannot be used together. Use 'credentials' instead.`,\n );\n }\n\n if (token !== undefined) {\n const mapped = [{ personalAccessToken: token }];\n credentialConfigs = credentialConfigs?.concat(mapped) ?? mapped;\n }\n\n if (config.getOptional('credential') !== undefined) {\n const mapped = [\n {\n organizations: config.getOptionalStringArray(\n 'credential.organizations',\n ),\n token: config.getOptionalString('credential.token')?.trim(),\n tenantId: config.getOptionalString('credential.tenantId'),\n clientId: config.getOptionalString('credential.clientId'),\n clientSecret: config\n .getOptionalString('credential.clientSecret')\n ?.trim(),\n },\n ];\n credentialConfigs = credentialConfigs?.concat(mapped) ?? mapped;\n }\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid Azure integration config, '${host}' is not a valid host`,\n );\n }\n\n let credentials: AzureDevOpsCredential[] | undefined = undefined;\n if (credentialConfigs !== undefined) {\n const errors = credentialConfigs\n ?.reduce((acc, credentialConfig, index) => {\n let error: string | undefined = undefined;\n try {\n asAzureDevOpsCredential(credentialConfig);\n } catch (e) {\n error = e.message;\n }\n\n if (error !== undefined) {\n acc.push(`credential at position ${index + 1} ${error}`);\n }\n\n return acc;\n }, Array.of<string>())\n .concat(\n Object.entries(\n credentialConfigs\n .filter(\n credential =>\n credential.organizations !== undefined &&\n credential.organizations.length > 0,\n )\n .reduce((acc, credential, index) => {\n credential.organizations?.forEach(organization => {\n if (!acc[organization]) {\n acc[organization] = [];\n }\n\n acc[organization].push(index + 1);\n });\n\n return acc;\n }, {} as Record<string, number[]>),\n )\n .filter(([_, indexes]) => indexes.length > 1)\n .reduce((acc, [org, indexes]) => {\n acc.push(\n `organization ${org} is specified multiple times in credentials at positions ${indexes\n .slice(0, indexes.length - 1)\n .join(', ')} and ${indexes[indexes.length - 1]}`,\n );\n return acc;\n }, Array.of<string>()),\n );\n\n if (errors?.length > 0) {\n throw new Error(\n `Invalid Azure integration config for ${host}: ${errors.join('; ')}`,\n );\n }\n\n credentials = credentialConfigs.map(credentialConfig =>\n asAzureDevOpsCredential(credentialConfig),\n );\n\n if (\n credentials.some(\n credential => credential.kind !== 'PersonalAccessToken',\n ) &&\n host !== AZURE_HOST\n ) {\n throw new Error(\n `Invalid Azure integration config for ${host}, only personal access tokens can be used with hosts other than ${AZURE_HOST}`,\n );\n }\n\n if (\n credentials.filter(\n credential =>\n credential.organizations === undefined ||\n credential.organizations.length === 0,\n ).length > 1\n ) {\n throw new Error(\n `Invalid Azure integration config for ${host}, you cannot specify multiple credentials without organizations`,\n );\n }\n }\n\n return {\n host,\n credentials,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\n };\n}\n\n/**\n * Reads a set of Azure integration configs, and inserts some defaults for\n * public Azure if not specified.\n *\n * @param configs - All of the integration config objects\n * @public\n */\nexport function readAzureIntegrationConfigs(\n configs: Config[],\n): AzureIntegrationConfig[] {\n // First read all the explicit integrations\n const result = configs.map(readAzureIntegrationConfig);\n\n // If no explicit dev.azure.com integration was added, put one in the list as\n // a convenience\n if (!result.some(c => c.host === AZURE_HO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AK,OAAK,CAAA,CAAE,IAAA,KAAS,UAAU,CAAA,EAAG;AAC5C,IAAA,MAAA,CAAO,IAAA,CAAK,EAAE,IAAA,EAAM,UAAA,EAAY,CAAA;AAAA,EAClC;AAEA,EAAA,OAAO,MAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"config.esm.js","sources":["../../src/azure/config.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 { Config } from '@backstage/config';\nimport { isValidHost } from '../helpers';\n\nconst AZURE_HOST = 'dev.azure.com';\n\n/**\n * The configuration parameters for a single Azure provider.\n *\n * @public\n */\nexport type AzureIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. \"dev.azure.com\".\n *\n * Currently only \"dev.azure.com\" is supported.\n */\n host: string;\n\n /**\n * The credentials to use for requests. If multiple credentials are specified the first one that matches the organization is used.\n * If not organization matches the first credential without an organization is used.\n *\n * If no credentials are specified at all, either a default credential (for Azure DevOps) or anonymous access (for Azure DevOps Server) is used.\n */\n credentials?: AzureDevOpsCredential[];\n\n /**\n * Signing key for commits\n */\n commitSigningKey?: string;\n};\n\n/**\n * The kind of Azure DevOps credential.\n * @public\n */\nexport type AzureDevOpsCredentialKind =\n | 'PersonalAccessToken'\n | 'ClientSecret'\n | 'ManagedIdentity'\n | 'ManagedIdentityClientAssertion';\n\n/**\n * Common fields for the Azure DevOps credentials.\n * @public\n */\nexport type AzureCredentialBase = {\n /**\n * The kind of credential.\n */\n kind: AzureDevOpsCredentialKind;\n /**\n * The Azure DevOps organizations for which to use this credential.\n */\n organizations?: string[];\n};\n\n/**\n * A client secret credential that was generated for an App Registration.\n * @public\n */\nexport type AzureClientSecretCredential = AzureCredentialBase & {\n kind: 'ClientSecret';\n /**\n * The Entra ID tenant\n */\n tenantId: string;\n /**\n * The client id\n */\n clientId: string;\n\n /**\n * The client secret\n */\n clientSecret: string;\n};\n\n/**\n * A client assertion credential that uses a managed identity to generate a client assertion (JWT).\n * @public\n */\nexport type AzureManagedIdentityClientAssertionCredential =\n AzureCredentialBase & {\n kind: 'ManagedIdentityClientAssertion';\n /**\n * The Entra ID tenant\n */\n tenantId: string;\n\n /**\n * The client ID of the app registration you want to authenticate as.\n */\n clientId: string;\n\n /**\n * The client ID of the managed identity used to generate a client assertion (JWT).\n * Set to \"system-assigned\" to automatically use the system-assigned managed identity.\n * For user-assigned managed identities, specify the client ID of the managed identity you want to use.\n */\n managedIdentityClientId: 'system-assigned' | string;\n };\n\n/**\n * A managed identity credential.\n * @public\n */\nexport type AzureManagedIdentityCredential = AzureCredentialBase & {\n kind: 'ManagedIdentity';\n /**\n * The clientId\n */\n clientId: 'system-assigned' | string;\n};\n\n/**\n * A personal access token credential.\n * @public\n */\nexport type PersonalAccessTokenCredential = AzureCredentialBase & {\n kind: 'PersonalAccessToken';\n personalAccessToken: string;\n};\n\n/**\n * The general shape of a credential that can be used to authenticate to Azure DevOps.\n * @public\n */\nexport type AzureDevOpsCredentialLike = Omit<\n Partial<AzureClientSecretCredential> &\n Partial<AzureManagedIdentityClientAssertionCredential> &\n Partial<AzureManagedIdentityCredential> &\n Partial<PersonalAccessTokenCredential>,\n 'kind'\n>;\n\n/**\n * Credential used to authenticate to Azure DevOps.\n * @public\n */\nexport type AzureDevOpsCredential =\n | AzureClientSecretCredential\n | AzureManagedIdentityClientAssertionCredential\n | AzureManagedIdentityCredential\n | PersonalAccessTokenCredential;\n\nconst AzureDevOpsCredentialFields = [\n 'clientId',\n 'clientSecret',\n 'managedIdentityClientId',\n 'tenantId',\n 'personalAccessToken',\n] as const;\ntype AzureDevOpsCredentialField = (typeof AzureDevOpsCredentialFields)[number];\n\nconst AzureDevopsCredentialFieldMap = new Map<\n AzureDevOpsCredentialKind,\n AzureDevOpsCredentialField[]\n>([\n ['ClientSecret', ['clientId', 'clientSecret', 'tenantId']],\n ['ManagedIdentity', ['clientId']],\n [\n 'ManagedIdentityClientAssertion',\n ['clientId', 'managedIdentityClientId', 'tenantId'],\n ],\n ['PersonalAccessToken', ['personalAccessToken']],\n]);\n\nfunction asAzureDevOpsCredential(\n credential: AzureDevOpsCredentialLike,\n): AzureDevOpsCredential {\n for (const entry of AzureDevopsCredentialFieldMap.entries()) {\n const [kind, requiredFields] = entry;\n\n const forbiddenFields = AzureDevOpsCredentialFields.filter(\n field => !requiredFields.includes(field as AzureDevOpsCredentialField),\n );\n\n if (\n requiredFields.every(field => credential[field] !== undefined) &&\n forbiddenFields.every(field => credential[field] === undefined)\n ) {\n return {\n kind,\n organizations: credential.organizations,\n ...requiredFields.reduce((acc, field) => {\n acc[field] = credential[field];\n return acc;\n }, {} as Record<string, any>),\n } as AzureDevOpsCredential;\n }\n }\n throw new Error('is not a valid credential');\n}\n\n/**\n * Reads a single Azure integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readAzureIntegrationConfig(\n config: Config,\n): AzureIntegrationConfig {\n deprecatedConfigCheck(config);\n\n const host = config.getOptionalString('host') ?? AZURE_HOST;\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid Azure integration config, '${host}' is not a valid host`,\n );\n }\n\n const credentialConfigs = config\n .getOptionalConfigArray('credentials')\n ?.map(credential => {\n const result: Partial<AzureDevOpsCredentialLike> = {\n organizations: credential.getOptionalStringArray('organizations'),\n personalAccessToken: credential\n .getOptionalString('personalAccessToken')\n ?.trim(),\n tenantId: credential.getOptionalString('tenantId')?.trim(),\n clientId: credential.getOptionalString('clientId')?.trim(),\n clientSecret: credential.getOptionalString('clientSecret')?.trim(),\n managedIdentityClientId: credential\n .getOptionalString('managedIdentityClientId')\n ?.trim(),\n };\n\n return result;\n });\n\n let credentials: AzureDevOpsCredential[] | undefined = undefined;\n if (credentialConfigs !== undefined) {\n const errors = credentialConfigs\n ?.reduce((acc, credentialConfig, index) => {\n let error: string | undefined = undefined;\n try {\n asAzureDevOpsCredential(credentialConfig);\n } catch (e) {\n error = e.message;\n }\n\n if (error !== undefined) {\n acc.push(`credential at position ${index + 1} ${error}`);\n }\n\n return acc;\n }, Array.of<string>())\n .concat(\n Object.entries(\n credentialConfigs\n .filter(\n credential =>\n credential.organizations !== undefined &&\n credential.organizations.length > 0,\n )\n .reduce((acc, credential, index) => {\n credential.organizations?.forEach(organization => {\n if (!acc[organization]) {\n acc[organization] = [];\n }\n\n acc[organization].push(index + 1);\n });\n\n return acc;\n }, {} as Record<string, number[]>),\n )\n .filter(([_, indexes]) => indexes.length > 1)\n .reduce((acc, [org, indexes]) => {\n acc.push(\n `organization ${org} is specified multiple times in credentials at positions ${indexes\n .slice(0, indexes.length - 1)\n .join(', ')} and ${indexes[indexes.length - 1]}`,\n );\n return acc;\n }, Array.of<string>()),\n );\n\n if (errors?.length > 0) {\n throw new Error(\n `Invalid Azure integration config for ${host}: ${errors.join('; ')}`,\n );\n }\n\n credentials = credentialConfigs.map(credentialConfig =>\n asAzureDevOpsCredential(credentialConfig),\n );\n\n if (\n credentials.some(\n credential => credential.kind !== 'PersonalAccessToken',\n ) &&\n host !== AZURE_HOST\n ) {\n throw new Error(\n `Invalid Azure integration config for ${host}, only personal access tokens can be used with hosts other than ${AZURE_HOST}`,\n );\n }\n\n if (\n credentials.filter(\n credential =>\n credential.organizations === undefined ||\n credential.organizations.length === 0,\n ).length > 1\n ) {\n throw new Error(\n `Invalid Azure integration config for ${host}, you cannot specify multiple credentials without organizations`,\n );\n }\n }\n\n return {\n host,\n credentials,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\n };\n}\n\n/**\n * Reads a set of Azure integration configs, and inserts some defaults for\n * public Azure if not specified.\n *\n * @param configs - All of the integration config objects\n * @public\n */\nexport function readAzureIntegrationConfigs(\n configs: Config[],\n): AzureIntegrationConfig[] {\n // First read all the explicit integrations\n const result = configs.map(readAzureIntegrationConfig);\n\n // If no explicit dev.azure.com integration was added, put one in the list as\n // a convenience\n if (!result.some(c => c.host === AZURE_HOST)) {\n result.push({ host: AZURE_HOST });\n }\n\n return result;\n}\n\n/**\n * These config sections have been removed but to ensure they\n * don't leak sensitive tokens we have this check in place\n * to throw an error if found\n *\n * @internal\n * @deprecated To be removed at a later date\n */\nfunction deprecatedConfigCheck(config: Config) {\n if (config.getOptional('credential') || config.getOptional('token')) {\n throw new Error(\n `Invalid Azure integration config, 'credential' and 'token' have been removed. Use 'credentials' instead.`,\n );\n }\n}\n"],"names":[],"mappings":";;AAmBA,MAAM,UAAA,GAAa,eAAA;AA+InB,MAAM,2BAAA,GAA8B;AAAA,EAClC,UAAA;AAAA,EACA,cAAA;AAAA,EACA,yBAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAA;AAGA,MAAM,6BAAA,uBAAoC,GAAA,CAGxC;AAAA,EACA,CAAC,cAAA,EAAgB,CAAC,UAAA,EAAY,cAAA,EAAgB,UAAU,CAAC,CAAA;AAAA,EACzD,CAAC,iBAAA,EAAmB,CAAC,UAAU,CAAC,CAAA;AAAA,EAChC;AAAA,IACE,gCAAA;AAAA,IACA,CAAC,UAAA,EAAY,yBAAA,EAA2B,UAAU;AAAA,GACpD;AAAA,EACA,CAAC,qBAAA,EAAuB,CAAC,qBAAqB,CAAC;AACjD,CAAC,CAAA;AAED,SAAS,wBACP,UAAA,EACuB;AACvB,EAAA,KAAA,MAAW,KAAA,IAAS,6BAAA,CAA8B,OAAA,EAAQ,EAAG;AAC3D,IAAA,MAAM,CAAC,IAAA,EAAM,cAAc,CAAA,GAAI,KAAA;AAE/B,IAAA,MAAM,kBAAkB,2BAAA,CAA4B,MAAA;AAAA,MAClD,CAAA,KAAA,KAAS,CAAC,cAAA,CAAe,QAAA,CAAS,KAAmC;AAAA,KACvE;AAE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,IAC7B,UAAA,CAAW,cAAc,MAAA,KAAW;AAAA,KACxC,CAAE,SAAS,CAAA,EACX;AACA,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,wCAAwC,IAAI,CAAA,+DAAA;AAAA,OAC9C;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,WAAA;AAAA,IACA,gBAAA,EAAkB,MAAA,CAAO,iBAAA,CAAkB,kBAAkB;AAAA,GAC/D;AACF;AASO,SAAS,4BACd,OAAA,EAC0B;AAE1B,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,GAAA,CAAI,0BAA0B,CAAA;AAIrD,EAAA,IAAI,CAAC,MAAA,CAAO,IAAA,CAAK,OAAK,CAAA,CAAE,IAAA,KAAS,UAAU,CAAA,EAAG;AAC5C,IAAA,MAAA,CAAO,IAAA,CAAK,EAAE,IAAA,EAAM,UAAA,EAAY,CAAA;AAAA,EAClC;AAEA,EAAA,OAAO,MAAA;AACT;AAUA,SAAS,sBAAsB,MAAA,EAAgB;AAC7C,EAAA,IAAI,OAAO,WAAA,CAAY,YAAY,KAAK,MAAA,CAAO,WAAA,CAAY,OAAO,CAAA,EAAG;AACnE,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,wGAAA;AAAA,KACF;AAAA,EACF;AACF;;;;"}
|
package/dist/gerrit/core.cjs.js
CHANGED
|
@@ -3,28 +3,6 @@
|
|
|
3
3
|
var lodash = require('lodash');
|
|
4
4
|
|
|
5
5
|
const GERRIT_BODY_PREFIX = ")]}'";
|
|
6
|
-
function parseGerritGitilesUrl(config, url) {
|
|
7
|
-
const baseUrlParse = new URL(config.gitilesBaseUrl);
|
|
8
|
-
const urlParse = new URL(url);
|
|
9
|
-
const urlPath = urlParse.pathname.substring(urlParse.pathname.startsWith("/a/") ? 2 : 0).replace(baseUrlParse.pathname, "");
|
|
10
|
-
const parts = urlPath.split("/").filter((p) => !!p);
|
|
11
|
-
const projectEndIndex = parts.indexOf("+");
|
|
12
|
-
if (projectEndIndex <= 0) {
|
|
13
|
-
throw new Error(`Unable to parse project from url: ${url}`);
|
|
14
|
-
}
|
|
15
|
-
const project = lodash.trimStart(parts.slice(0, projectEndIndex).join("/"), "/");
|
|
16
|
-
const branchIndex = parts.indexOf("heads");
|
|
17
|
-
if (branchIndex <= 0) {
|
|
18
|
-
throw new Error(`Unable to parse branch from url: ${url}`);
|
|
19
|
-
}
|
|
20
|
-
const branch = parts[branchIndex + 1];
|
|
21
|
-
const filePath = parts.slice(branchIndex + 2).join("/");
|
|
22
|
-
return {
|
|
23
|
-
branch,
|
|
24
|
-
filePath: filePath === "" ? "/" : filePath,
|
|
25
|
-
project
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
6
|
function parseGitilesUrlRef(config, url) {
|
|
29
7
|
const baseUrlParse = new URL(config.gitilesBaseUrl);
|
|
30
8
|
const urlParse = new URL(url);
|
|
@@ -95,12 +73,6 @@ function buildGerritEditUrl(config, project, branch, filePath) {
|
|
|
95
73
|
"/"
|
|
96
74
|
)}`;
|
|
97
75
|
}
|
|
98
|
-
function buildGerritGitilesArchiveUrl(config, project, branch, filePath) {
|
|
99
|
-
const archiveName = filePath === "/" || filePath === "" ? ".tar.gz" : `/${filePath}.tar.gz`;
|
|
100
|
-
return `${getGitilesAuthenticationUrl(
|
|
101
|
-
config
|
|
102
|
-
)}/${project}/+archive/refs/heads/${branch}${archiveName}`;
|
|
103
|
-
}
|
|
104
76
|
function buildGerritGitilesArchiveUrlFromLocation(config, url) {
|
|
105
77
|
const {
|
|
106
78
|
path: filePath,
|
|
@@ -144,13 +116,16 @@ function getGitilesAuthenticationUrl(config) {
|
|
|
144
116
|
return config.gitilesBaseUrl;
|
|
145
117
|
}
|
|
146
118
|
function getGerritBranchApiUrl(config, url) {
|
|
147
|
-
const {
|
|
119
|
+
const { ref, refType, project } = parseGitilesUrlRef(config, url);
|
|
120
|
+
if (refType !== "branch") {
|
|
121
|
+
throw new Error(`Unsupported gitiles ref type: ${refType}`);
|
|
122
|
+
}
|
|
148
123
|
return `${config.baseUrl}${getAuthenticationPrefix(
|
|
149
124
|
config
|
|
150
|
-
)}projects/${encodeURIComponent(project)}/branches/${
|
|
125
|
+
)}projects/${encodeURIComponent(project)}/branches/${ref}`;
|
|
151
126
|
}
|
|
152
127
|
function getGerritCloneRepoUrl(config, url) {
|
|
153
|
-
const { project } =
|
|
128
|
+
const { project } = parseGitilesUrlRef(config, url);
|
|
154
129
|
return `${config.cloneUrl}${getAuthenticationPrefix(config)}${project}`;
|
|
155
130
|
}
|
|
156
131
|
function getGerritFileContentsApiUrl(config, url) {
|
|
@@ -202,7 +177,6 @@ async function parseGerritJsonResponse(response) {
|
|
|
202
177
|
}
|
|
203
178
|
|
|
204
179
|
exports.buildGerritEditUrl = buildGerritEditUrl;
|
|
205
|
-
exports.buildGerritGitilesArchiveUrl = buildGerritGitilesArchiveUrl;
|
|
206
180
|
exports.buildGerritGitilesArchiveUrlFromLocation = buildGerritGitilesArchiveUrlFromLocation;
|
|
207
181
|
exports.getAuthenticationPrefix = getAuthenticationPrefix;
|
|
208
182
|
exports.getGerritBranchApiUrl = getGerritBranchApiUrl;
|
|
@@ -211,7 +185,6 @@ exports.getGerritFileContentsApiUrl = getGerritFileContentsApiUrl;
|
|
|
211
185
|
exports.getGerritProjectsApiUrl = getGerritProjectsApiUrl;
|
|
212
186
|
exports.getGerritRequestOptions = getGerritRequestOptions;
|
|
213
187
|
exports.getGitilesAuthenticationUrl = getGitilesAuthenticationUrl;
|
|
214
|
-
exports.parseGerritGitilesUrl = parseGerritGitilesUrl;
|
|
215
188
|
exports.parseGerritJsonResponse = parseGerritJsonResponse;
|
|
216
189
|
exports.parseGitilesUrlRef = parseGitilesUrlRef;
|
|
217
190
|
//# sourceMappingURL=core.cjs.js.map
|
|
@@ -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 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":["trimStart","takeWhile","join","trimEnd"],"mappings":";;;;AAkBA,MAAM,kBAAA,GAAqB,MAAA;AA4BpB,SAAS,qBAAA,CACd,QACA,GAAA,EACuD;AACv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AAQO,SAAS,wBAAwB,MAAA,EAEtC;AACA,EAAA,MAAM,UAAkC,EAAC;AAEzC,EAAA,IAAI,CAAC,OAAO,QAAA,EAAU;AACpB,IAAA,OAAO,OAAA;AAAA,EACT;AACA,EAAA,MAAM,MAAA,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
|
+
{"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 * 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 );\n}\n"],"names":["trimStart","takeWhile","join","trimEnd"],"mappings":";;;;AAkBA,MAAM,kBAAA,GAAqB,MAAA;AAqBpB,SAAS,kBAAA,CACd,QACA,GAAA,EAOA;AACA,EAAA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,MAAA,CAAO,cAAe,CAAA;AACnD,EAAA,MAAM,QAAA,GAAW,IAAI,GAAA,CAAI,GAAG,CAAA;AAK5B,EAAA,MAAM,OAAA,GAAUA,gBAAA;AAAA,IACd,QAAA,CAAS,QAAA,CACN,SAAA,CAAU,QAAA,CAAS,SAAS,UAAA,CAAW,KAAK,CAAA,GAAI,CAAA,GAAI,CAAC,CAAA,CACrD,OAAA,CAAQ,YAAA,CAAa,UAAU,EAAE,CAAA;AAAA,IACpC;AAAA,GACF;AAGA,EAAA,MAAM,KAAA,GAAQ,QAAQ,KAAA,CAAM,GAAG,EAAE,MAAA,CAAO,CAAA,CAAA,KAAK,CAAC,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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;;;;;;;;;;;;;;"}
|
package/dist/gerrit/core.esm.js
CHANGED
|
@@ -1,28 +1,6 @@
|
|
|
1
1
|
import { trimStart, takeWhile, join, trimEnd } from 'lodash';
|
|
2
2
|
|
|
3
3
|
const GERRIT_BODY_PREFIX = ")]}'";
|
|
4
|
-
function parseGerritGitilesUrl(config, url) {
|
|
5
|
-
const baseUrlParse = new URL(config.gitilesBaseUrl);
|
|
6
|
-
const urlParse = new URL(url);
|
|
7
|
-
const urlPath = urlParse.pathname.substring(urlParse.pathname.startsWith("/a/") ? 2 : 0).replace(baseUrlParse.pathname, "");
|
|
8
|
-
const parts = urlPath.split("/").filter((p) => !!p);
|
|
9
|
-
const projectEndIndex = parts.indexOf("+");
|
|
10
|
-
if (projectEndIndex <= 0) {
|
|
11
|
-
throw new Error(`Unable to parse project from url: ${url}`);
|
|
12
|
-
}
|
|
13
|
-
const project = trimStart(parts.slice(0, projectEndIndex).join("/"), "/");
|
|
14
|
-
const branchIndex = parts.indexOf("heads");
|
|
15
|
-
if (branchIndex <= 0) {
|
|
16
|
-
throw new Error(`Unable to parse branch from url: ${url}`);
|
|
17
|
-
}
|
|
18
|
-
const branch = parts[branchIndex + 1];
|
|
19
|
-
const filePath = parts.slice(branchIndex + 2).join("/");
|
|
20
|
-
return {
|
|
21
|
-
branch,
|
|
22
|
-
filePath: filePath === "" ? "/" : filePath,
|
|
23
|
-
project
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
4
|
function parseGitilesUrlRef(config, url) {
|
|
27
5
|
const baseUrlParse = new URL(config.gitilesBaseUrl);
|
|
28
6
|
const urlParse = new URL(url);
|
|
@@ -93,12 +71,6 @@ function buildGerritEditUrl(config, project, branch, filePath) {
|
|
|
93
71
|
"/"
|
|
94
72
|
)}`;
|
|
95
73
|
}
|
|
96
|
-
function buildGerritGitilesArchiveUrl(config, project, branch, filePath) {
|
|
97
|
-
const archiveName = filePath === "/" || filePath === "" ? ".tar.gz" : `/${filePath}.tar.gz`;
|
|
98
|
-
return `${getGitilesAuthenticationUrl(
|
|
99
|
-
config
|
|
100
|
-
)}/${project}/+archive/refs/heads/${branch}${archiveName}`;
|
|
101
|
-
}
|
|
102
74
|
function buildGerritGitilesArchiveUrlFromLocation(config, url) {
|
|
103
75
|
const {
|
|
104
76
|
path: filePath,
|
|
@@ -142,13 +114,16 @@ function getGitilesAuthenticationUrl(config) {
|
|
|
142
114
|
return config.gitilesBaseUrl;
|
|
143
115
|
}
|
|
144
116
|
function getGerritBranchApiUrl(config, url) {
|
|
145
|
-
const {
|
|
117
|
+
const { ref, refType, project } = parseGitilesUrlRef(config, url);
|
|
118
|
+
if (refType !== "branch") {
|
|
119
|
+
throw new Error(`Unsupported gitiles ref type: ${refType}`);
|
|
120
|
+
}
|
|
146
121
|
return `${config.baseUrl}${getAuthenticationPrefix(
|
|
147
122
|
config
|
|
148
|
-
)}projects/${encodeURIComponent(project)}/branches/${
|
|
123
|
+
)}projects/${encodeURIComponent(project)}/branches/${ref}`;
|
|
149
124
|
}
|
|
150
125
|
function getGerritCloneRepoUrl(config, url) {
|
|
151
|
-
const { project } =
|
|
126
|
+
const { project } = parseGitilesUrlRef(config, url);
|
|
152
127
|
return `${config.cloneUrl}${getAuthenticationPrefix(config)}${project}`;
|
|
153
128
|
}
|
|
154
129
|
function getGerritFileContentsApiUrl(config, url) {
|
|
@@ -199,5 +174,5 @@ async function parseGerritJsonResponse(response) {
|
|
|
199
174
|
);
|
|
200
175
|
}
|
|
201
176
|
|
|
202
|
-
export { buildGerritEditUrl,
|
|
177
|
+
export { buildGerritEditUrl, buildGerritGitilesArchiveUrlFromLocation, getAuthenticationPrefix, getGerritBranchApiUrl, getGerritCloneRepoUrl, getGerritFileContentsApiUrl, getGerritProjectsApiUrl, getGerritRequestOptions, getGitilesAuthenticationUrl, parseGerritJsonResponse, parseGitilesUrlRef };
|
|
203
178
|
//# sourceMappingURL=core.esm.js.map
|
|
@@ -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,CAAE,CAAA;AAAA,EAC5D;AACA,EAAA,MAAM,OAAA,GAAU,SAAA,CAAU,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,eAAe,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA,EAAG,GAAG,CAAA;AAExE,EAAA,MAAM,WAAA,GAAc,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA;AACzC,EAAA,IAAI,eAAe,CAAA,EAAG;AACpB,IAAA,MAAM,IA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A;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 );\n}\n"],"names":[],"mappings":";;AAkBA,MAAM,kBAAA,GAAqB,MAAA;AAqBpB,SAAS,kBAAA,CACd,QACA,GAAA,EAOA;AACA,EAAA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,MAAA,CAAO,cAAe,CAAA;AACnD,EAAA,MAAM,QAAA,GAAW,IAAI,GAAA,CAAI,GAAG,CAAA;AAK5B,EAAA,MAAM,OAAA,GAAU,SAAA;AAAA,IACd,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;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;;;;"}
|
package/dist/github/core.cjs.js
CHANGED
|
@@ -23,16 +23,6 @@ function getGithubFileFetchUrl(url, config, credentials) {
|
|
|
23
23
|
throw new Error(`Incorrect URL: ${url}, ${e}`);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
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
26
|
function chooseEndpoint(config, credentials) {
|
|
37
27
|
if (config.apiBaseUrl && (credentials.token || !config.rawBaseUrl)) {
|
|
38
28
|
return "api";
|
|
@@ -41,6 +31,5 @@ function chooseEndpoint(config, credentials) {
|
|
|
41
31
|
}
|
|
42
32
|
|
|
43
33
|
exports.chooseEndpoint = chooseEndpoint;
|
|
44
|
-
exports.getGitHubRequestOptions = getGitHubRequestOptions;
|
|
45
34
|
exports.getGithubFileFetchUrl = getGithubFileFetchUrl;
|
|
46
35
|
//# 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\
|
|
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\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,EAAE,OAAO,IAAA,EAAM,GAAA,EAAK,cAAc,QAAA,EAAS,GAAIA,6BAAY,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;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;;;;;"}
|
package/dist/github/core.esm.js
CHANGED
|
@@ -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,
|
|
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\
|
|
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\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;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;;;;"}
|
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
var helpers = require('../helpers.cjs.js');
|
|
4
4
|
var config = require('./config.cjs.js');
|
|
5
|
+
var pThrottle = require('p-throttle');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var pThrottle__default = /*#__PURE__*/_interopDefaultCompat(pThrottle);
|
|
5
10
|
|
|
6
11
|
class GitLabIntegration {
|
|
7
12
|
constructor(integrationConfig) {
|
|
8
13
|
this.integrationConfig = integrationConfig;
|
|
14
|
+
this.fetchImpl = this.createFetchStrategy();
|
|
9
15
|
}
|
|
10
16
|
static factory = ({ config: config$1 }) => {
|
|
11
17
|
const configs = config.readGitLabIntegrationConfigs(
|
|
@@ -16,6 +22,7 @@ class GitLabIntegration {
|
|
|
16
22
|
(i) => i.config.host
|
|
17
23
|
);
|
|
18
24
|
};
|
|
25
|
+
fetchImpl;
|
|
19
26
|
get type() {
|
|
20
27
|
return "gitlab";
|
|
21
28
|
}
|
|
@@ -31,6 +38,67 @@ class GitLabIntegration {
|
|
|
31
38
|
resolveEditUrl(url) {
|
|
32
39
|
return replaceGitLabUrlType(url, "edit");
|
|
33
40
|
}
|
|
41
|
+
fetch(input, init) {
|
|
42
|
+
return this.fetchImpl(input, init);
|
|
43
|
+
}
|
|
44
|
+
createFetchStrategy() {
|
|
45
|
+
let fetchFn = async (url, options) => {
|
|
46
|
+
return fetch(url, { ...options, mode: "same-origin" });
|
|
47
|
+
};
|
|
48
|
+
const retryConfig = this.integrationConfig.retry;
|
|
49
|
+
if (retryConfig) {
|
|
50
|
+
fetchFn = this.withRetry(fetchFn, retryConfig);
|
|
51
|
+
if (retryConfig.maxApiRequestsPerMinute && retryConfig.maxApiRequestsPerMinute > 0) {
|
|
52
|
+
fetchFn = pThrottle__default.default({
|
|
53
|
+
limit: retryConfig.maxApiRequestsPerMinute,
|
|
54
|
+
interval: 6e4
|
|
55
|
+
})(fetchFn);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return fetchFn;
|
|
59
|
+
}
|
|
60
|
+
withRetry(fetchFn, retryConfig) {
|
|
61
|
+
const maxRetries = retryConfig?.maxRetries ?? 0;
|
|
62
|
+
const retryStatusCodes = retryConfig?.retryStatusCodes ?? [];
|
|
63
|
+
if (maxRetries <= 0 || retryStatusCodes.length === 0) {
|
|
64
|
+
return fetchFn;
|
|
65
|
+
}
|
|
66
|
+
return async (url, options) => {
|
|
67
|
+
const abortSignal = options?.signal;
|
|
68
|
+
let response;
|
|
69
|
+
let attempt = 0;
|
|
70
|
+
for (; ; ) {
|
|
71
|
+
response = await fetchFn(url, options);
|
|
72
|
+
if (!retryStatusCodes.includes(response.status)) {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
if (attempt++ >= maxRetries) {
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
79
|
+
const delay = retryAfter ? parseInt(retryAfter, 10) * 1e3 : Math.min(100 * Math.pow(2, attempt - 1), 1e4);
|
|
80
|
+
await sleep(delay, abortSignal);
|
|
81
|
+
}
|
|
82
|
+
return response;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function sleep(durationMs, abortSignal) {
|
|
87
|
+
if (abortSignal?.aborted) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
await new Promise((resolve) => {
|
|
91
|
+
let timeoutHandle = void 0;
|
|
92
|
+
const done = () => {
|
|
93
|
+
if (timeoutHandle) {
|
|
94
|
+
clearTimeout(timeoutHandle);
|
|
95
|
+
}
|
|
96
|
+
abortSignal?.removeEventListener("abort", done);
|
|
97
|
+
resolve();
|
|
98
|
+
};
|
|
99
|
+
timeoutHandle = setTimeout(done, durationMs);
|
|
100
|
+
abortSignal?.addEventListener("abort", done);
|
|
101
|
+
});
|
|
34
102
|
}
|
|
35
103
|
function replaceGitLabUrlType(url, type) {
|
|
36
104
|
return url.replace(/\/\-\/(blob|tree|edit)\//, `/-/${type}/`);
|
|
@@ -38,4 +106,5 @@ function replaceGitLabUrlType(url, type) {
|
|
|
38
106
|
|
|
39
107
|
exports.GitLabIntegration = GitLabIntegration;
|
|
40
108
|
exports.replaceGitLabUrlType = replaceGitLabUrlType;
|
|
109
|
+
exports.sleep = sleep;
|
|
41
110
|
//# sourceMappingURL=GitLabIntegration.cjs.js.map
|