@backstage/integration 1.13.0 → 1.14.0-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 +13 -0
- package/dist/gitlab/core.esm.js +10 -6
- package/dist/gitlab/core.esm.js.map +1 -1
- package/dist/harness/core.esm.js +14 -21
- package/dist/harness/core.esm.js.map +1 -1
- package/dist/index.cjs.js +23 -26
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @backstage/integration
|
|
2
2
|
|
|
3
|
+
## 1.14.0-next.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 78c1329: Updated `GitlabUrlReader.readUrl` and `GitlabUrlReader.readTree` to accept a user-provided token, supporting both bearer and private tokens.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- c591670: Updated functions for `getHarnessEditContentsUrl`, `getHarnessFileContentsUrl`, `getHarnessArchiveUrl`, `getHarnessLatestCommitUrl` and `parseHarnessUrl` to handle account and org level urls
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- @backstage/config@1.2.0
|
|
14
|
+
- @backstage/errors@1.2.4
|
|
15
|
+
|
|
3
16
|
## 1.13.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/dist/gitlab/core.esm.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { getGitLabIntegrationRelativePath } from './config.esm.js';
|
|
2
1
|
import fetch from 'cross-fetch';
|
|
2
|
+
import { getGitLabIntegrationRelativePath } from './config.esm.js';
|
|
3
3
|
|
|
4
4
|
async function getGitLabFileFetchUrl(url, config) {
|
|
5
5
|
const projectID = await getProjectId(url, config);
|
|
6
6
|
return buildProjectUrl(url, projectID, config).toString();
|
|
7
7
|
}
|
|
8
|
-
function getGitLabRequestOptions(config) {
|
|
9
|
-
|
|
8
|
+
function getGitLabRequestOptions(config, token) {
|
|
9
|
+
if (token) {
|
|
10
|
+
return {
|
|
11
|
+
headers: token.startsWith("gl") ? { "PRIVATE-TOKEN": token } : { Authorization: `Bearer ${token}` }
|
|
12
|
+
// Otherwise, it's a bearer token
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const { token: configToken = "" } = config;
|
|
10
16
|
return {
|
|
11
|
-
headers: {
|
|
12
|
-
"PRIVATE-TOKEN": token
|
|
13
|
-
}
|
|
17
|
+
headers: { "PRIVATE-TOKEN": configToken }
|
|
14
18
|
};
|
|
15
19
|
}
|
|
16
20
|
function buildProjectUrl(target, projectID, config) {
|
|
@@ -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 {\n getGitLabIntegrationRelativePath,\n GitLabIntegrationConfig,\n} from './config';\
|
|
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('Please provide full path to yaml file from GitLab');\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,KA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A;AAAA,QACR,CAAiB,cAAA,EAAA,IAAA,CAAK,KAAK,CAAA,GAAA,EAAM,KAAK,iBAAiB,CAAA,CAAA;AAAA,OACzD,CAAA;AAAA,KACF;AAEA,IAAO,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
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
function getHarnessEditContentsUrl(config, url) {
|
|
2
2
|
const parsedUrl = parseHarnessUrl(config, url);
|
|
3
|
-
return `${parsedUrl.baseUrl}/ng/account/${parsedUrl.accountId}/module/code
|
|
3
|
+
return `${parsedUrl.baseUrl}/ng/account/${parsedUrl.accountId}/module/code${parsedUrl.orgName !== "" ? `/orgs/${parsedUrl.orgName}` : ""}${parsedUrl.projectName !== "" ? `/projects/${parsedUrl.projectName}` : ""}/repos/${parsedUrl.repoName}/files/${parsedUrl.branch}/~/${parsedUrl.path}`;
|
|
4
4
|
}
|
|
5
5
|
function getHarnessFileContentsUrl(config, url) {
|
|
6
6
|
const parsedUrl = parseHarnessUrl(config, url);
|
|
7
|
-
return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}/${parsedUrl.orgName}
|
|
7
|
+
return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}/${parsedUrl.orgName}${parsedUrl.projectName !== "" ? `/${parsedUrl.projectName}/` : "/"}${parsedUrl.repoName}/+/raw/${parsedUrl.path}?routingId=${parsedUrl.accountId}&git_ref=refs/heads/${parsedUrl.refString}`;
|
|
8
8
|
}
|
|
9
9
|
function getHarnessArchiveUrl(config, url) {
|
|
10
10
|
const parsedUrl = parseHarnessUrl(config, url);
|
|
11
|
-
return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}/${parsedUrl.orgName}
|
|
11
|
+
return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}/${parsedUrl.orgName}${parsedUrl.projectName !== "" ? `/${parsedUrl.projectName}/` : "/"}${parsedUrl.repoName}/+/archive/${parsedUrl.branch}.zip?routingId=${parsedUrl.accountId}`;
|
|
12
12
|
}
|
|
13
13
|
function getHarnessLatestCommitUrl(config, url) {
|
|
14
14
|
const parsedUrl = parseHarnessUrl(config, url);
|
|
15
|
-
return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}/${parsedUrl.orgName}
|
|
15
|
+
return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}/${parsedUrl.orgName}${parsedUrl.projectName !== "" ? `/${parsedUrl.projectName}/` : "/"}${parsedUrl.repoName}/+/content?routingId=${parsedUrl.accountId}&include_commit=true&git_ref=refs/heads/${parsedUrl.branch}`;
|
|
16
16
|
}
|
|
17
17
|
function getHarnessRequestOptions(config) {
|
|
18
18
|
const headers = {};
|
|
@@ -32,23 +32,16 @@ function parseHarnessUrl(config, url) {
|
|
|
32
32
|
const pathUrl = new URL(url);
|
|
33
33
|
const pathSegments = pathUrl.pathname.split("/").filter((segment) => segment !== "");
|
|
34
34
|
const urlParts = pathUrl.pathname.split("/");
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
_repos,
|
|
46
|
-
repoName,
|
|
47
|
-
_files,
|
|
48
|
-
_ref,
|
|
49
|
-
_branch,
|
|
50
|
-
..._path
|
|
51
|
-
] = pathSegments;
|
|
35
|
+
const accountIdIndex = pathSegments.findIndex((segment) => segment === "account") + 1;
|
|
36
|
+
const accountId = pathSegments[accountIdIndex];
|
|
37
|
+
const orgNameIndex = pathSegments.findIndex((segment) => segment === "orgs");
|
|
38
|
+
const orgName = orgNameIndex !== -1 ? pathSegments[orgNameIndex + 1] : "";
|
|
39
|
+
const projectNameIndex = pathSegments.findIndex(
|
|
40
|
+
(segment) => segment === "projects"
|
|
41
|
+
);
|
|
42
|
+
const projectName = projectNameIndex !== -1 ? pathSegments[projectNameIndex + 1] : "";
|
|
43
|
+
const repoNameIndex = pathSegments.findIndex((segment) => segment === "repos") + 1;
|
|
44
|
+
const repoName = pathSegments[repoNameIndex];
|
|
52
45
|
const refAndPath = urlParts.slice(
|
|
53
46
|
urlParts.findIndex((i) => i === "files" || i === "edit") + 1
|
|
54
47
|
);
|
|
@@ -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 return `${parsedUrl.baseUrl}/ng/account/${parsedUrl.accountId}/module/code/orgs/${parsedUrl.orgName}/projects/${parsedUrl.projectName}/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 * 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 return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}/${parsedUrl.orgName}/${parsedUrl.projectName}/${parsedUrl.repoName}/+/raw/${parsedUrl.path}?routingId=${parsedUrl.accountId}&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/${parsedUrl.accountId}/${parsedUrl.orgName}/${parsedUrl.projectName}/${parsedUrl.repoName}/+/archive/${parsedUrl.branch}.zip?routingId=${parsedUrl.accountId}`;\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/${parsedUrl.accountId}/${parsedUrl.orgName}/${parsedUrl.projectName}/${parsedUrl.repoName}/+/content?routingId=${parsedUrl.accountId}&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 const [\n _ng,\n _account,\n accountId,\n _module,\n _moduleName,\n _org,\n orgName,\n _projects,\n projectName,\n _repos,\n repoName,\n _files,\n _ref,\n _branch,\n ..._path\n ] = pathSegments;\n const refAndPath = urlParts.slice(\n urlParts.findIndex(i => i === 'files' || i === 'edit') + 1,\n );\n const refIndex = refAndPath.findIndex(item => item === '~');\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 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;AAC7C,EAAO,OAAA,CAAA,EAAG,UAAU,OAAO,CAAA,YAAA,EAAe,UAAU,SAAS,CAAA,kBAAA,EAAqB,UAAU,OAAO,CAAA,UAAA,EAAa,UAAU,WAAW,CAAA,OAAA,EAAU,UAAU,QAAQ,CAAA,OAAA,EAAU,UAAU,MAAM,CAAA,GAAA,EAAM,UAAU,IAAI,CAAA,CAAA,CAAA;AACjN,CAAA;AAegB,SAAA,yBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,SAAA,GAAY,eAAgB,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAA;AAC7C,EAAO,OAAA,CAAA,EAAG,UAAU,OAAO,CAAA,2BAAA,EAA8B,UAAU,SAAS,CAAA,CAAA,EAAI,SAAU,CAAA,OAAO,CAAI,CAAA,EAAA,SAAA,CAAU,WAAW,CAAI,CAAA,EAAA,SAAA,CAAU,QAAQ,CAAA,OAAA,EAAU,SAAU,CAAA,IAAI,cAAc,SAAU,CAAA,SAAS,CAAuB,oBAAA,EAAA,SAAA,CAAU,SAAS,CAAA,CAAA,CAAA;AACrP,CAAA;AAgBgB,SAAA,oBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,SAAA,GAAY,eAAgB,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAA;AAC7C,EA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,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;;;;"}
|
|
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,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AE,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
|
@@ -1927,12 +1927,16 @@ async function getGitLabFileFetchUrl(url, config) {
|
|
|
1927
1927
|
const projectID = await getProjectId(url, config);
|
|
1928
1928
|
return buildProjectUrl(url, projectID, config).toString();
|
|
1929
1929
|
}
|
|
1930
|
-
function getGitLabRequestOptions(config) {
|
|
1931
|
-
|
|
1930
|
+
function getGitLabRequestOptions(config, token) {
|
|
1931
|
+
if (token) {
|
|
1932
|
+
return {
|
|
1933
|
+
headers: token.startsWith("gl") ? { "PRIVATE-TOKEN": token } : { Authorization: `Bearer ${token}` }
|
|
1934
|
+
// Otherwise, it's a bearer token
|
|
1935
|
+
};
|
|
1936
|
+
}
|
|
1937
|
+
const { token: configToken = "" } = config;
|
|
1932
1938
|
return {
|
|
1933
|
-
headers: {
|
|
1934
|
-
"PRIVATE-TOKEN": token
|
|
1935
|
-
}
|
|
1939
|
+
headers: { "PRIVATE-TOKEN": configToken }
|
|
1936
1940
|
};
|
|
1937
1941
|
}
|
|
1938
1942
|
function buildProjectUrl(target, projectID, config) {
|
|
@@ -2094,19 +2098,19 @@ function readHarnessConfig(config) {
|
|
|
2094
2098
|
|
|
2095
2099
|
function getHarnessEditContentsUrl(config, url) {
|
|
2096
2100
|
const parsedUrl = parseHarnessUrl(config, url);
|
|
2097
|
-
return `${parsedUrl.baseUrl}/ng/account/${parsedUrl.accountId}/module/code
|
|
2101
|
+
return `${parsedUrl.baseUrl}/ng/account/${parsedUrl.accountId}/module/code${parsedUrl.orgName !== "" ? `/orgs/${parsedUrl.orgName}` : ""}${parsedUrl.projectName !== "" ? `/projects/${parsedUrl.projectName}` : ""}/repos/${parsedUrl.repoName}/files/${parsedUrl.branch}/~/${parsedUrl.path}`;
|
|
2098
2102
|
}
|
|
2099
2103
|
function getHarnessFileContentsUrl(config, url) {
|
|
2100
2104
|
const parsedUrl = parseHarnessUrl(config, url);
|
|
2101
|
-
return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}/${parsedUrl.orgName}
|
|
2105
|
+
return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}/${parsedUrl.orgName}${parsedUrl.projectName !== "" ? `/${parsedUrl.projectName}/` : "/"}${parsedUrl.repoName}/+/raw/${parsedUrl.path}?routingId=${parsedUrl.accountId}&git_ref=refs/heads/${parsedUrl.refString}`;
|
|
2102
2106
|
}
|
|
2103
2107
|
function getHarnessArchiveUrl(config, url) {
|
|
2104
2108
|
const parsedUrl = parseHarnessUrl(config, url);
|
|
2105
|
-
return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}/${parsedUrl.orgName}
|
|
2109
|
+
return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}/${parsedUrl.orgName}${parsedUrl.projectName !== "" ? `/${parsedUrl.projectName}/` : "/"}${parsedUrl.repoName}/+/archive/${parsedUrl.branch}.zip?routingId=${parsedUrl.accountId}`;
|
|
2106
2110
|
}
|
|
2107
2111
|
function getHarnessLatestCommitUrl(config, url) {
|
|
2108
2112
|
const parsedUrl = parseHarnessUrl(config, url);
|
|
2109
|
-
return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}/${parsedUrl.orgName}
|
|
2113
|
+
return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}/${parsedUrl.orgName}${parsedUrl.projectName !== "" ? `/${parsedUrl.projectName}/` : "/"}${parsedUrl.repoName}/+/content?routingId=${parsedUrl.accountId}&include_commit=true&git_ref=refs/heads/${parsedUrl.branch}`;
|
|
2110
2114
|
}
|
|
2111
2115
|
function getHarnessRequestOptions(config) {
|
|
2112
2116
|
const headers = {};
|
|
@@ -2126,23 +2130,16 @@ function parseHarnessUrl(config, url) {
|
|
|
2126
2130
|
const pathUrl = new URL(url);
|
|
2127
2131
|
const pathSegments = pathUrl.pathname.split("/").filter((segment) => segment !== "");
|
|
2128
2132
|
const urlParts = pathUrl.pathname.split("/");
|
|
2129
|
-
const
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
_repos,
|
|
2140
|
-
repoName,
|
|
2141
|
-
_files,
|
|
2142
|
-
_ref,
|
|
2143
|
-
_branch,
|
|
2144
|
-
..._path
|
|
2145
|
-
] = pathSegments;
|
|
2133
|
+
const accountIdIndex = pathSegments.findIndex((segment) => segment === "account") + 1;
|
|
2134
|
+
const accountId = pathSegments[accountIdIndex];
|
|
2135
|
+
const orgNameIndex = pathSegments.findIndex((segment) => segment === "orgs");
|
|
2136
|
+
const orgName = orgNameIndex !== -1 ? pathSegments[orgNameIndex + 1] : "";
|
|
2137
|
+
const projectNameIndex = pathSegments.findIndex(
|
|
2138
|
+
(segment) => segment === "projects"
|
|
2139
|
+
);
|
|
2140
|
+
const projectName = projectNameIndex !== -1 ? pathSegments[projectNameIndex + 1] : "";
|
|
2141
|
+
const repoNameIndex = pathSegments.findIndex((segment) => segment === "repos") + 1;
|
|
2142
|
+
const repoName = pathSegments[repoNameIndex];
|
|
2146
2143
|
const refAndPath = urlParts.slice(
|
|
2147
2144
|
urlParts.findIndex((i) => i === "files" || i === "edit") + 1
|
|
2148
2145
|
);
|