@backstage/integration 1.10.0 → 1.11.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 +6 -0
- package/config.d.ts +18 -0
- package/dist/ScmIntegrations.esm.js +114 -0
- package/dist/ScmIntegrations.esm.js.map +1 -0
- package/dist/awsCodeCommit/AwsCodeCommitIntegration.esm.js +63 -0
- package/dist/awsCodeCommit/AwsCodeCommitIntegration.esm.js.map +1 -0
- package/dist/awsCodeCommit/config.esm.js +28 -0
- package/dist/awsCodeCommit/config.esm.js.map +1 -0
- package/dist/awsS3/AwsS3Integration.esm.js +44 -0
- package/dist/awsS3/AwsS3Integration.esm.js.map +1 -0
- package/dist/awsS3/config.esm.js +51 -0
- package/dist/awsS3/config.esm.js.map +1 -0
- package/dist/azure/AzureIntegration.esm.js +69 -0
- package/dist/azure/AzureIntegration.esm.js.map +1 -0
- package/dist/azure/AzureUrl.esm.js +191 -0
- package/dist/azure/AzureUrl.esm.js.map +1 -0
- package/dist/azure/CachedAzureDevOpsCredentialsProvider.esm.js +80 -0
- package/dist/azure/CachedAzureDevOpsCredentialsProvider.esm.js.map +1 -0
- package/dist/azure/DefaultAzureDevOpsCredentialsProvider.esm.js +76 -0
- package/dist/azure/DefaultAzureDevOpsCredentialsProvider.esm.js.map +1 -0
- package/dist/azure/config.esm.js +153 -0
- package/dist/azure/config.esm.js.map +1 -0
- package/dist/azure/core.esm.js +14 -0
- package/dist/azure/core.esm.js.map +1 -0
- package/dist/azure/deprecated.esm.js +25 -0
- package/dist/azure/deprecated.esm.js.map +1 -0
- package/dist/bitbucket/BitbucketIntegration.esm.js +67 -0
- package/dist/bitbucket/BitbucketIntegration.esm.js.map +1 -0
- package/dist/bitbucket/config.esm.js +45 -0
- package/dist/bitbucket/config.esm.js.map +1 -0
- package/dist/bitbucket/core.esm.js +85 -0
- package/dist/bitbucket/core.esm.js.map +1 -0
- package/dist/bitbucketCloud/BitbucketCloudIntegration.esm.js +56 -0
- package/dist/bitbucketCloud/BitbucketCloudIntegration.esm.js.map +1 -0
- package/dist/bitbucketCloud/config.esm.js +28 -0
- package/dist/bitbucketCloud/config.esm.js.map +1 -0
- package/dist/bitbucketCloud/core.esm.js +68 -0
- package/dist/bitbucketCloud/core.esm.js.map +1 -0
- package/dist/bitbucketServer/BitbucketServerIntegration.esm.js +54 -0
- package/dist/bitbucketServer/BitbucketServerIntegration.esm.js.map +1 -0
- package/dist/bitbucketServer/config.esm.js +34 -0
- package/dist/bitbucketServer/config.esm.js.map +1 -0
- package/dist/bitbucketServer/core.esm.js +63 -0
- package/dist/bitbucketServer/core.esm.js.map +1 -0
- package/dist/gerrit/GerritIntegration.esm.js +58 -0
- package/dist/gerrit/GerritIntegration.esm.js.map +1 -0
- package/dist/gerrit/config.esm.js +58 -0
- package/dist/gerrit/config.esm.js.map +1 -0
- package/dist/gerrit/core.esm.js +106 -0
- package/dist/gerrit/core.esm.js.map +1 -0
- package/dist/gitea/GiteaIntegration.esm.js +40 -0
- package/dist/gitea/GiteaIntegration.esm.js.map +1 -0
- package/dist/gitea/config.esm.js +33 -0
- package/dist/gitea/config.esm.js.map +1 -0
- package/dist/gitea/core.esm.js +53 -0
- package/dist/gitea/core.esm.js.map +1 -0
- package/dist/github/DefaultGithubCredentialsProvider.esm.js +52 -0
- package/dist/github/DefaultGithubCredentialsProvider.esm.js.map +1 -0
- package/dist/github/GithubIntegration.esm.js +56 -0
- package/dist/github/GithubIntegration.esm.js.map +1 -0
- package/dist/github/SingleInstanceGithubCredentialsProvider.esm.js +222 -0
- package/dist/github/SingleInstanceGithubCredentialsProvider.esm.js.map +1 -0
- package/dist/github/config.esm.js +53 -0
- package/dist/github/config.esm.js.map +1 -0
- package/dist/github/core.esm.js +38 -0
- package/dist/github/core.esm.js.map +1 -0
- package/dist/github/deprecated.esm.js +26 -0
- package/dist/github/deprecated.esm.js.map +1 -0
- package/dist/gitlab/DefaultGitlabCredentialsProvider.esm.js +28 -0
- package/dist/gitlab/DefaultGitlabCredentialsProvider.esm.js.map +1 -0
- package/dist/gitlab/GitLabIntegration.esm.js +46 -0
- package/dist/gitlab/GitLabIntegration.esm.js.map +1 -0
- package/dist/gitlab/SingleInstanceGitlabCredentialsProvider.esm.js +29 -0
- package/dist/gitlab/SingleInstanceGitlabCredentialsProvider.esm.js.map +1 -0
- package/dist/gitlab/config.esm.js +57 -0
- package/dist/gitlab/config.esm.js.map +1 -0
- package/dist/gitlab/core.esm.js +69 -0
- package/dist/gitlab/core.esm.js.map +1 -0
- package/dist/googleGcs/config.esm.js +14 -0
- package/dist/googleGcs/config.esm.js.map +1 -0
- package/dist/harness/HarnessIntegration.esm.js +40 -0
- package/dist/harness/HarnessIntegration.esm.js.map +1 -0
- package/dist/harness/config.esm.js +20 -0
- package/dist/harness/config.esm.js.map +1 -0
- package/dist/harness/core.esm.js +73 -0
- package/dist/harness/core.esm.js.map +1 -0
- package/dist/helpers.esm.js +62 -0
- package/dist/helpers.esm.js.map +1 -0
- package/dist/index.cjs.js +214 -85
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +73 -1
- package/dist/index.esm.js +40 -2323
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.esm.js","sources":["../../src/bitbucketServer/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 parseGitUrl from 'git-url-parse';\nimport { BitbucketServerIntegrationConfig } from './config';\n\n/**\n * Given a URL pointing to a path on a provider, returns the default branch.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketServerDefaultBranch(\n url: string,\n config: BitbucketServerIntegrationConfig,\n): Promise<string> {\n const { name: repoName, owner: project } = parseGitUrl(url);\n\n // Bitbucket Server https://docs.atlassian.com/bitbucket-server/rest/7.9.0/bitbucket-rest.html#idp184\n let branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/default-branch`;\n\n let response = await fetch(\n branchUrl,\n getBitbucketServerRequestOptions(config),\n );\n\n if (response.status === 404) {\n // First try the new format, and then if it gets specifically a 404 it should try the old format\n // (to support old Atlassian Bitbucket Server v5.11.1 format )\n branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/branches/default`;\n response = await fetch(branchUrl, getBitbucketServerRequestOptions(config));\n }\n\n if (!response.ok) {\n const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;\n throw new Error(message);\n }\n\n const { displayId } = await response.json();\n const defaultBranch = displayId;\n if (!defaultBranch) {\n throw new Error(\n `Failed to read default branch from ${branchUrl}. ` +\n `Response ${response.status} ${response.json()}`,\n );\n }\n return defaultBranch;\n}\n\n/**\n * Given a URL pointing to a path on a provider, returns a URL that is suitable\n * for downloading the subtree.\n *\n * @param url - A URL pointing to a path\n * @param config - The relevant provider config\n * @public\n */\nexport async function getBitbucketServerDownloadUrl(\n url: string,\n config: BitbucketServerIntegrationConfig,\n): Promise<string> {\n const { name: repoName, owner: project, ref, filepath } = parseGitUrl(url);\n\n let branch = ref;\n if (!branch) {\n branch = await getBitbucketServerDefaultBranch(url, config);\n }\n // path will limit the downloaded content\n // /docs will only download the docs folder and everything below it\n // /docs/index.md will download the docs folder and everything below it\n const path = filepath\n ? `&path=${encodeURIComponent(decodeURIComponent(filepath))}`\n : '';\n return `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=tgz&at=${branch}&prefix=${project}-${repoName}${path}`;\n}\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://bitbucket.company.com/projectname/reponame/src/main/file.yaml\n * to: https://bitbucket.company.com/rest/api/1.0/project/projectname/reponame/raw/file.yaml?at=main\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getBitbucketServerFileFetchUrl(\n url: string,\n config: BitbucketServerIntegrationConfig,\n): string {\n try {\n const { owner, name, ref, filepathtype, filepath } = parseGitUrl(url);\n if (\n !owner ||\n !name ||\n (filepathtype !== 'browse' &&\n filepathtype !== 'raw' &&\n filepathtype !== 'src')\n ) {\n throw new Error('Invalid Bitbucket Server URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n return `${config.apiBaseUrl}/projects/${owner}/repos/${name}/raw/${pathWithoutSlash}?at=${ref}`;\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n *\n * @param config - The relevant provider config\n * @public\n */\nexport function getBitbucketServerRequestOptions(\n config: BitbucketServerIntegrationConfig,\n): { headers: Record<string, string> } {\n const headers: Record<string, string> = {};\n\n if (config.token) {\n headers.Authorization = `Bearer ${config.token}`;\n } else if (config.username && config.password) {\n const buffer = Buffer.from(`${config.username}:${config.password}`, 'utf8');\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n }\n\n return {\n headers,\n };\n}\n"],"names":[],"mappings":";;;AA2BsB,eAAA,+BAAA,CACpB,KACA,MACiB,EAAA;AACjB,EAAA,MAAM,EAAE,IAAM,EAAA,QAAA,EAAU,OAAO,OAAQ,EAAA,GAAI,YAAY,GAAG,CAAA,CAAA;AAG1D,EAAA,IAAI,YAAY,CAAG,EAAA,MAAA,CAAO,UAAU,CAAa,UAAA,EAAA,OAAO,UAAU,QAAQ,CAAA,eAAA,CAAA,CAAA;AAE1E,EAAA,IAAI,WAAW,MAAM,KAAA;AAAA,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aAAA,GAAgB,CAAU,OAAA,EAAA,MAAA,CAAO,KAAK,CAAA,CAAA,CAAA;AAAA,GACrC,MAAA,IAAA,MAAA,CAAO,QAAY,IAAA,MAAA,CAAO,QAAU,EAAA;AAC7C,IAAM,MAAA,MAAA,GAAS,MAAO,CAAA,IAAA,CAAK,CAAG,EAAA,MAAA,CAAO,QAAQ,CAAI,CAAA,EAAA,MAAA,CAAO,QAAQ,CAAA,CAAA,EAAI,MAAM,CAAA,CAAA;AAC1E,IAAA,OAAA,CAAQ,aAAgB,GAAA,CAAA,MAAA,EAAS,MAAO,CAAA,QAAA,CAAS,QAAQ,CAAC,CAAA,CAAA,CAAA;AAAA,GAC5D;AAEA,EAAO,OAAA;AAAA,IACL,OAAA;AAAA,GACF,CAAA;AACF;;;;"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { basicIntegrations } from '../helpers.esm.js';
|
|
2
|
+
import { readGerritIntegrationConfigs } from './config.esm.js';
|
|
3
|
+
import { parseGerritGitilesUrl, buildGerritGitilesUrl } from './core.esm.js';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __publicField = (obj, key, value) => {
|
|
8
|
+
__defNormalProp(obj, key + "" , value);
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
const _GerritIntegration = class _GerritIntegration {
|
|
12
|
+
constructor(integrationConfig) {
|
|
13
|
+
this.integrationConfig = integrationConfig;
|
|
14
|
+
}
|
|
15
|
+
get type() {
|
|
16
|
+
return "gerrit";
|
|
17
|
+
}
|
|
18
|
+
get title() {
|
|
19
|
+
return this.integrationConfig.host;
|
|
20
|
+
}
|
|
21
|
+
get config() {
|
|
22
|
+
return this.integrationConfig;
|
|
23
|
+
}
|
|
24
|
+
resolveUrl(options) {
|
|
25
|
+
const { url, base, lineNumber } = options;
|
|
26
|
+
let updated;
|
|
27
|
+
if (url.startsWith("/")) {
|
|
28
|
+
const { branch, project } = parseGerritGitilesUrl(this.config, base);
|
|
29
|
+
return buildGerritGitilesUrl(this.config, project, branch, url);
|
|
30
|
+
}
|
|
31
|
+
if (url) {
|
|
32
|
+
updated = new URL(url, base);
|
|
33
|
+
} else {
|
|
34
|
+
updated = new URL(base);
|
|
35
|
+
}
|
|
36
|
+
if (lineNumber) {
|
|
37
|
+
updated.hash = lineNumber.toString();
|
|
38
|
+
}
|
|
39
|
+
return updated.toString();
|
|
40
|
+
}
|
|
41
|
+
resolveEditUrl(url) {
|
|
42
|
+
return url;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
__publicField(_GerritIntegration, "factory", ({ config }) => {
|
|
46
|
+
var _a;
|
|
47
|
+
const configs = readGerritIntegrationConfigs(
|
|
48
|
+
(_a = config.getOptionalConfigArray("integrations.gerrit")) != null ? _a : []
|
|
49
|
+
);
|
|
50
|
+
return basicIntegrations(
|
|
51
|
+
configs.map((c) => new _GerritIntegration(c)),
|
|
52
|
+
(i) => i.config.host
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
let GerritIntegration = _GerritIntegration;
|
|
56
|
+
|
|
57
|
+
export { GerritIntegration };
|
|
58
|
+
//# sourceMappingURL=GerritIntegration.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GerritIntegration.esm.js","sources":["../../src/gerrit/GerritIntegration.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 */\n\nimport { basicIntegrations } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport {\n GerritIntegrationConfig,\n readGerritIntegrationConfigs,\n} from './config';\nimport { parseGerritGitilesUrl, buildGerritGitilesUrl } from './core';\n\n/**\n * A Gerrit based integration.\n *\n * @public\n */\nexport class GerritIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GerritIntegration> = ({ config }) => {\n const configs = readGerritIntegrationConfigs(\n config.getOptionalConfigArray('integrations.gerrit') ?? [],\n );\n return basicIntegrations(\n configs.map(c => new GerritIntegration(c)),\n i => i.config.host,\n );\n };\n\n constructor(private readonly integrationConfig: GerritIntegrationConfig) {}\n\n get type(): string {\n return 'gerrit';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GerritIntegrationConfig {\n return this.integrationConfig;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n }): string {\n const { url, base, lineNumber } = options;\n let updated;\n if (url.startsWith('/')) {\n const { branch, project } = parseGerritGitilesUrl(this.config, base);\n return buildGerritGitilesUrl(this.config, project, branch, url);\n }\n if (url) {\n updated = new URL(url, base);\n } else {\n updated = new URL(base);\n }\n if (lineNumber) {\n updated.hash = lineNumber.toString();\n }\n return updated.toString();\n }\n\n resolveEditUrl(url: string): string {\n // Not applicable for gerrit.\n return url;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AA6BO,MAAM,kBAAA,GAAN,MAAM,kBAA4C,CAAA;AAAA,EAWvD,YAA6B,iBAA4C,EAAA;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA,CAAA;AAAA,GAA6C;AAAA,EAE1E,IAAI,IAAe,GAAA;AACjB,IAAO,OAAA,QAAA,CAAA;AAAA,GACT;AAAA,EAEA,IAAI,KAAgB,GAAA;AAClB,IAAA,OAAO,KAAK,iBAAkB,CAAA,IAAA,CAAA;AAAA,GAChC;AAAA,EAEA,IAAI,MAAkC,GAAA;AACpC,IAAA,OAAO,IAAK,CAAA,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AA,CAAA,KAAK,EAAE,MAAO,CAAA,IAAA;AAAA,GAChB,CAAA;AACF,CAAA,CAAA,CAAA;AATK,IAAM,iBAAN,GAAA;;;;"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { trimEnd } from 'lodash';
|
|
2
|
+
import { isValidHost, isValidUrl } from '../helpers.esm.js';
|
|
3
|
+
|
|
4
|
+
function readGerritIntegrationConfig(config) {
|
|
5
|
+
var _a;
|
|
6
|
+
const host = config.getString("host");
|
|
7
|
+
let baseUrl = config.getOptionalString("baseUrl");
|
|
8
|
+
let cloneUrl = config.getOptionalString("cloneUrl");
|
|
9
|
+
let gitilesBaseUrl = config.getOptionalString("gitilesBaseUrl");
|
|
10
|
+
const username = config.getOptionalString("username");
|
|
11
|
+
const password = (_a = config.getOptionalString("password")) == null ? void 0 : _a.trim();
|
|
12
|
+
if (!isValidHost(host)) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
`Invalid Gerrit integration config, '${host}' is not a valid host`
|
|
15
|
+
);
|
|
16
|
+
} else if (baseUrl && !isValidUrl(baseUrl)) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Invalid Gerrit integration config, '${baseUrl}' is not a valid baseUrl`
|
|
19
|
+
);
|
|
20
|
+
} else if (cloneUrl && !isValidUrl(cloneUrl)) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`Invalid Gerrit integration config, '${cloneUrl}' is not a valid cloneUrl`
|
|
23
|
+
);
|
|
24
|
+
} else if (gitilesBaseUrl && !isValidUrl(gitilesBaseUrl)) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`Invalid Gerrit integration config, '${gitilesBaseUrl}' is not a valid gitilesBaseUrl`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
if (baseUrl) {
|
|
30
|
+
baseUrl = trimEnd(baseUrl, "/");
|
|
31
|
+
} else {
|
|
32
|
+
baseUrl = `https://${host}`;
|
|
33
|
+
}
|
|
34
|
+
if (gitilesBaseUrl) {
|
|
35
|
+
gitilesBaseUrl = trimEnd(gitilesBaseUrl, "/");
|
|
36
|
+
} else {
|
|
37
|
+
gitilesBaseUrl = `https://${host}`;
|
|
38
|
+
}
|
|
39
|
+
if (cloneUrl) {
|
|
40
|
+
cloneUrl = trimEnd(cloneUrl, "/");
|
|
41
|
+
} else {
|
|
42
|
+
cloneUrl = baseUrl;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
host,
|
|
46
|
+
baseUrl,
|
|
47
|
+
cloneUrl,
|
|
48
|
+
gitilesBaseUrl,
|
|
49
|
+
username,
|
|
50
|
+
password
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function readGerritIntegrationConfigs(configs) {
|
|
54
|
+
return configs.map(readGerritIntegrationConfig);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { readGerritIntegrationConfig, readGerritIntegrationConfigs };
|
|
58
|
+
//# sourceMappingURL=config.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.esm.js","sources":["../../src/gerrit/config.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 */\n\nimport { Config } from '@backstage/config';\nimport { trimEnd } from 'lodash';\nimport { isValidHost, isValidUrl } from '../helpers';\n\n/**\n * The configuration parameters for a single Gerrit API provider.\n *\n * @public\n */\nexport type GerritIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. \"gerrit-review.com\"\n */\n host: string;\n\n /**\n * The optional base URL of the Gerrit instance. It is assumed that https\n * is used and that the base path is \"/\" on the host. If that is not the\n * case set the complete base url to the gerrit instance, e.g.\n * \"https://gerrit-review.com/gerrit\". This is the url that you would open\n * in a browser.\n */\n baseUrl?: string;\n\n /**\n * The optional base url to use for cloning a repository. If not set the\n * baseUrl will be used.\n */\n cloneUrl?: string;\n\n /**\n * Optional base url for Gitiles. This is needed for creating a valid\n * user-friendly url that can be used for browsing the content of the\n * provider. If not set a default value will be created in the same way\n * as the \"baseUrl\" option.\n */\n gitilesBaseUrl?: string;\n\n /**\n * The username to use for requests to gerrit.\n */\n username?: string;\n\n /**\n * The password or http token to use for authentication.\n */\n password?: string;\n};\n\n/**\n * Reads a single Gerrit integration config.\n *\n * @param config - The config object of a single integration\n *\n * @public\n */\nexport function readGerritIntegrationConfig(\n config: Config,\n): GerritIntegrationConfig {\n const host = config.getString('host');\n let baseUrl = config.getOptionalString('baseUrl');\n let cloneUrl = config.getOptionalString('cloneUrl');\n let gitilesBaseUrl = config.getOptionalString('gitilesBaseUrl');\n const username = config.getOptionalString('username');\n const password = config.getOptionalString('password')?.trim();\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid Gerrit integration config, '${host}' is not a valid host`,\n );\n } else if (baseUrl && !isValidUrl(baseUrl)) {\n throw new Error(\n `Invalid Gerrit integration config, '${baseUrl}' is not a valid baseUrl`,\n );\n } else if (cloneUrl && !isValidUrl(cloneUrl)) {\n throw new Error(\n `Invalid Gerrit integration config, '${cloneUrl}' is not a valid cloneUrl`,\n );\n } else if (gitilesBaseUrl && !isValidUrl(gitilesBaseUrl)) {\n throw new Error(\n `Invalid Gerrit integration config, '${gitilesBaseUrl}' is not a valid gitilesBaseUrl`,\n );\n }\n if (baseUrl) {\n baseUrl = trimEnd(baseUrl, '/');\n } else {\n baseUrl = `https://${host}`;\n }\n if (gitilesBaseUrl) {\n gitilesBaseUrl = trimEnd(gitilesBaseUrl, '/');\n } else {\n gitilesBaseUrl = `https://${host}`;\n }\n if (cloneUrl) {\n cloneUrl = trimEnd(cloneUrl, '/');\n } else {\n cloneUrl = baseUrl;\n }\n\n return {\n host,\n baseUrl,\n cloneUrl,\n gitilesBaseUrl,\n username,\n password,\n };\n}\n\n/**\n * Reads a set of Gerrit integration configs.\n *\n * @param configs - All of the integration config objects\n *\n * @public\n */\nexport function readGerritIntegrationConfigs(\n configs: Config[],\n): GerritIntegrationConfig[] {\n return configs.map(readGerritIntegrationConfig);\n}\n"],"names":[],"mappings":";;;AAwEO,SAAS,4BACd,MACyB,EAAA;AA1E3B,EAAA,IAAA,EAAA,CAAA;AA2EE,EAAM,MAAA,IAAA,GAAO,MAAO,CAAA,SAAA,CAAU,MAAM,CAAA,CAAA;AACpC,EAAI,IAAA,OAAA,GAAU,MAAO,CAAA,iBAAA,CAAkB,SAAS,CAAA,CAAA;AAChD,EAAI,IAAA,QAAA,GAAW,MAAO,CAAA,iBAAA,CAAkB,UAAU,CAAA,CAAA;AAClD,EAAI,IAAA,cAAA,GAAiB,MAAO,CAAA,iBAAA,CAAkB,gBAAgB,CAAA,CAAA;AAC9D,EAAM,MAAA,QAAA,GAAW,MAAO,CAAA,iBAAA,CAAkB,UAAU,CAAA,CAAA;AACpD,EAAA,MAAM,QAAW,GAAA,CAAA,EAAA,GAAA,MAAA,CAAO,iBAAkB,CAAA,UAAU,MAAnC,IAAsC,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,IAAA,EAAA,CAAA;AAEvD,EAAI,IAAA,CAAC,WAAY,CAAA,IAAI,CAAG,EAAA;AACtB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,uCAAuC,IAAI,CAAA,qBAAA,CAAA;AAAA,KAC7C,CAAA;AAAA,GACS,MAAA,IAAA,OAAA,IAAW,CAAC,UAAA,CAAW,OAAO,CAAG,EAAA;AAC1C,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,uCAAuC,OAAO,CAAA,wBAAA,CAAA;AAAA,KAChD,CAAA;AAAA,GACS,MAAA,IAAA,QAAA,IAAY,CAAC,UAAA,CAAW,QAAQ,CAAG,EAAA;AAC5C,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,uCAAuC,QAAQ,CAAA,yBAAA,CAAA;AAAA,KACjD,CAAA;AAAA,GACS,MAAA,IAAA,cAAA,IAAkB,CAAC,UAAA,CAAW,cAAc,CAAG,EAAA;AACxD,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,uCAAuC,cAAc,CAAA,+BAAA,CAAA;AAAA,KACvD,CAAA;AAAA,GACF;AACA,EAAA,IAAI,OAAS,EAAA;AACX,IAAU,OAAA,GAAA,OAAA,CAAQ,SAAS,GAAG,CAAA,CAAA;AAAA,GACzB,MAAA;AACL,IAAA,OAAA,GAAU,WAAW,IAAI,CAAA,CAAA,CAAA;AAAA,GAC3B;AACA,EAAA,IAAI,cAAgB,EAAA;AAClB,IAAiB,cAAA,GAAA,OAAA,CAAQ,gBAAgB,GAAG,CAAA,CAAA;AAAA,GACvC,MAAA;AACL,IAAA,cAAA,GAAiB,WAAW,IAAI,CAAA,CAAA,CAAA;AAAA,GAClC;AACA,EAAA,IAAI,QAAU,EAAA;AACZ,IAAW,QAAA,GAAA,OAAA,CAAQ,UAAU,GAAG,CAAA,CAAA;AAAA,GAC3B,MAAA;AACL,IAAW,QAAA,GAAA,OAAA,CAAA;AAAA,GACb;AAEA,EAAO,OAAA;AAAA,IACL,IAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA;AAAA,IACA,cAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,GACF,CAAA;AACF,CAAA;AASO,SAAS,6BACd,OAC2B,EAAA;AAC3B,EAAO,OAAA,OAAA,CAAQ,IAAI,2BAA2B,CAAA,CAAA;AAChD;;;;"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { trimStart } from 'lodash';
|
|
2
|
+
|
|
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
|
+
function buildGerritGitilesUrl(config, project, branch, filePath) {
|
|
27
|
+
return `${config.gitilesBaseUrl}/${project}/+/refs/heads/${branch}/${trimStart(filePath, "/")}`;
|
|
28
|
+
}
|
|
29
|
+
function buildGerritGitilesArchiveUrl(config, project, branch, filePath) {
|
|
30
|
+
const archiveName = filePath === "/" || filePath === "" ? ".tar.gz" : `/${filePath}.tar.gz`;
|
|
31
|
+
return `${getGitilesAuthenticationUrl(
|
|
32
|
+
config
|
|
33
|
+
)}/${project}/+archive/refs/heads/${branch}${archiveName}`;
|
|
34
|
+
}
|
|
35
|
+
function getAuthenticationPrefix(config) {
|
|
36
|
+
return config.password ? "/a/" : "/";
|
|
37
|
+
}
|
|
38
|
+
function getGitilesAuthenticationUrl(config) {
|
|
39
|
+
if (!config.baseUrl || !config.gitilesBaseUrl) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
"Unexpected Gerrit config values. baseUrl or gitilesBaseUrl not set."
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
if (config.gitilesBaseUrl.startsWith(config.baseUrl)) {
|
|
45
|
+
return config.gitilesBaseUrl.replace(
|
|
46
|
+
config.baseUrl.concat("/"),
|
|
47
|
+
config.baseUrl.concat(getAuthenticationPrefix(config))
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
if (config.password) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
"Since the baseUrl (Gerrit) is not part of the gitilesBaseUrl, an authentication URL could not be constructed."
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return config.gitilesBaseUrl;
|
|
56
|
+
}
|
|
57
|
+
function getGerritBranchApiUrl(config, url) {
|
|
58
|
+
const { branch, project } = parseGerritGitilesUrl(config, url);
|
|
59
|
+
return `${config.baseUrl}${getAuthenticationPrefix(
|
|
60
|
+
config
|
|
61
|
+
)}projects/${encodeURIComponent(project)}/branches/${branch}`;
|
|
62
|
+
}
|
|
63
|
+
function getGerritCloneRepoUrl(config, url) {
|
|
64
|
+
const { project } = parseGerritGitilesUrl(config, url);
|
|
65
|
+
return `${config.cloneUrl}${getAuthenticationPrefix(config)}${project}`;
|
|
66
|
+
}
|
|
67
|
+
function getGerritFileContentsApiUrl(config, url) {
|
|
68
|
+
const { branch, filePath, project } = parseGerritGitilesUrl(config, url);
|
|
69
|
+
return `${config.baseUrl}${getAuthenticationPrefix(
|
|
70
|
+
config
|
|
71
|
+
)}projects/${encodeURIComponent(
|
|
72
|
+
project
|
|
73
|
+
)}/branches/${branch}/files/${encodeURIComponent(filePath)}/content`;
|
|
74
|
+
}
|
|
75
|
+
function getGerritProjectsApiUrl(config) {
|
|
76
|
+
return `${config.baseUrl}${getAuthenticationPrefix(config)}projects/`;
|
|
77
|
+
}
|
|
78
|
+
function getGerritRequestOptions(config) {
|
|
79
|
+
const headers = {};
|
|
80
|
+
if (!config.password) {
|
|
81
|
+
return headers;
|
|
82
|
+
}
|
|
83
|
+
const buffer = Buffer.from(`${config.username}:${config.password}`, "utf8");
|
|
84
|
+
headers.Authorization = `Basic ${buffer.toString("base64")}`;
|
|
85
|
+
return {
|
|
86
|
+
headers
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
async function parseGerritJsonResponse(response) {
|
|
90
|
+
const responseBody = await response.text();
|
|
91
|
+
if (responseBody.startsWith(GERRIT_BODY_PREFIX)) {
|
|
92
|
+
try {
|
|
93
|
+
return JSON.parse(responseBody.slice(GERRIT_BODY_PREFIX.length));
|
|
94
|
+
} catch (ex) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`Invalid response from Gerrit: ${responseBody.slice(0, 10)} - ${ex}`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
throw new Error(
|
|
101
|
+
`Gerrit JSON body prefix missing. Found: ${responseBody.slice(0, 10)}`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { buildGerritGitilesArchiveUrl, buildGerritGitilesUrl, getAuthenticationPrefix, getGerritBranchApiUrl, getGerritCloneRepoUrl, getGerritFileContentsApiUrl, getGerritProjectsApiUrl, getGerritRequestOptions, getGitilesAuthenticationUrl, parseGerritGitilesUrl, parseGerritJsonResponse };
|
|
106
|
+
//# sourceMappingURL=core.esm.js.map
|
|
@@ -0,0 +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 { 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 */\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 * Build a Gerrit Gitiles url that targets a specific path.\n *\n * @param config - A Gerrit provider config.\n * @param project - The name of the git project\n * @param branch - The branch we will target.\n * @param filePath - The absolute file path.\n * @public\n */\nexport function buildGerritGitilesUrl(\n config: GerritIntegrationConfig,\n project: string,\n branch: string,\n filePath: string,\n): string {\n return `${\n config.gitilesBaseUrl\n }/${project}/+/refs/heads/${branch}/${trimStart(filePath, '/')}`;\n}\n\n/**\n * Build a Gerrit Gitiles archive url that targets a specific branch and path\n *\n * @param config - A Gerrit provider config.\n * @param project - The name of the git project\n * @param branch - The branch we will target.\n * @param filePath - The absolute file path.\n * @public\n */\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 * Return the authentication prefix.\n *\n * @remarks\n *\n * To authenticate with a password the API url must be prefixed with \"/a/\".\n * If no password is set anonymous access (without the prefix) will\n * be used.\n *\n * @param config - A Gerrit provider config.\n * @public\n */\nexport function getAuthenticationPrefix(\n config: GerritIntegrationConfig,\n): string {\n return config.password ? '/a/' : '/';\n}\n\n/**\n * Return the authentication gitiles url.\n *\n * @remarks\n *\n * To authenticate with a password the API url must be prefixed with \"/a/\".\n * If no password is set anonymous access (without the prefix) will\n * be used.\n *\n * @param config - A Gerrit provider config.\n */\nexport function getGitilesAuthenticationUrl(\n config: GerritIntegrationConfig,\n): string {\n if (!config.baseUrl || !config.gitilesBaseUrl) {\n throw new Error(\n 'Unexpected Gerrit config values. baseUrl or gitilesBaseUrl not set.',\n );\n }\n if (config.gitilesBaseUrl.startsWith(config.baseUrl)) {\n return config.gitilesBaseUrl.replace(\n config.baseUrl.concat('/'),\n config.baseUrl.concat(getAuthenticationPrefix(config)),\n );\n }\n if (config.password) {\n throw new Error(\n 'Since the baseUrl (Gerrit) is not part of the gitilesBaseUrl, an authentication URL could not be constructed.',\n );\n }\n return config.gitilesBaseUrl!;\n}\n\n/**\n * Return the url to get branch info from the Gerrit API.\n *\n * @param config - A Gerrit provider config.\n * @param url - An url pointing to a file in git.\n * @public\n */\nexport function getGerritBranchApiUrl(\n config: GerritIntegrationConfig,\n url: string,\n) {\n const { branch, project } = parseGerritGitilesUrl(config, url);\n\n return `${config.baseUrl}${getAuthenticationPrefix(\n config,\n )}projects/${encodeURIComponent(project)}/branches/${branch}`;\n}\n\n/**\n * Return the url to clone the repo that is referenced by the url.\n *\n * @param url - An url pointing to a file in git.\n * @public\n */\nexport function getGerritCloneRepoUrl(\n config: GerritIntegrationConfig,\n url: string,\n) {\n const { project } = parseGerritGitilesUrl(config, url);\n\n return `${config.cloneUrl}${getAuthenticationPrefix(config)}${project}`;\n}\n\n/**\n * Return the url to fetch the contents of a file using the Gerrit API.\n *\n * @param config - A Gerrit provider config.\n * @param url - An url pointing to a file in git.\n * @public\n */\nexport function getGerritFileContentsApiUrl(\n config: GerritIntegrationConfig,\n url: string,\n) {\n const { branch, filePath, project } = parseGerritGitilesUrl(config, url);\n\n return `${config.baseUrl}${getAuthenticationPrefix(\n config,\n )}projects/${encodeURIComponent(\n project,\n )}/branches/${branch}/files/${encodeURIComponent(filePath)}/content`;\n}\n\n/**\n * Return the url to query available projects using the Gerrit API.\n *\n * @param config - A Gerrit provider config.\n * @public\n */\nexport function getGerritProjectsApiUrl(config: GerritIntegrationConfig) {\n return `${config.baseUrl}${getAuthenticationPrefix(config)}projects/`;\n}\n\n/**\n * Return request headers for a Gerrit provider.\n *\n * @param config - A Gerrit provider config\n * @public\n */\nexport function getGerritRequestOptions(config: GerritIntegrationConfig): {\n headers?: Record<string, string>;\n} {\n const headers: Record<string, string> = {};\n\n if (!config.password) {\n return headers;\n }\n const buffer = Buffer.from(`${config.username}:${config.password}`, 'utf8');\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n return {\n headers,\n };\n}\n\n/**\n * Parse the json response from Gerrit and strip the magic prefix.\n *\n * @remarks\n *\n * To prevent against XSSI attacks the JSON response body from Gerrit starts\n * with a magic prefix that must be stripped before it can be fed to a JSON\n * parser.\n *\n * @param response - An API response.\n * @public\n */\nexport async function parseGerritJsonResponse(\n response: Response,\n): Promise<unknown> {\n const responseBody = await response.text();\n if (responseBody.startsWith(GERRIT_BODY_PREFIX)) {\n try {\n return JSON.parse(responseBody.slice(GERRIT_BODY_PREFIX.length));\n } catch (ex) {\n throw new Error(\n `Invalid response from Gerrit: ${responseBody.slice(0, 10)} - ${ex}`,\n );\n }\n }\n throw new Error(\n `Gerrit JSON body prefix missing. Found: ${responseBody.slice(0, 10)}`,\n );\n}\n"],"names":[],"mappings":";;AAkBA,MAAM,kBAAqB,GAAA,MAAA,CAAA;AA2BX,SAAA,qBAAA,CACd,QACA,GACuD,EAAA;AACvD,EAAA,MAAM,YAAe,GAAA,IAAI,GAAI,CAAA,MAAA,CAAO,cAAe,CAAA,CAAA;AACnD,EAAM,MAAA,QAAA,GAAW,IAAI,GAAA,CAAI,GAAG,CAAA,CAAA;AAM5B,EAAA,MAAM,OAAU,GAAA,QAAA,CAAS,QACtB,CAAA,SAAA,CAAU,SAAS,QAAS,CAAA,UAAA,CAAW,KAAK,CAAA,GAAI,IAAI,CAAC,CAAA,CACrD,OAAQ,CAAA,YAAA,CAAa,UAAU,EAAE,CAAA,CAAA;AAEpC,EAAM,MAAA,KAAA,GAAQ,QAAQ,KAAM,CAAA,GAAG,EAAE,MAAO,CAAA,CAAA,CAAA,KAAK,CAAC,CAAC,CAAC,CAAA,CAAA;AAEhD,EAAM,MAAA,eAAA,GAAkB,KAAM,CAAA,OAAA,CAAQ,GAAG,CAAA,CAAA;AAEzC,EAAA,IAAI,mBAAmB,CAAG,EAAA;AACxB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAqC,kCAAA,EAAA,GAAG,CAAE,CAAA,CAAA,CAAA;AAAA,GAC5D;AACA,EAAM,MAAA,OAAA,GAAU,SAAU,CAAA,KAAA,CAAM,KAAM,CAAA,CAAA,EAAG,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;AACF,MAAA,OAAO,KAAK,KAAM,CAAA,YAAA,CAAa,KAAM,CAAA,kBAAA,CAAmB,MAAM,CAAC,CAAA,CAAA;AAAA,aACxD,EAAI,EAAA;AACX,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,iCAAiC,YAAa,CAAA,KAAA,CAAM,GAAG,EAAE,CAAC,MAAM,EAAE,CAAA,CAAA;AAAA,OACpE,CAAA;AAAA,KACF;AAAA,GACF;AACA,EAAA,MAAM,IAAI,KAAA;AAAA,IACR,CAA2C,wCAAA,EAAA,YAAA,CAAa,KAAM,CAAA,CAAA,EAAG,EAAE,CAAC,CAAA,CAAA;AAAA,GACtE,CAAA;AACF;;;;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { basicIntegrations, defaultScmResolveUrl } from '../helpers.esm.js';
|
|
2
|
+
import { readGiteaConfig } from './config.esm.js';
|
|
3
|
+
import { getGiteaEditContentsUrl } from './core.esm.js';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __publicField = (obj, key, value) => {
|
|
8
|
+
__defNormalProp(obj, key + "" , value);
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
const _GiteaIntegration = class _GiteaIntegration {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
}
|
|
15
|
+
get type() {
|
|
16
|
+
return "gitea";
|
|
17
|
+
}
|
|
18
|
+
get title() {
|
|
19
|
+
return this.config.host;
|
|
20
|
+
}
|
|
21
|
+
resolveUrl(options) {
|
|
22
|
+
return defaultScmResolveUrl(options);
|
|
23
|
+
}
|
|
24
|
+
resolveEditUrl(url) {
|
|
25
|
+
return getGiteaEditContentsUrl(this.config, url);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
__publicField(_GiteaIntegration, "factory", ({ config }) => {
|
|
29
|
+
var _a;
|
|
30
|
+
const configs = (_a = config.getOptionalConfigArray("integrations.gitea")) != null ? _a : [];
|
|
31
|
+
const giteaConfigs = configs.map((c) => readGiteaConfig(c));
|
|
32
|
+
return basicIntegrations(
|
|
33
|
+
giteaConfigs.map((c) => new _GiteaIntegration(c)),
|
|
34
|
+
(gitea) => gitea.config.host
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
let GiteaIntegration = _GiteaIntegration;
|
|
38
|
+
|
|
39
|
+
export { GiteaIntegration };
|
|
40
|
+
//# sourceMappingURL=GiteaIntegration.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GiteaIntegration.esm.js","sources":["../../src/gitea/GiteaIntegration.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 { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport { GiteaIntegrationConfig, readGiteaConfig } from './config';\nimport { getGiteaEditContentsUrl } from './core';\n\n/**\n * A Gitea based integration.\n *\n * @public\n */\nexport class GiteaIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GiteaIntegration> = ({ config }) => {\n const configs = config.getOptionalConfigArray('integrations.gitea') ?? [];\n const giteaConfigs = configs.map(c => readGiteaConfig(c));\n\n return basicIntegrations(\n giteaConfigs.map(c => new GiteaIntegration(c)),\n (gitea: GiteaIntegration) => gitea.config.host,\n );\n };\n\n constructor(readonly config: GiteaIntegrationConfig) {}\n\n get type(): string {\n return 'gitea';\n }\n\n get title(): string {\n return this.config.host;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number | undefined;\n }): string {\n return defaultScmResolveUrl(options);\n }\n\n resolveEditUrl(url: string): string {\n return getGiteaEditContentsUrl(this.config, url);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAyBO,MAAM,iBAAA,GAAN,MAAM,iBAA2C,CAAA;AAAA,EAWtD,YAAqB,MAAgC,EAAA;AAAhC,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA,CAAA;AAAA,GAAiC;AAAA,EAEtD,IAAI,IAAe,GAAA;AACjB,IAAO,OAAA,OAAA,CAAA;AAAA,GACT;AAAA,EAEA,IAAI,KAAgB,GAAA;AAClB,IAAA,OAAO,KAAK,MAAO,CAAA,IAAA,CAAA;AAAA,GACrB;AAAA,EAEA,WAAW,OAIA,EAAA;AACT,IAAA,OAAO,qBAAqB,OAAO,CAAA,CAAA;AAAA,GACrC;AAAA,EAEA,eAAe,GAAqB,EAAA;AAClC,IAAO,OAAA,uBAAA,CAAwB,IAAK,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAA;AAAA,GACjD;AACF,CAAA,CAAA;AA/BE,aAAA,CADW,iBACJ,EAAA,SAAA,EAAoD,CAAC,EAAE,QAAa,KAAA;AA1B7E,EAAA,IAAA,EAAA,CAAA;AA2BI,EAAA,MAAM,WAAU,EAAO,GAAA,MAAA,CAAA,sBAAA,CAAuB,oBAAoB,CAAA,KAAlD,YAAuD,EAAC,CAAA;AACxE,EAAA,MAAM,eAAe,OAAQ,CAAA,GAAA,CAAI,CAAK,CAAA,KAAA,eAAA,CAAgB,CAAC,CAAC,CAAA,CAAA;AAExD,EAAO,OAAA,iBAAA;AAAA,IACL,aAAa,GAAI,CAAA,CAAA,CAAA,KAAK,IAAI,iBAAA,CAAiB,CAAC,CAAC,CAAA;AAAA,IAC7C,CAAC,KAA4B,KAAA,KAAA,CAAM,MAAO,CAAA,IAAA;AAAA,GAC5C,CAAA;AACF,CAAA,CAAA,CAAA;AATK,IAAM,gBAAN,GAAA;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { trimEnd } from 'lodash';
|
|
2
|
+
import { isValidHost, isValidUrl } from '../helpers.esm.js';
|
|
3
|
+
|
|
4
|
+
function readGiteaConfig(config) {
|
|
5
|
+
var _a;
|
|
6
|
+
const host = config.getString("host");
|
|
7
|
+
let baseUrl = config.getOptionalString("baseUrl");
|
|
8
|
+
const username = config.getOptionalString("username");
|
|
9
|
+
const password = (_a = config.getOptionalString("password")) == null ? void 0 : _a.trim();
|
|
10
|
+
if (!isValidHost(host)) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
`Invalid Gitea integration config, '${host}' is not a valid host`
|
|
13
|
+
);
|
|
14
|
+
} else if (baseUrl && !isValidUrl(baseUrl)) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
`Invalid Gitea integration config, '${baseUrl}' is not a valid baseUrl`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
if (baseUrl) {
|
|
20
|
+
baseUrl = trimEnd(baseUrl, "/");
|
|
21
|
+
} else {
|
|
22
|
+
baseUrl = `https://${host}`;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
host,
|
|
26
|
+
baseUrl,
|
|
27
|
+
username,
|
|
28
|
+
password
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { readGiteaConfig };
|
|
33
|
+
//# sourceMappingURL=config.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.esm.js","sources":["../../src/gitea/config.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 */\n\nimport { Config } from '@backstage/config';\nimport { trimEnd } from 'lodash';\nimport { isValidHost, isValidUrl } from '../helpers';\n\n/**\n * The configuration for a single Gitea integration.\n *\n * @public\n */\nexport type GiteaIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. \"gitea.website.com\"\n */\n host: string;\n /**\n * The optional base URL of the Gitea instance. It is assumed that https\n * is used and that the base path is \"/\" on the host. If that is not the\n * case set the complete base url to the gitea instance, e.g.\n * \"https://gitea.website.com/\". This is the url that you would open\n * in a browser.\n */\n baseUrl?: string;\n /**\n * The username to use for requests to gitea.\n */\n username?: string;\n\n /**\n * The password or http token to use for authentication.\n */\n password?: string;\n};\n\n/**\n * Parses a location config block for use in GiteaIntegration\n *\n * @public\n */\nexport function readGiteaConfig(config: Config): GiteaIntegrationConfig {\n const host = config.getString('host');\n let baseUrl = config.getOptionalString('baseUrl');\n const username = config.getOptionalString('username');\n const password = config.getOptionalString('password')?.trim();\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid Gitea integration config, '${host}' is not a valid host`,\n );\n } else if (baseUrl && !isValidUrl(baseUrl)) {\n throw new Error(\n `Invalid Gitea integration config, '${baseUrl}' is not a valid baseUrl`,\n );\n }\n\n if (baseUrl) {\n baseUrl = trimEnd(baseUrl, '/');\n } else {\n baseUrl = `https://${host}`;\n }\n\n return {\n host,\n baseUrl,\n username,\n password,\n };\n}\n"],"names":[],"mappings":";;;AAsDO,SAAS,gBAAgB,MAAwC,EAAA;AAtDxE,EAAA,IAAA,EAAA,CAAA;AAuDE,EAAM,MAAA,IAAA,GAAO,MAAO,CAAA,SAAA,CAAU,MAAM,CAAA,CAAA;AACpC,EAAI,IAAA,OAAA,GAAU,MAAO,CAAA,iBAAA,CAAkB,SAAS,CAAA,CAAA;AAChD,EAAM,MAAA,QAAA,GAAW,MAAO,CAAA,iBAAA,CAAkB,UAAU,CAAA,CAAA;AACpD,EAAA,MAAM,QAAW,GAAA,CAAA,EAAA,GAAA,MAAA,CAAO,iBAAkB,CAAA,UAAU,MAAnC,IAAsC,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,IAAA,EAAA,CAAA;AAEvD,EAAI,IAAA,CAAC,WAAY,CAAA,IAAI,CAAG,EAAA;AACtB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,sCAAsC,IAAI,CAAA,qBAAA,CAAA;AAAA,KAC5C,CAAA;AAAA,GACS,MAAA,IAAA,OAAA,IAAW,CAAC,UAAA,CAAW,OAAO,CAAG,EAAA;AAC1C,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,sCAAsC,OAAO,CAAA,wBAAA,CAAA;AAAA,KAC/C,CAAA;AAAA,GACF;AAEA,EAAA,IAAI,OAAS,EAAA;AACX,IAAU,OAAA,GAAA,OAAA,CAAQ,SAAS,GAAG,CAAA,CAAA;AAAA,GACzB,MAAA;AACL,IAAA,OAAA,GAAU,WAAW,IAAI,CAAA,CAAA,CAAA;AAAA,GAC3B;AAEA,EAAO,OAAA;AAAA,IACL,IAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,GACF,CAAA;AACF;;;;"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
function getGiteaEditContentsUrl(config, url) {
|
|
2
|
+
const giteaUrl = parseGiteaUrl(config, url);
|
|
3
|
+
return `${giteaUrl.url}/${giteaUrl.owner}/${giteaUrl.name}/_edit/${giteaUrl.ref}/${giteaUrl.path}`;
|
|
4
|
+
}
|
|
5
|
+
function getGiteaFileContentsUrl(config, url) {
|
|
6
|
+
const giteaUrl = parseGiteaUrl(config, url);
|
|
7
|
+
return `${giteaUrl.url}/api/v1/repos/${giteaUrl.owner}/${giteaUrl.name}/contents/${giteaUrl.path}?ref=${giteaUrl.ref}`;
|
|
8
|
+
}
|
|
9
|
+
function getGiteaArchiveUrl(config, url) {
|
|
10
|
+
const giteaUrl = parseGiteaUrl(config, url);
|
|
11
|
+
return `${giteaUrl.url}/api/v1/repos/${giteaUrl.owner}/${giteaUrl.name}/archive/${giteaUrl.ref}.tar.gz`;
|
|
12
|
+
}
|
|
13
|
+
function getGiteaLatestCommitUrl(config, url) {
|
|
14
|
+
const giteaUrl = parseGiteaUrl(config, url);
|
|
15
|
+
return `${giteaUrl.url}/api/v1/repos/${giteaUrl.owner}/${giteaUrl.name}/git/commits/${giteaUrl.ref}`;
|
|
16
|
+
}
|
|
17
|
+
function getGiteaRequestOptions(config) {
|
|
18
|
+
const headers = {};
|
|
19
|
+
const { username, password } = config;
|
|
20
|
+
if (!password) {
|
|
21
|
+
return headers;
|
|
22
|
+
}
|
|
23
|
+
if (username) {
|
|
24
|
+
headers.Authorization = `basic ${Buffer.from(
|
|
25
|
+
`${username}:${password}`
|
|
26
|
+
).toString("base64")}`;
|
|
27
|
+
} else {
|
|
28
|
+
headers.Authorization = `token ${password}`;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
headers
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function parseGiteaUrl(config, url) {
|
|
35
|
+
var _a;
|
|
36
|
+
const baseUrl = (_a = config.baseUrl) != null ? _a : `https://${config.host}`;
|
|
37
|
+
try {
|
|
38
|
+
const [_blank, owner, name, _src, _branch, ref, ...path] = url.replace(baseUrl, "").split("/");
|
|
39
|
+
const pathWithoutSlash = path.join("/").replace(/^\//, "");
|
|
40
|
+
return {
|
|
41
|
+
url: baseUrl,
|
|
42
|
+
owner,
|
|
43
|
+
name,
|
|
44
|
+
ref,
|
|
45
|
+
path: pathWithoutSlash
|
|
46
|
+
};
|
|
47
|
+
} catch (e) {
|
|
48
|
+
throw new Error(`Incorrect URL: ${url}, ${e}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { getGiteaArchiveUrl, getGiteaEditContentsUrl, getGiteaFileContentsUrl, getGiteaLatestCommitUrl, getGiteaRequestOptions, parseGiteaUrl };
|
|
53
|
+
//# sourceMappingURL=core.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.esm.js","sources":["../../src/gitea/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 { GiteaIntegrationConfig } 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://gitea.com/a/b/src/branchname/path/to/c.yaml\n * or: https://gitea.com/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 getGiteaEditContentsUrl(\n config: GiteaIntegrationConfig,\n url: string,\n) {\n const giteaUrl = parseGiteaUrl(config, url);\n return `${giteaUrl.url}/${giteaUrl.owner}/${giteaUrl.name}/_edit/${giteaUrl.ref}/${giteaUrl.path}`;\n}\n\n/**\n * Given a URL pointing to a file, returns an api URL\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://gitea.com/a/b/src/branch/branchname/path/to/c.yaml\n * to: https://gitea.com/api/v1/repos/a/b/contents/path/to/c.yaml?ref=branchname\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport function getGiteaFileContentsUrl(\n config: GiteaIntegrationConfig,\n url: string,\n) {\n const giteaUrl = parseGiteaUrl(config, url);\n return `${giteaUrl.url}/api/v1/repos/${giteaUrl.owner}/${giteaUrl.name}/contents/${giteaUrl.path}?ref=${giteaUrl.ref}`;\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://gitea.com/a/b/src/branchname\n * or: https://gitea.com/api/v1/repos/a/b/archive/branchname.tar.gz\n *\n * @param url - A URL pointing to a repository/path\n * @param config - The relevant provider config\n * @public\n */\nexport function getGiteaArchiveUrl(\n config: GiteaIntegrationConfig,\n url: string,\n) {\n const giteaUrl = parseGiteaUrl(config, url);\n return `${giteaUrl.url}/api/v1/repos/${giteaUrl.owner}/${giteaUrl.name}/archive/${giteaUrl.ref}.tar.gz`;\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://gitea.com/a/b/src/branchname\n * or: https://gitea.com/api/v1/repos/a/b/git/commits/branchname\n *\n * @param url - A URL pointing to a repository branch\n * @param config - The relevant provider config\n * @public\n */\nexport function getGiteaLatestCommitUrl(\n config: GiteaIntegrationConfig,\n url: string,\n) {\n const giteaUrl = parseGiteaUrl(config, url);\n return `${giteaUrl.url}/api/v1/repos/${giteaUrl.owner}/${giteaUrl.name}/git/commits/${giteaUrl.ref}`;\n}\n\n/**\n * Return request headers for a Gitea provider.\n *\n * @param config - A Gitea provider config\n * @public\n */\nexport function getGiteaRequestOptions(config: GiteaIntegrationConfig): {\n headers?: Record<string, string>;\n} {\n const headers: Record<string, string> = {};\n const { username, password } = config;\n\n if (!password) {\n return headers;\n }\n\n if (username) {\n headers.Authorization = `basic ${Buffer.from(\n `${username}:${password}`,\n ).toString('base64')}`;\n } else {\n headers.Authorization = `token ${password}`;\n }\n\n return {\n headers,\n };\n}\n\n/**\n * Return parsed git url properties.\n *\n * @param config - A Gitea provider config\n * @param url - A URL pointing to a repository\n * @public\n */\nexport function parseGiteaUrl(\n config: GiteaIntegrationConfig,\n url: string,\n): {\n url: string;\n owner: string;\n name: string;\n ref: string;\n path: string;\n} {\n const baseUrl = config.baseUrl ?? `https://${config.host}`;\n try {\n const [_blank, owner, name, _src, _branch, ref, ...path] = url\n .replace(baseUrl, '')\n .split('/');\n const pathWithoutSlash = path.join('/').replace(/^\\//, '');\n\n return {\n url: baseUrl,\n owner: owner,\n name: name,\n ref: ref,\n path: pathWithoutSlash,\n };\n } catch (e) {\n throw new Error(`Incorrect URL: ${url}, ${e}`);\n }\n}\n"],"names":[],"mappings":"AA+BgB,SAAA,uBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,QAAA,GAAW,aAAc,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAA;AAC1C,EAAA,OAAO,CAAG,EAAA,QAAA,CAAS,GAAG,CAAA,CAAA,EAAI,SAAS,KAAK,CAAA,CAAA,EAAI,QAAS,CAAA,IAAI,CAAU,OAAA,EAAA,QAAA,CAAS,GAAG,CAAA,CAAA,EAAI,SAAS,IAAI,CAAA,CAAA,CAAA;AAClG,CAAA;AAgBgB,SAAA,uBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,QAAA,GAAW,aAAc,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAA;AAC1C,EAAA,OAAO,CAAG,EAAA,QAAA,CAAS,GAAG,CAAA,cAAA,EAAiB,SAAS,KAAK,CAAA,CAAA,EAAI,QAAS,CAAA,IAAI,CAAa,UAAA,EAAA,QAAA,CAAS,IAAI,CAAA,KAAA,EAAQ,SAAS,GAAG,CAAA,CAAA,CAAA;AACtH,CAAA;AAgBgB,SAAA,kBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,QAAA,GAAW,aAAc,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAA;AAC1C,EAAO,OAAA,CAAA,EAAG,QAAS,CAAA,GAAG,CAAiB,cAAA,EAAA,QAAA,CAAS,KAAK,CAAA,CAAA,EAAI,QAAS,CAAA,IAAI,CAAY,SAAA,EAAA,QAAA,CAAS,GAAG,CAAA,OAAA,CAAA,CAAA;AAChG,CAAA;AAgBgB,SAAA,uBAAA,CACd,QACA,GACA,EAAA;AACA,EAAM,MAAA,QAAA,GAAW,aAAc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AA;AACZ,IAAA,MAAM,mBAAmB,IAAK,CAAA,IAAA,CAAK,GAAG,CAAE,CAAA,OAAA,CAAQ,OAAO,EAAE,CAAA,CAAA;AAEzD,IAAO,OAAA;AAAA,MACL,GAAK,EAAA,OAAA;AAAA,MACL,KAAA;AAAA,MACA,IAAA;AAAA,MACA,GAAA;AAAA,MACA,IAAM,EAAA,gBAAA;AAAA,KACR,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;;;;"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { SingleInstanceGithubCredentialsProvider } from './SingleInstanceGithubCredentialsProvider.esm.js';
|
|
2
|
+
|
|
3
|
+
class DefaultGithubCredentialsProvider {
|
|
4
|
+
constructor(providers) {
|
|
5
|
+
this.providers = providers;
|
|
6
|
+
}
|
|
7
|
+
static fromIntegrations(integrations) {
|
|
8
|
+
const credentialsProviders = /* @__PURE__ */ new Map();
|
|
9
|
+
integrations.github.list().forEach((integration) => {
|
|
10
|
+
const credentialsProvider = SingleInstanceGithubCredentialsProvider.create(integration.config);
|
|
11
|
+
credentialsProviders.set(integration.config.host, credentialsProvider);
|
|
12
|
+
});
|
|
13
|
+
return new DefaultGithubCredentialsProvider(credentialsProviders);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns {@link GithubCredentials} for a given URL.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
*
|
|
20
|
+
* Consecutive calls to this method with the same URL will return cached
|
|
21
|
+
* credentials.
|
|
22
|
+
*
|
|
23
|
+
* The shortest lifetime for a token returned is 10 minutes.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const { token, headers } = await getCredentials({
|
|
28
|
+
* url: 'https://github.com/backstage/foobar'
|
|
29
|
+
* })
|
|
30
|
+
*
|
|
31
|
+
* const { token, headers } = await getCredentials({
|
|
32
|
+
* url: 'https://github.com/backstage'
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @param opts - The organization or repository URL
|
|
37
|
+
* @returns A promise of {@link GithubCredentials}.
|
|
38
|
+
*/
|
|
39
|
+
async getCredentials(opts) {
|
|
40
|
+
const parsed = new URL(opts.url);
|
|
41
|
+
const provider = this.providers.get(parsed.host);
|
|
42
|
+
if (!provider) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
`There is no GitHub integration that matches ${opts.url}. Please add a configuration for an integration.`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return provider.getCredentials(opts);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { DefaultGithubCredentialsProvider };
|
|
52
|
+
//# sourceMappingURL=DefaultGithubCredentialsProvider.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultGithubCredentialsProvider.esm.js","sources":["../../src/github/DefaultGithubCredentialsProvider.ts"],"sourcesContent":["/*\n * Copyright 2021 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 { GithubCredentials, GithubCredentialsProvider } from './types';\nimport { ScmIntegrationRegistry } from '../registry';\nimport { SingleInstanceGithubCredentialsProvider } from './SingleInstanceGithubCredentialsProvider';\n\n/**\n * Handles the creation and caching of credentials for GitHub integrations.\n *\n * @public\n * @remarks\n *\n * TODO: Possibly move this to a backend only package so that it's not used in the frontend by mistake\n */\nexport class DefaultGithubCredentialsProvider\n implements GithubCredentialsProvider\n{\n static fromIntegrations(integrations: ScmIntegrationRegistry) {\n const credentialsProviders: Map<string, GithubCredentialsProvider> =\n new Map<string, GithubCredentialsProvider>();\n\n integrations.github.list().forEach(integration => {\n const credentialsProvider =\n SingleInstanceGithubCredentialsProvider.create(integration.config);\n credentialsProviders.set(integration.config.host, credentialsProvider);\n });\n return new DefaultGithubCredentialsProvider(credentialsProviders);\n }\n\n private constructor(\n private readonly providers: Map<string, GithubCredentialsProvider>,\n ) {}\n\n /**\n * Returns {@link GithubCredentials} for a given URL.\n *\n * @remarks\n *\n * Consecutive calls to this method with the same URL will return cached\n * credentials.\n *\n * The shortest lifetime for a token returned is 10 minutes.\n *\n * @example\n * ```ts\n * const { token, headers } = await getCredentials({\n * url: 'https://github.com/backstage/foobar'\n * })\n *\n * const { token, headers } = await getCredentials({\n * url: 'https://github.com/backstage'\n * })\n * ```\n *\n * @param opts - The organization or repository URL\n * @returns A promise of {@link GithubCredentials}.\n */\n async getCredentials(opts: { url: string }): Promise<GithubCredentials> {\n const parsed = new URL(opts.url);\n const provider = this.providers.get(parsed.host);\n\n if (!provider) {\n throw new Error(\n `There is no GitHub integration that matches ${opts.url}. Please add a configuration for an integration.`,\n );\n }\n\n return provider.getCredentials(opts);\n }\n}\n"],"names":[],"mappings":";;AA4BO,MAAM,gCAEb,CAAA;AAAA,EAaU,YACW,SACjB,EAAA;AADiB,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA,CAAA;AAAA,GAChB;AAAA,EAdH,OAAO,iBAAiB,YAAsC,EAAA;AAC5D,IAAM,MAAA,oBAAA,uBACA,GAAuC,EAAA,CAAA;AAE7C,IAAA,YAAA,CAAa,MAAO,CAAA,IAAA,EAAO,CAAA,OAAA,CAAQ,CAAe,WAAA,KAAA;AAChD,MAAA,MAAM,mBACJ,GAAA,uCAAA,CAAwC,MAAO,CAAA,WAAA,CAAY,MAAM,CAAA,CAAA;AACnE,MAAA,oBAAA,CAAqB,GAAI,CAAA,WAAA,CAAY,MAAO,CAAA,IAAA,EAAM,mBAAmB,CAAA,CAAA;AAAA,KACtE,CAAA,CAAA;AACD,IAAO,OAAA,IAAI,iCAAiC,oBAAoB,CAAA,CAAA;AAAA,GAClE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA8BA,MAAM,eAAe,IAAmD,EAAA;AACtE,IAAA,MAAM,MAAS,GAAA,IAAI,GAAI,CAAA,IAAA,CAAK,GAAG,CAAA,CAAA;AAC/B,IAAA,MAAM,QAAW,GAAA,IAAA,CAAK,SAAU,CAAA,GAAA,CAAI,OAAO,IAAI,CAAA,CAAA;AAE/C,IAAA,IAAI,CAAC,QAAU,EAAA;AACb,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,4CAAA,EAA+C,KAAK,GAAG,CAAA,gDAAA,CAAA;AAAA,OACzD,CAAA;AAAA,KACF;AAEA,IAAO,OAAA,QAAA,CAAS,eAAe,IAAI,CAAA,CAAA;AAAA,GACrC;AACF;;;;"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { basicIntegrations, defaultScmResolveUrl } from '../helpers.esm.js';
|
|
2
|
+
import { readGithubIntegrationConfigs } from './config.esm.js';
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __publicField = (obj, key, value) => {
|
|
7
|
+
__defNormalProp(obj, key + "" , value);
|
|
8
|
+
return value;
|
|
9
|
+
};
|
|
10
|
+
const _GithubIntegration = class _GithubIntegration {
|
|
11
|
+
constructor(integrationConfig) {
|
|
12
|
+
this.integrationConfig = integrationConfig;
|
|
13
|
+
}
|
|
14
|
+
get type() {
|
|
15
|
+
return "github";
|
|
16
|
+
}
|
|
17
|
+
get title() {
|
|
18
|
+
return this.integrationConfig.host;
|
|
19
|
+
}
|
|
20
|
+
get config() {
|
|
21
|
+
return this.integrationConfig;
|
|
22
|
+
}
|
|
23
|
+
resolveUrl(options) {
|
|
24
|
+
return replaceGithubUrlType(defaultScmResolveUrl(options), "tree");
|
|
25
|
+
}
|
|
26
|
+
resolveEditUrl(url) {
|
|
27
|
+
return replaceGithubUrlType(url, "edit");
|
|
28
|
+
}
|
|
29
|
+
parseRateLimitInfo(response) {
|
|
30
|
+
return {
|
|
31
|
+
isRateLimited: response.status === 429 || response.status === 403 && response.headers.get("x-ratelimit-remaining") === "0"
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
__publicField(_GithubIntegration, "factory", ({ config }) => {
|
|
36
|
+
var _a;
|
|
37
|
+
const configs = readGithubIntegrationConfigs(
|
|
38
|
+
(_a = config.getOptionalConfigArray("integrations.github")) != null ? _a : []
|
|
39
|
+
);
|
|
40
|
+
return basicIntegrations(
|
|
41
|
+
configs.map((c) => new _GithubIntegration(c)),
|
|
42
|
+
(i) => i.config.host
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
let GithubIntegration = _GithubIntegration;
|
|
46
|
+
function replaceGithubUrlType(url, type) {
|
|
47
|
+
return url.replace(
|
|
48
|
+
/\/\/([^/]+)\/([^/]+)\/([^/]+)\/(blob|tree|edit)\//,
|
|
49
|
+
(_, host, owner, repo) => {
|
|
50
|
+
return `//${host}/${owner}/${repo}/${type}/`;
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { GithubIntegration, replaceGithubUrlType };
|
|
56
|
+
//# sourceMappingURL=GithubIntegration.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GithubIntegration.esm.js","sources":["../../src/github/GithubIntegration.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 { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport {\n RateLimitInfo,\n ScmIntegration,\n ScmIntegrationsFactory,\n} from '../types';\nimport {\n GithubIntegrationConfig,\n readGithubIntegrationConfigs,\n} from './config';\nimport { ConsumedResponse } from '@backstage/errors';\n\n/**\n * A GitHub based integration.\n *\n * @public\n */\nexport class GithubIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GithubIntegration> = ({ config }) => {\n const configs = readGithubIntegrationConfigs(\n config.getOptionalConfigArray('integrations.github') ?? [],\n );\n return basicIntegrations(\n configs.map(c => new GithubIntegration(c)),\n i => i.config.host,\n );\n };\n\n constructor(private readonly integrationConfig: GithubIntegrationConfig) {}\n\n get type(): string {\n return 'github';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GithubIntegrationConfig {\n return this.integrationConfig;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n }): string {\n // GitHub uses blob URLs for files and tree urls for directory listings. But\n // there is a redirect from tree to blob for files, so we can always return\n // tree urls here.\n return replaceGithubUrlType(defaultScmResolveUrl(options), 'tree');\n }\n\n resolveEditUrl(url: string): string {\n return replaceGithubUrlType(url, 'edit');\n }\n\n parseRateLimitInfo(response: ConsumedResponse): RateLimitInfo {\n return {\n isRateLimited:\n response.status === 429 ||\n (response.status === 403 &&\n response.headers.get('x-ratelimit-remaining') === '0'),\n };\n }\n}\n\n/**\n * Takes a GitHub URL and replaces the type part (blob, tree etc).\n *\n * @param url - The original URL\n * @param type - The desired type, e.g. \"blob\"\n * @public\n */\nexport function replaceGithubUrlType(\n url: string,\n type: 'blob' | 'tree' | 'edit',\n): string {\n return url.replace(\n /\\/\\/([^/]+)\\/([^/]+)\\/([^/]+)\\/(blob|tree|edit)\\//,\n (_, host, owner, repo) => {\n return `//${host}/${owner}/${repo}/${type}/`;\n },\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AAiCO,MAAM,kBAAA,GAAN,MAAM,kBAA4C,CAAA;AAAA,EAWvD,YAA6B,iBAA4C,EAAA;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA,CAAA;AAAA,GAA6C;AAAA,EAE1E,IAAI,IAAe,GAAA;AACjB,IAAO,OAAA,QAAA,CAAA;AAAA,GACT;AAAA,EAEA,IAAI,KAAgB,GAAA;AAClB,IAAA,OAAO,KAAK,iBAAkB,CAAA,IAAA,CAAA;AAAA,GAChC;AAAA,EAEA,IAAI,MAAkC,GAAA;AACpC,IAAA,OAAO,IAAK,CAAA,iBAAA,CAAA;AAAA,GACd;AAAA,EAEA,WAAW,OAIA,EAAA;AAIT,IAAA,OAAO,oBAAqB,CAAA,oBAAA,CAAqB,OAAO,CAAA,EAAG,MAAM,CAAA,CAAA;AAAA,GACnE;AAAA,EAEA,eAAe,GAAqB,EAAA;AAClC,IAAO,OAAA,oBAAA,CAAqB,KAAK,MAAM,CAAA,CAAA;AAAA,GACzC;AAAA,EAEA,mBAAmB,QAA2C,EAAA;AAC5D,IAAO,OAAA;AAAA,MACL,aAAA,EACE,QAAS,CAAA,MAAA,KAAW,GACnB,IAAA,QAAA,CAAS,MAAW,KAAA,GAAA,IACnB,QAAS,CAAA,OAAA,CAAQ,GAAI,CAAA,uBAAuB,CAAM,KAAA,GAAA;AAAA,KACxD,CAAA;AAAA,GACF;AACF,CAAA,CAAA;AA/CE,aAAA,CADW,kBACJ,EAAA,SAAA,EAAqD,CAAC,EAAE,QAAa,KAAA;AAlC9E,EAAA,IAAA,EAAA,CAAA;AAmCI,EAAA,MAAM,OAAU,GAA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