@backstage/integration 1.15.0 → 1.15.1-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/gitlab/core.esm.js +3 -1
- package/dist/gitlab/core.esm.js.map +1 -1
- package/dist/harness/core.esm.js +30 -4
- package/dist/harness/core.esm.js.map +1 -1
- package/dist/index.cjs.js +33 -5
- package/dist/index.cjs.js.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @backstage/integration
|
|
2
2
|
|
|
3
|
+
## 1.15.1-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 920004b: Updating error message for getProjectId when fetching Gitlab project from its url to be more accurate
|
|
8
|
+
- 090e49a: Updated functions parseHarnessUrl, getHarnessLatestCommitUrl, getHarnessFileContentsUrl and getHarnessArchiveUrl to fix parsing of urls
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
- @backstage/config@1.2.0
|
|
11
|
+
- @backstage/errors@1.2.4
|
|
12
|
+
|
|
3
13
|
## 1.15.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/dist/gitlab/core.esm.js
CHANGED
|
@@ -40,7 +40,9 @@ function buildProjectUrl(target, projectID, config) {
|
|
|
40
40
|
async function getProjectId(target, config) {
|
|
41
41
|
const url = new URL(target);
|
|
42
42
|
if (!url.pathname.includes("/blob/")) {
|
|
43
|
-
throw new Error(
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Failed converting ${url.pathname} to a project id. Url path must include /blob/.`
|
|
45
|
+
);
|
|
44
46
|
}
|
|
45
47
|
try {
|
|
46
48
|
let repo = url.pathname.split("/-/blob/")[0].split("/blob/")[0];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.esm.js","sources":["../../src/gitlab/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 fetch from 'cross-fetch';\nimport {\n getGitLabIntegrationRelativePath,\n GitLabIntegrationConfig,\n} from './config';\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://gitlab.example.com/a/b/blob/master/c.yaml\n * to: https://gitlab.com/api/v4/projects/projectId/repository/c.yaml?ref=master\n * -or-\n * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n * to: https://gitlab.com/api/v4/projects/projectId/repository/files/filepath?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport async function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n): Promise<string> {\n const projectID = await getProjectId(url, config);\n return buildProjectUrl(url, projectID, config).toString();\n}\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n *\n * @param config - The relevant provider config\n * @public\n */\nexport function getGitLabRequestOptions(\n config: GitLabIntegrationConfig,\n token?: string,\n): { headers: Record<string, string> } {\n if (token) {\n // If token comes from the user and starts with \"gl\", it's a private token (see https://docs.gitlab.com/ee/security/token_overview.html#token-prefixes)\n return {\n headers: token.startsWith('gl')\n ? { 'PRIVATE-TOKEN': token }\n : { Authorization: `Bearer ${token}` }, // Otherwise, it's a bearer token\n };\n }\n\n // If token not provided, fetch the integration token\n const { token: configToken = '' } = config;\n return {\n headers: { 'PRIVATE-TOKEN': configToken },\n };\n}\n\n// Converts\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: https://gitlab.com/api/v4/projects/projectId/repository/files/filepath?ref=branch\nexport function buildProjectUrl(\n target: string,\n projectID: Number,\n config: GitLabIntegrationConfig,\n): URL {\n try {\n const url = new URL(target);\n\n const branchAndFilePath = url.pathname\n .split('/blob/')\n .slice(1)\n .join('/blob/');\n const [branch, ...filePath] = branchAndFilePath.split('/');\n const relativePath = getGitLabIntegrationRelativePath(config);\n\n url.pathname = [\n ...(relativePath ? [relativePath] : []),\n 'api/v4/projects',\n projectID,\n 'repository/files',\n encodeURIComponent(decodeURIComponent(filePath.join('/'))),\n 'raw',\n ].join('/');\n\n url.search = `?ref=${branch}`;\n\n return url;\n } catch (e) {\n throw new Error(`Incorrect url: ${target}, ${e}`);\n }\n}\n\n// Convert\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: The project ID that corresponds to the URL\nexport async function getProjectId(\n target: string,\n config: GitLabIntegrationConfig,\n): Promise<number> {\n const url = new URL(target);\n\n if (!url.pathname.includes('/blob/')) {\n throw new Error(
|
|
1
|
+
{"version":3,"file":"core.esm.js","sources":["../../src/gitlab/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 fetch from 'cross-fetch';\nimport {\n getGitLabIntegrationRelativePath,\n GitLabIntegrationConfig,\n} from './config';\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://gitlab.example.com/a/b/blob/master/c.yaml\n * to: https://gitlab.com/api/v4/projects/projectId/repository/c.yaml?ref=master\n * -or-\n * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n * to: https://gitlab.com/api/v4/projects/projectId/repository/files/filepath?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport async function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n): Promise<string> {\n const projectID = await getProjectId(url, config);\n return buildProjectUrl(url, projectID, config).toString();\n}\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n *\n * @param config - The relevant provider config\n * @public\n */\nexport function getGitLabRequestOptions(\n config: GitLabIntegrationConfig,\n token?: string,\n): { headers: Record<string, string> } {\n if (token) {\n // If token comes from the user and starts with \"gl\", it's a private token (see https://docs.gitlab.com/ee/security/token_overview.html#token-prefixes)\n return {\n headers: token.startsWith('gl')\n ? { 'PRIVATE-TOKEN': token }\n : { Authorization: `Bearer ${token}` }, // Otherwise, it's a bearer token\n };\n }\n\n // If token not provided, fetch the integration token\n const { token: configToken = '' } = config;\n return {\n headers: { 'PRIVATE-TOKEN': configToken },\n };\n}\n\n// Converts\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: https://gitlab.com/api/v4/projects/projectId/repository/files/filepath?ref=branch\nexport function buildProjectUrl(\n target: string,\n projectID: Number,\n config: GitLabIntegrationConfig,\n): URL {\n try {\n const url = new URL(target);\n\n const branchAndFilePath = url.pathname\n .split('/blob/')\n .slice(1)\n .join('/blob/');\n const [branch, ...filePath] = branchAndFilePath.split('/');\n const relativePath = getGitLabIntegrationRelativePath(config);\n\n url.pathname = [\n ...(relativePath ? [relativePath] : []),\n 'api/v4/projects',\n projectID,\n 'repository/files',\n encodeURIComponent(decodeURIComponent(filePath.join('/'))),\n 'raw',\n ].join('/');\n\n url.search = `?ref=${branch}`;\n\n return url;\n } catch (e) {\n throw new Error(`Incorrect url: ${target}, ${e}`);\n }\n}\n\n// Convert\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: The project ID that corresponds to the URL\nexport async function getProjectId(\n target: string,\n config: GitLabIntegrationConfig,\n): Promise<number> {\n const url = new URL(target);\n\n if (!url.pathname.includes('/blob/')) {\n throw new Error(\n `Failed converting ${url.pathname} to a project id. Url path must include /blob/.`,\n );\n }\n\n try {\n let repo = url.pathname.split('/-/blob/')[0].split('/blob/')[0];\n\n // Get gitlab relative path\n const relativePath = getGitLabIntegrationRelativePath(config);\n\n // Check relative path exist and replace it if it's the case.\n if (relativePath) {\n repo = repo.replace(relativePath, '');\n }\n\n // Convert\n // to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FsubgroupA%2FteamA%2Frepo\n const repoIDLookup = new URL(\n `${url.origin}${relativePath}/api/v4/projects/${encodeURIComponent(\n repo.replace(/^\\//, ''),\n )}`,\n );\n\n const response = await fetch(\n repoIDLookup.toString(),\n getGitLabRequestOptions(config),\n );\n\n const data = await response.json();\n\n if (!response.ok) {\n throw new Error(\n `GitLab Error '${data.error}', ${data.error_description}`,\n );\n }\n\n return Number(data.id);\n } catch (e) {\n throw new Error(`Could not get GitLab project ID for: ${target}, ${e}`);\n }\n}\n"],"names":[],"mappings":";;;AAuCsB,eAAA,qBAAA,CACpB,KACA,MACiB,EAAA;AACjB,EAAA,MAAM,SAAY,GAAA,MAAM,YAAa,CAAA,GAAA,EAAK,MAAM,CAAA,CAAA;AAChD,EAAA,OAAO,eAAgB,CAAA,GAAA,EAAK,SAAW,EAAA,MAAM,EAAE,QAAS,EAAA,CAAA;AAC1D,CAAA;AAQgB,SAAA,uBAAA,CACd,QACA,KACqC,EAAA;AACrC,EAAA,IAAI,KAAO,EAAA;AAET,IAAO,OAAA;AAAA,MACL,OAAS,EAAA,KAAA,CAAM,UAAW,CAAA,IAAI,CAC1B,GAAA,EAAE,eAAiB,EAAA,KAAA,EACnB,GAAA,EAAE,aAAe,EAAA,CAAA,OAAA,EAAU,KAAK,CAAG,CAAA,EAAA;AAA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O,OAAA,MAAA,CAAO,KAAK,EAAE,CAAA,CAAA;AAAA,WACd,CAAG,EAAA;AACV,IAAA,MAAM,IAAI,KAAM,CAAA,CAAA,qCAAA,EAAwC,MAAM,CAAA,EAAA,EAAK,CAAC,CAAE,CAAA,CAAA,CAAA;AAAA,GACxE;AACF;;;;"}
|
package/dist/harness/core.esm.js
CHANGED
|
@@ -4,15 +4,39 @@ function getHarnessEditContentsUrl(config, url) {
|
|
|
4
4
|
}
|
|
5
5
|
function getHarnessFileContentsUrl(config, url) {
|
|
6
6
|
const parsedUrl = parseHarnessUrl(config, url);
|
|
7
|
-
|
|
7
|
+
let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;
|
|
8
|
+
if (parsedUrl.orgName) {
|
|
9
|
+
constructedUrl += `/${parsedUrl.orgName}`;
|
|
10
|
+
}
|
|
11
|
+
if (parsedUrl.projectName) {
|
|
12
|
+
constructedUrl += `/${parsedUrl.projectName}`;
|
|
13
|
+
}
|
|
14
|
+
constructedUrl += `/${parsedUrl.repoName}/+/raw/${parsedUrl.path}?routingId=${parsedUrl.accountId}&git_ref=refs/heads/${parsedUrl.refString}`;
|
|
15
|
+
return constructedUrl;
|
|
8
16
|
}
|
|
9
17
|
function getHarnessArchiveUrl(config, url) {
|
|
10
18
|
const parsedUrl = parseHarnessUrl(config, url);
|
|
11
|
-
|
|
19
|
+
let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;
|
|
20
|
+
if (parsedUrl.orgName) {
|
|
21
|
+
constructedUrl += `/${parsedUrl.orgName}`;
|
|
22
|
+
}
|
|
23
|
+
if (parsedUrl.projectName) {
|
|
24
|
+
constructedUrl += `/${parsedUrl.projectName}`;
|
|
25
|
+
}
|
|
26
|
+
constructedUrl += `/${parsedUrl.repoName}/+/archive/${parsedUrl.branch}.zip?routingId=${parsedUrl.accountId}`;
|
|
27
|
+
return constructedUrl;
|
|
12
28
|
}
|
|
13
29
|
function getHarnessLatestCommitUrl(config, url) {
|
|
14
30
|
const parsedUrl = parseHarnessUrl(config, url);
|
|
15
|
-
|
|
31
|
+
let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;
|
|
32
|
+
if (parsedUrl.orgName) {
|
|
33
|
+
constructedUrl += `/${parsedUrl.orgName}`;
|
|
34
|
+
}
|
|
35
|
+
if (parsedUrl.projectName) {
|
|
36
|
+
constructedUrl += `/${parsedUrl.projectName}`;
|
|
37
|
+
}
|
|
38
|
+
constructedUrl += `/${parsedUrl.repoName}/+/content?routingId=${parsedUrl.accountId}&include_commit=true&git_ref=refs/heads/${parsedUrl.branch}`;
|
|
39
|
+
return constructedUrl;
|
|
16
40
|
}
|
|
17
41
|
function getHarnessRequestOptions(config) {
|
|
18
42
|
const headers = {};
|
|
@@ -40,7 +64,9 @@ function parseHarnessUrl(config, url) {
|
|
|
40
64
|
(segment) => segment === "projects"
|
|
41
65
|
);
|
|
42
66
|
const projectName = projectNameIndex !== -1 ? pathSegments[projectNameIndex + 1] : "";
|
|
43
|
-
const repoNameIndex = pathSegments.findIndex(
|
|
67
|
+
const repoNameIndex = pathSegments.findIndex(
|
|
68
|
+
(segment, index) => segment === "repos" && index > Math.max(accountIdIndex, orgNameIndex, projectNameIndex)
|
|
69
|
+
) + 1;
|
|
44
70
|
const repoName = pathSegments[repoNameIndex];
|
|
45
71
|
const refAndPath = urlParts.slice(
|
|
46
72
|
urlParts.findIndex((i) => i === "files" || i === "edit") + 1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.esm.js","sources":["../../src/harness/core.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { HarnessIntegrationConfig } from './config';\n\n/**\n * Given a URL pointing to a file, returns a URL\n * for editing the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/a/b/src/branchname/path/to/c.yaml\n * or: https://app.harness.io/a/b/_edit/branchname/path/to/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessEditContentsUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n return `${parsedUrl.baseUrl}/ng/account/${parsedUrl.accountId}/module/code${\n parsedUrl.orgName !== '' ? `/orgs/${parsedUrl.orgName}` : ''\n }${\n parsedUrl.projectName !== '' ? `/projects/${parsedUrl.projectName}` : ''\n }/repos/${parsedUrl.repoName}/files/${parsedUrl.branch}/~/${parsedUrl.path}`;\n}\n\n/**\n * Given a file path URL,\n * it returns an API URL which returns the contents of the file .\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/ng/account/accountId/module/code/orgs/orgName/projects/projName/repos/repoName/files/refMain/~/all-apis.yaml\n * https://qa.harness.io/ng/account/bDCAuAjFSJCLFj_0ug3lCg/module/code/orgs/HiteshTest/repos/impoorter/files/main/~/catalog.yaml\n * to: https://app.harness.io/gateway/code/api/v1/repos/accountId/orgName/projName/repoName/+/content/all-apis.yaml?routingId=accountId&include_commit=false&ref=refMain\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessFileContentsUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${\n parsedUrl.accountId\n }/${parsedUrl.orgName}${\n parsedUrl.projectName !== '' ? `/${parsedUrl.projectName}/` : '/'\n }${parsedUrl.repoName}/+/raw/${parsedUrl.path}?routingId=${\n parsedUrl.accountId\n }&git_ref=refs/heads/${parsedUrl.refString}`;\n}\n\n/**\n * Given a URL pointing to a repository/path, returns a URL\n * for archive contents of the repository.\n *\n * @remarks\n *\n * Converts\n * from: https://qa.harness.io/ng/account/accountId/module/code/orgs/orgId/projects/projectName/repos/repoName/files/branch/~/fileName\n * to: https://qa.harness.io/gateway/code/api/v1/repos/accountId/orgId/projectName/repoName/+/archive/branch.zip?routingId=accountId\n *\n * @param url - A URL pointing to a repository/path\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessArchiveUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${\n parsedUrl.accountId\n }/${parsedUrl.orgName}${\n parsedUrl.projectName !== '' ? `/${parsedUrl.projectName}/` : '/'\n }${parsedUrl.repoName}/+/archive/${parsedUrl.branch}.zip?routingId=${\n parsedUrl.accountId\n }`;\n}\n\n/**\n * Given a URL pointing to a repository branch, returns a URL\n * for latest commit information.\n *\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/ng/account/accountId/module/code/orgs/orgName/projects/projectName/repos/repoName/files/branchName\n * to: https://app.harness.io/gateway/code/api/v1/repos/accountId/orgName/projectName/repoName/+/content?routingId=accountId&include_commit=true&git_ref=refs/heads/branchName\n *\n * @param url - A URL pointing to a repository branch\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessLatestCommitUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${\n parsedUrl.accountId\n }/${parsedUrl.orgName}${\n parsedUrl.projectName !== '' ? `/${parsedUrl.projectName}/` : '/'\n }${parsedUrl.repoName}/+/content?routingId=${\n parsedUrl.accountId\n }&include_commit=true&git_ref=refs/heads/${parsedUrl.branch}`;\n}\n\n/**\n * Return request headers for a Harness Code provider.\n *\n * @param config - A Harness Code provider config\n * @public\n */\nexport function getHarnessRequestOptions(config: HarnessIntegrationConfig): {\n headers?: Record<string, string>;\n} {\n const headers: Record<string, string> = {};\n const { token, apiKey } = config;\n\n if (apiKey) {\n headers['x-api-key'] = apiKey;\n } else if (token) {\n headers.Authorization = `Bearer ${token}`;\n }\n\n return {\n headers,\n };\n}\n\n/**\n * Return parsed git url properties.\n *\n * @param config - A Harness provider config\n * @param url - A URL pointing to a repository\n * @public\n */\nexport function parseHarnessUrl(\n config: HarnessIntegrationConfig,\n url: string,\n): {\n baseUrl: string;\n accountId: string;\n orgName: string;\n projectName: string;\n refString: string;\n repoName: string;\n path: string;\n refDashStr: string;\n branch: string;\n} {\n const baseUrl = `https://${config.host}`;\n try {\n const pathUrl = new URL(url);\n const pathSegments = pathUrl.pathname\n .split('/')\n .filter(segment => segment !== '');\n const urlParts = pathUrl.pathname.split('/');\n\n const accountIdIndex =\n pathSegments.findIndex(segment => segment === 'account') + 1;\n const accountId = pathSegments[accountIdIndex];\n\n const orgNameIndex = pathSegments.findIndex(segment => segment === 'orgs');\n const orgName = orgNameIndex !== -1 ? pathSegments[orgNameIndex + 1] : '';\n\n const projectNameIndex = pathSegments.findIndex(\n segment => segment === 'projects',\n );\n\n const projectName =\n projectNameIndex !== -1 ? pathSegments[projectNameIndex + 1] : '';\n\n const repoNameIndex =\n pathSegments.findIndex(segment => segment === 'repos') + 1;\n const repoName = pathSegments[repoNameIndex];\n\n const refAndPath = urlParts.slice(\n urlParts.findIndex(i => i === 'files' || i === 'edit') + 1,\n );\n const refIndex = refAndPath.findIndex(item => item === '~');\n\n const refString = refAndPath.slice(0, refIndex).join('/');\n const pathWithoutSlash =\n refIndex !== -1\n ? refAndPath\n .slice(refIndex + 1)\n .join('/')\n .replace(/^\\//, '')\n : '';\n\n return {\n baseUrl: baseUrl,\n accountId: accountId,\n orgName: orgName,\n projectName: projectName,\n refString: refString,\n path: pathWithoutSlash,\n repoName: repoName,\n refDashStr: refAndPath.slice(0, refIndex).join('-'),\n branch:\n refIndex !== -1\n ? refAndPath.slice(0, refIndex).join('/')\n : refAndPath.join('/'),\n };\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n"],"names":[],"mappings":"AA+BgB,SAAA,yBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,SAAA,GAAY,eAAgB,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAA;AAE7C,EAAA,OAAO,CAAG,EAAA,SAAA,CAAU,OAAO,CAAA,YAAA,EAAe,UAAU,SAAS,CAAA,YAAA,EAC3D,SAAU,CAAA,OAAA,KAAY,EAAK,GAAA,CAAA,MAAA,EAAS,SAAU,CAAA,OAAO,KAAK,EAC5D,CAAA,EACE,SAAU,CAAA,WAAA,KAAgB,EAAK,GAAA,CAAA,UAAA,EAAa,SAAU,CAAA,WAAW,KAAK,EACxE,CAAA,OAAA,EAAU,SAAU,CAAA,QAAQ,CAAU,OAAA,EAAA,SAAA,CAAU,MAAM,CAAA,GAAA,EAAM,UAAU,IAAI,CAAA,CAAA,CAAA;AAC5E,CAAA;AAgBgB,SAAA,yBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,SAAA,GAAY,eAAgB,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAA;AAE7C,EAAA,OAAO,CAAG,EAAA,SAAA,CAAU,OAAO,CAAA,2BAAA,EACzB,SAAU,CAAA,SACZ,CAAI,CAAA,EAAA,SAAA,CAAU,OAAO,CAAA,EACnB,SAAU,CAAA,WAAA,KAAgB,EAAK,GAAA,CAAA,CAAA,EAAI,SAAU,CAAA,WAAW,CAAM,CAAA,CAAA,GAAA,GAChE,CAAG,EAAA,SAAA,CAAU,QAAQ,CAAA,OAAA,EAAU,SAAU,CAAA,IAAI,CAC3C,WAAA,EAAA,SAAA,CAAU,SACZ,CAAA,oBAAA,EAAuB,UAAU,SAAS,CAAA,CAAA,CAAA;AAC5C,CAAA;AAgBgB,SAAA,oBAAA,CACd,QAC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Copyright 2024 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 { HarnessIntegrationConfig } from './config';\n\n/**\n * Given a URL pointing to a file, returns a URL\n * for editing the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/a/b/src/branchname/path/to/c.yaml\n * or: https://app.harness.io/a/b/_edit/branchname/path/to/c.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessEditContentsUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n return `${parsedUrl.baseUrl}/ng/account/${parsedUrl.accountId}/module/code${\n parsedUrl.orgName !== '' ? `/orgs/${parsedUrl.orgName}` : ''\n }${\n parsedUrl.projectName !== '' ? `/projects/${parsedUrl.projectName}` : ''\n }/repos/${parsedUrl.repoName}/files/${parsedUrl.branch}/~/${parsedUrl.path}`;\n}\n\n/**\n * Given a file path URL,\n * it returns an API URL which returns the contents of the file .\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/ng/account/accountId/module/code/orgs/orgName/projects/projName/repos/repoName/files/refMain/~/all-apis.yaml\n * https://qa.harness.io/ng/account/bDCAuAjFSJCLFj_0ug3lCg/module/code/orgs/HiteshTest/repos/impoorter/files/main/~/catalog.yaml\n * to: https://app.harness.io/gateway/code/api/v1/repos/accountId/orgName/projName/repoName/+/content/all-apis.yaml?routingId=accountId&include_commit=false&ref=refMain\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessFileContentsUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;\n\n if (parsedUrl.orgName) {\n constructedUrl += `/${parsedUrl.orgName}`;\n }\n\n if (parsedUrl.projectName) {\n constructedUrl += `/${parsedUrl.projectName}`;\n }\n\n constructedUrl += `/${parsedUrl.repoName}/+/raw/${parsedUrl.path}?routingId=${parsedUrl.accountId}&git_ref=refs/heads/${parsedUrl.refString}`;\n\n return constructedUrl;\n}\n\n/**\n * Given a URL pointing to a repository/path, returns a URL\n * for archive contents of the repository.\n *\n * @remarks\n *\n * Converts\n * from: https://qa.harness.io/ng/account/accountId/module/code/orgs/orgId/projects/projectName/repos/repoName/files/branch/~/fileName\n * to: https://qa.harness.io/gateway/code/api/v1/repos/accountId/orgId/projectName/repoName/+/archive/branch.zip?routingId=accountId\n *\n * @param url - A URL pointing to a repository/path\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessArchiveUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;\n\n if (parsedUrl.orgName) {\n constructedUrl += `/${parsedUrl.orgName}`;\n }\n\n if (parsedUrl.projectName) {\n constructedUrl += `/${parsedUrl.projectName}`;\n }\n\n constructedUrl += `/${parsedUrl.repoName}/+/archive/${parsedUrl.branch}.zip?routingId=${parsedUrl.accountId}`;\n\n return constructedUrl;\n}\n\n/**\n * Given a URL pointing to a repository branch, returns a URL\n * for latest commit information.\n *\n * @remarks\n *\n * Converts\n * from: https://app.harness.io/ng/account/accountId/module/code/orgs/orgName/projects/projectName/repos/repoName/files/branchName\n * to: https://app.harness.io/gateway/code/api/v1/repos/accountId/orgName/projectName/repoName/+/content?routingId=accountId&include_commit=true&git_ref=refs/heads/branchName\n *\n * @param url - A URL pointing to a repository branch\n * @param config - The relevant provider config\n * @public\n */\nexport function getHarnessLatestCommitUrl(\n config: HarnessIntegrationConfig,\n url: string,\n) {\n const parsedUrl = parseHarnessUrl(config, url);\n\n let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;\n\n if (parsedUrl.orgName) {\n constructedUrl += `/${parsedUrl.orgName}`;\n }\n\n if (parsedUrl.projectName) {\n constructedUrl += `/${parsedUrl.projectName}`;\n }\n\n constructedUrl += `/${parsedUrl.repoName}/+/content?routingId=${parsedUrl.accountId}&include_commit=true&git_ref=refs/heads/${parsedUrl.branch}`;\n\n return constructedUrl;\n}\n\n/**\n * Return request headers for a Harness Code provider.\n *\n * @param config - A Harness Code provider config\n * @public\n */\nexport function getHarnessRequestOptions(config: HarnessIntegrationConfig): {\n headers?: Record<string, string>;\n} {\n const headers: Record<string, string> = {};\n const { token, apiKey } = config;\n\n if (apiKey) {\n headers['x-api-key'] = apiKey;\n } else if (token) {\n headers.Authorization = `Bearer ${token}`;\n }\n\n return {\n headers,\n };\n}\n\n/**\n * Return parsed git url properties.\n *\n * @param config - A Harness provider config\n * @param url - A URL pointing to a repository\n * @public\n */\nexport function parseHarnessUrl(\n config: HarnessIntegrationConfig,\n url: string,\n): {\n baseUrl: string;\n accountId: string;\n orgName: string;\n projectName: string;\n refString: string;\n repoName: string;\n path: string;\n refDashStr: string;\n branch: string;\n} {\n const baseUrl = `https://${config.host}`;\n try {\n const pathUrl = new URL(url);\n const pathSegments = pathUrl.pathname\n .split('/')\n .filter(segment => segment !== '');\n const urlParts = pathUrl.pathname.split('/');\n\n const accountIdIndex =\n pathSegments.findIndex(segment => segment === 'account') + 1;\n const accountId = pathSegments[accountIdIndex];\n\n const orgNameIndex = pathSegments.findIndex(segment => segment === 'orgs');\n const orgName = orgNameIndex !== -1 ? pathSegments[orgNameIndex + 1] : '';\n const projectNameIndex = pathSegments.findIndex(\n segment => segment === 'projects',\n );\n\n const projectName =\n projectNameIndex !== -1 ? pathSegments[projectNameIndex + 1] : '';\n // Adjust repoNameIndex to correctly identify the repository name\n const repoNameIndex =\n pathSegments.findIndex(\n (segment, index) =>\n segment === 'repos' &&\n index > Math.max(accountIdIndex, orgNameIndex, projectNameIndex),\n ) + 1;\n const repoName = pathSegments[repoNameIndex];\n const refAndPath = urlParts.slice(\n urlParts.findIndex(i => i === 'files' || i === 'edit') + 1,\n );\n const refIndex = refAndPath.findIndex(item => item === '~');\n\n const refString = refAndPath.slice(0, refIndex).join('/');\n const pathWithoutSlash =\n refIndex !== -1\n ? refAndPath\n .slice(refIndex + 1)\n .join('/')\n .replace(/^\\//, '')\n : '';\n\n return {\n baseUrl: baseUrl,\n accountId: accountId,\n orgName: orgName,\n projectName: projectName,\n refString: refString,\n path: pathWithoutSlash,\n repoName: repoName,\n refDashStr: refAndPath.slice(0, refIndex).join('-'),\n branch:\n refIndex !== -1\n ? refAndPath.slice(0, refIndex).join('/')\n : refAndPath.join('/'),\n };\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n"],"names":[],"mappings":"AA+BgB,SAAA,yBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,SAAA,GAAY,eAAgB,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAA;AAE7C,EAAA,OAAO,CAAG,EAAA,SAAA,CAAU,OAAO,CAAA,YAAA,EAAe,UAAU,SAAS,CAAA,YAAA,EAC3D,SAAU,CAAA,OAAA,KAAY,EAAK,GAAA,CAAA,MAAA,EAAS,SAAU,CAAA,OAAO,KAAK,EAC5D,CAAA,EACE,SAAU,CAAA,WAAA,KAAgB,EAAK,GAAA,CAAA,UAAA,EAAa,SAAU,CAAA,WAAW,KAAK,EACxE,CAAA,OAAA,EAAU,SAAU,CAAA,QAAQ,CAAU,OAAA,EAAA,SAAA,CAAU,MAAM,CAAA,GAAA,EAAM,UAAU,IAAI,CAAA,CAAA,CAAA;AAC5E,CAAA;AAgBgB,SAAA,yBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,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,CAAA,KAAK,MAAM,OAAW,IAAA,CAAA,KAAM,MAAM,CAAI,GAAA,CAAA;AAAA,KAC3D,CAAA;AACA,IAAA,MAAM,QAAW,GAAA,UAAA,CAAW,SAAU,CAAA,CAAA,IAAA,KAAQ,SAAS,GAAG,CAAA,CAAA;AAE1D,IAAA,MAAM,YAAY,UAAW,CAAA,KAAA,CAAM,GAAG,QAAQ,CAAA,CAAE,KAAK,GAAG,CAAA,CAAA;AACxD,IAAA,MAAM,gBACJ,GAAA,QAAA,KAAa,CACT,CAAA,GAAA,UAAA,CACG,MAAM,QAAW,GAAA,CAAC,CAClB,CAAA,IAAA,CAAK,GAAG,CAAA,CACR,OAAQ,CAAA,KAAA,EAAO,EAAE,CACpB,GAAA,EAAA,CAAA;AAEN,IAAO,OAAA;AAAA,MACL,OAAA;AAAA,MACA,SAAA;AAAA,MACA,OAAA;AAAA,MACA,WAAA;AAAA,MACA,SAAA;AAAA,MACA,IAAM,EAAA,gBAAA;AAAA,MACN,QAAA;AAAA,MACA,YAAY,UAAW,CAAA,KAAA,CAAM,GAAG,QAAQ,CAAA,CAAE,KAAK,GAAG,CAAA;AAAA,MAClD,MACE,EAAA,QAAA,KAAa,CACT,CAAA,GAAA,UAAA,CAAW,KAAM,CAAA,CAAA,EAAG,QAAQ,CAAA,CAAE,IAAK,CAAA,GAAG,CACtC,GAAA,UAAA,CAAW,KAAK,GAAG,CAAA;AAAA,KAC3B,CAAA;AAAA,WACO,CAAG,EAAA;AACV,IAAA,MAAM,IAAI,KAAM,CAAA,CAAA,eAAA,EAAkB,GAAG,CAAA,EAAA,EAAK,CAAC,CAAE,CAAA,CAAA,CAAA;AAAA,GAC/C;AACF;;;;"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -2023,7 +2023,9 @@ function buildProjectUrl(target, projectID, config) {
|
|
|
2023
2023
|
async function getProjectId(target, config) {
|
|
2024
2024
|
const url = new URL(target);
|
|
2025
2025
|
if (!url.pathname.includes("/blob/")) {
|
|
2026
|
-
throw new Error(
|
|
2026
|
+
throw new Error(
|
|
2027
|
+
`Failed converting ${url.pathname} to a project id. Url path must include /blob/.`
|
|
2028
|
+
);
|
|
2027
2029
|
}
|
|
2028
2030
|
try {
|
|
2029
2031
|
let repo = url.pathname.split("/-/blob/")[0].split("/blob/")[0];
|
|
@@ -2163,15 +2165,39 @@ function getHarnessEditContentsUrl(config, url) {
|
|
|
2163
2165
|
}
|
|
2164
2166
|
function getHarnessFileContentsUrl(config, url) {
|
|
2165
2167
|
const parsedUrl = parseHarnessUrl(config, url);
|
|
2166
|
-
|
|
2168
|
+
let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;
|
|
2169
|
+
if (parsedUrl.orgName) {
|
|
2170
|
+
constructedUrl += `/${parsedUrl.orgName}`;
|
|
2171
|
+
}
|
|
2172
|
+
if (parsedUrl.projectName) {
|
|
2173
|
+
constructedUrl += `/${parsedUrl.projectName}`;
|
|
2174
|
+
}
|
|
2175
|
+
constructedUrl += `/${parsedUrl.repoName}/+/raw/${parsedUrl.path}?routingId=${parsedUrl.accountId}&git_ref=refs/heads/${parsedUrl.refString}`;
|
|
2176
|
+
return constructedUrl;
|
|
2167
2177
|
}
|
|
2168
2178
|
function getHarnessArchiveUrl(config, url) {
|
|
2169
2179
|
const parsedUrl = parseHarnessUrl(config, url);
|
|
2170
|
-
|
|
2180
|
+
let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;
|
|
2181
|
+
if (parsedUrl.orgName) {
|
|
2182
|
+
constructedUrl += `/${parsedUrl.orgName}`;
|
|
2183
|
+
}
|
|
2184
|
+
if (parsedUrl.projectName) {
|
|
2185
|
+
constructedUrl += `/${parsedUrl.projectName}`;
|
|
2186
|
+
}
|
|
2187
|
+
constructedUrl += `/${parsedUrl.repoName}/+/archive/${parsedUrl.branch}.zip?routingId=${parsedUrl.accountId}`;
|
|
2188
|
+
return constructedUrl;
|
|
2171
2189
|
}
|
|
2172
2190
|
function getHarnessLatestCommitUrl(config, url) {
|
|
2173
2191
|
const parsedUrl = parseHarnessUrl(config, url);
|
|
2174
|
-
|
|
2192
|
+
let constructedUrl = `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}`;
|
|
2193
|
+
if (parsedUrl.orgName) {
|
|
2194
|
+
constructedUrl += `/${parsedUrl.orgName}`;
|
|
2195
|
+
}
|
|
2196
|
+
if (parsedUrl.projectName) {
|
|
2197
|
+
constructedUrl += `/${parsedUrl.projectName}`;
|
|
2198
|
+
}
|
|
2199
|
+
constructedUrl += `/${parsedUrl.repoName}/+/content?routingId=${parsedUrl.accountId}&include_commit=true&git_ref=refs/heads/${parsedUrl.branch}`;
|
|
2200
|
+
return constructedUrl;
|
|
2175
2201
|
}
|
|
2176
2202
|
function getHarnessRequestOptions(config) {
|
|
2177
2203
|
const headers = {};
|
|
@@ -2199,7 +2225,9 @@ function parseHarnessUrl(config, url) {
|
|
|
2199
2225
|
(segment) => segment === "projects"
|
|
2200
2226
|
);
|
|
2201
2227
|
const projectName = projectNameIndex !== -1 ? pathSegments[projectNameIndex + 1] : "";
|
|
2202
|
-
const repoNameIndex = pathSegments.findIndex(
|
|
2228
|
+
const repoNameIndex = pathSegments.findIndex(
|
|
2229
|
+
(segment, index) => segment === "repos" && index > Math.max(accountIdIndex, orgNameIndex, projectNameIndex)
|
|
2230
|
+
) + 1;
|
|
2203
2231
|
const repoName = pathSegments[repoNameIndex];
|
|
2204
2232
|
const refAndPath = urlParts.slice(
|
|
2205
2233
|
urlParts.findIndex((i) => i === "files" || i === "edit") + 1
|