@backstage/integration 1.20.0 → 2.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/config.d.ts +25 -60
- package/dist/ScmIntegrations.cjs.js +1 -17
- package/dist/ScmIntegrations.cjs.js.map +1 -1
- package/dist/ScmIntegrations.esm.js +1 -17
- package/dist/ScmIntegrations.esm.js.map +1 -1
- package/dist/azure/config.cjs.js +14 -35
- package/dist/azure/config.cjs.js.map +1 -1
- package/dist/azure/config.esm.js +14 -35
- package/dist/azure/config.esm.js.map +1 -1
- package/dist/gerrit/core.cjs.js +6 -33
- package/dist/gerrit/core.cjs.js.map +1 -1
- package/dist/gerrit/core.esm.js +7 -32
- package/dist/gerrit/core.esm.js.map +1 -1
- package/dist/github/core.cjs.js +0 -11
- package/dist/github/core.cjs.js.map +1 -1
- package/dist/github/core.esm.js +1 -11
- package/dist/github/core.esm.js.map +1 -1
- package/dist/gitlab/GitLabIntegration.cjs.js +69 -0
- package/dist/gitlab/GitLabIntegration.cjs.js.map +1 -1
- package/dist/gitlab/GitLabIntegration.esm.js +65 -1
- package/dist/gitlab/GitLabIntegration.esm.js.map +1 -1
- package/dist/gitlab/config.cjs.js +27 -1
- package/dist/gitlab/config.cjs.js.map +1 -1
- package/dist/gitlab/config.esm.js +27 -1
- package/dist/gitlab/config.esm.js.map +1 -1
- package/dist/gitlab/core.cjs.js +14 -42
- package/dist/gitlab/core.cjs.js.map +1 -1
- package/dist/gitlab/core.esm.js +14 -38
- package/dist/gitlab/core.esm.js.map +1 -1
- package/dist/index.cjs.js +61 -76
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +30 -225
- package/dist/index.esm.js +2 -6
- package/dist/index.esm.js.map +1 -1
- package/package.json +7 -6
- package/dist/azure/deprecated.cjs.js +0 -26
- package/dist/azure/deprecated.cjs.js.map +0 -1
- package/dist/azure/deprecated.esm.js +0 -24
- package/dist/azure/deprecated.esm.js.map +0 -1
- package/dist/bitbucket/BitbucketIntegration.cjs.js +0 -65
- package/dist/bitbucket/BitbucketIntegration.cjs.js.map +0 -1
- package/dist/bitbucket/BitbucketIntegration.esm.js +0 -59
- package/dist/bitbucket/BitbucketIntegration.esm.js.map +0 -1
- package/dist/bitbucket/config.cjs.js +0 -48
- package/dist/bitbucket/config.cjs.js.map +0 -1
- package/dist/bitbucket/config.esm.js +0 -45
- package/dist/bitbucket/config.esm.js.map +0 -1
- package/dist/bitbucket/core.cjs.js +0 -95
- package/dist/bitbucket/core.cjs.js.map +0 -1
- package/dist/bitbucket/core.esm.js +0 -85
- package/dist/bitbucket/core.esm.js.map +0 -1
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { CachedAzureDevOpsCredentialsProvider } from './CachedAzureDevOpsCredentialsProvider.esm.js';
|
|
2
|
-
|
|
3
|
-
async function getAzureRequestOptions(config, additionalHeaders) {
|
|
4
|
-
const headers = additionalHeaders ? { ...additionalHeaders } : {};
|
|
5
|
-
const credentialConfig = config.credentials?.filter(
|
|
6
|
-
(credential) => credential.organizations === void 0 || credential.organizations.length === 0
|
|
7
|
-
)[0];
|
|
8
|
-
if (credentialConfig) {
|
|
9
|
-
const credentialsProvider = CachedAzureDevOpsCredentialsProvider.fromAzureDevOpsCredential(
|
|
10
|
-
credentialConfig
|
|
11
|
-
);
|
|
12
|
-
const credentials = await credentialsProvider.getCredentials();
|
|
13
|
-
return {
|
|
14
|
-
headers: {
|
|
15
|
-
...credentials?.headers,
|
|
16
|
-
...headers
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
return { headers };
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { getAzureRequestOptions };
|
|
24
|
-
//# sourceMappingURL=deprecated.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deprecated.esm.js","sources":["../../src/azure/deprecated.ts"],"sourcesContent":["/*\n * Copyright 2023 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 { AzureIntegrationConfig } from './config';\nimport { CachedAzureDevOpsCredentialsProvider } from './CachedAzureDevOpsCredentialsProvider';\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n *\n * @param config - The relevant provider config\n * @param additionalHeaders - Additional headers for the request\n * @public\n * @deprecated Use {@link AzureDevOpsCredentialsProvider} instead.\n */\nexport async function getAzureRequestOptions(\n config: AzureIntegrationConfig,\n additionalHeaders?: Record<string, string>,\n): Promise<{ headers: Record<string, string> }> {\n const headers: Record<string, string> = additionalHeaders\n ? { ...additionalHeaders }\n : {};\n\n /*\n * Since we do not have a way to determine which organization the request is for,\n * we will use the first credential that does not have an organization specified.\n */\n const credentialConfig = config.credentials?.filter(\n credential =>\n credential.organizations === undefined ||\n credential.organizations.length === 0,\n )[0];\n\n if (credentialConfig) {\n const credentialsProvider =\n CachedAzureDevOpsCredentialsProvider.fromAzureDevOpsCredential(\n credentialConfig,\n );\n const credentials = await credentialsProvider.getCredentials();\n\n return {\n headers: {\n ...credentials?.headers,\n ...headers,\n },\n };\n }\n\n return { headers };\n}\n"],"names":[],"mappings":";;AA0BA,eAAsB,sBAAA,CACpB,QACA,iBAAA,EAC8C;AAC9C,EAAA,MAAM,UAAkC,iBAAA,GACpC,EAAE,GAAG,iBAAA,KACL,EAAC;AAML,EAAA,MAAM,gBAAA,GAAmB,OAAO,WAAA,EAAa,MAAA;AAAA,IAC3C,gBACE,UAAA,CAAW,aAAA,KAAkB,MAAA,IAC7B,UAAA,CAAW,cAAc,MAAA,KAAW;AAAA,IACtC,CAAC,CAAA;AAEH,EAAA,IAAI,gBAAA,EAAkB;AACpB,IAAA,MAAM,sBACJ,oCAAA,CAAqC,yBAAA;AAAA,MACnC;AAAA,KACF;AACF,IAAA,MAAM,WAAA,GAAc,MAAM,mBAAA,CAAoB,cAAA,EAAe;AAE7D,IAAA,OAAO;AAAA,MACL,OAAA,EAAS;AAAA,QACP,GAAG,WAAA,EAAa,OAAA;AAAA,QAChB,GAAG;AAAA;AACL,KACF;AAAA,EACF;AAEA,EAAA,OAAO,EAAE,OAAA,EAAQ;AACnB;;;;"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var parseGitUrl = require('git-url-parse');
|
|
4
|
-
var helpers = require('../helpers.cjs.js');
|
|
5
|
-
var config = require('./config.cjs.js');
|
|
6
|
-
|
|
7
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
8
|
-
|
|
9
|
-
var parseGitUrl__default = /*#__PURE__*/_interopDefaultCompat(parseGitUrl);
|
|
10
|
-
|
|
11
|
-
class BitbucketIntegration {
|
|
12
|
-
constructor(integrationConfig) {
|
|
13
|
-
this.integrationConfig = integrationConfig;
|
|
14
|
-
}
|
|
15
|
-
static factory = ({
|
|
16
|
-
config: config$1
|
|
17
|
-
}) => {
|
|
18
|
-
const configs = config.readBitbucketIntegrationConfigs(
|
|
19
|
-
config$1.getOptionalConfigArray("integrations.bitbucket") ?? [
|
|
20
|
-
// if integrations.bitbucket was not used assume the use was migrated to the new configs
|
|
21
|
-
// and backport for the deprecated integration to be usable for other parts of the system
|
|
22
|
-
// until these got migrated
|
|
23
|
-
...config$1.getOptionalConfigArray("integrations.bitbucketCloud") ?? [],
|
|
24
|
-
...config$1.getOptionalConfigArray("integrations.bitbucketServer") ?? []
|
|
25
|
-
]
|
|
26
|
-
);
|
|
27
|
-
return helpers.basicIntegrations(
|
|
28
|
-
configs.map((c) => new BitbucketIntegration(c)),
|
|
29
|
-
(i) => i.config.host
|
|
30
|
-
);
|
|
31
|
-
};
|
|
32
|
-
get type() {
|
|
33
|
-
return "bitbucket";
|
|
34
|
-
}
|
|
35
|
-
get title() {
|
|
36
|
-
return this.integrationConfig.host;
|
|
37
|
-
}
|
|
38
|
-
get config() {
|
|
39
|
-
return this.integrationConfig;
|
|
40
|
-
}
|
|
41
|
-
resolveUrl(options) {
|
|
42
|
-
const resolved = helpers.defaultScmResolveUrl(options);
|
|
43
|
-
if (!options.lineNumber) {
|
|
44
|
-
return resolved;
|
|
45
|
-
}
|
|
46
|
-
const url = new URL(resolved);
|
|
47
|
-
if (this.integrationConfig.host === "bitbucket.org") {
|
|
48
|
-
url.hash = `lines-${options.lineNumber}`;
|
|
49
|
-
} else {
|
|
50
|
-
url.hash = `${options.lineNumber}`;
|
|
51
|
-
}
|
|
52
|
-
return url.toString();
|
|
53
|
-
}
|
|
54
|
-
resolveEditUrl(url) {
|
|
55
|
-
const urlData = parseGitUrl__default.default(url);
|
|
56
|
-
const editUrl = new URL(url);
|
|
57
|
-
editUrl.searchParams.set("mode", "edit");
|
|
58
|
-
editUrl.searchParams.set("spa", "0");
|
|
59
|
-
editUrl.searchParams.set("at", urlData.ref);
|
|
60
|
-
return editUrl.toString();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
exports.BitbucketIntegration = BitbucketIntegration;
|
|
65
|
-
//# sourceMappingURL=BitbucketIntegration.cjs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BitbucketIntegration.cjs.js","sources":["../../src/bitbucket/BitbucketIntegration.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport parseGitUrl from 'git-url-parse';\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport {\n BitbucketIntegrationConfig,\n readBitbucketIntegrationConfigs,\n} from './config';\n\n/**\n * A Bitbucket based integration.\n *\n * @public\n * @deprecated replaced by the integrations bitbucketCloud and bitbucketServer.\n */\nexport class BitbucketIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<BitbucketIntegration> = ({\n config,\n }) => {\n const configs = readBitbucketIntegrationConfigs(\n config.getOptionalConfigArray('integrations.bitbucket') ?? [\n // if integrations.bitbucket was not used assume the use was migrated to the new configs\n // and backport for the deprecated integration to be usable for other parts of the system\n // until these got migrated\n ...(config.getOptionalConfigArray('integrations.bitbucketCloud') ?? []),\n ...(config.getOptionalConfigArray('integrations.bitbucketServer') ??\n []),\n ],\n );\n return basicIntegrations(\n configs.map(c => new BitbucketIntegration(c)),\n i => i.config.host,\n );\n };\n\n constructor(private readonly integrationConfig: BitbucketIntegrationConfig) {}\n\n get type(): string {\n return 'bitbucket';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): BitbucketIntegrationConfig {\n return this.integrationConfig;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n }): string {\n const resolved = defaultScmResolveUrl(options);\n if (!options.lineNumber) {\n return resolved;\n }\n\n const url = new URL(resolved);\n\n if (this.integrationConfig.host === 'bitbucket.org') {\n // Bitbucket Cloud uses the syntax #lines-{start}[:{end}][,...]\n url.hash = `lines-${options.lineNumber}`;\n } else {\n // Bitbucket Server uses the syntax #{start}[-{end}][,...]\n url.hash = `${options.lineNumber}`;\n }\n\n return url.toString();\n }\n\n resolveEditUrl(url: string): string {\n const urlData = parseGitUrl(url);\n const editUrl = new URL(url);\n\n editUrl.searchParams.set('mode', 'edit');\n // TODO: Not sure what spa=0 does, at least bitbucket.org doesn't support it\n // but this is taken over from the initial implementation.\n editUrl.searchParams.set('spa', '0');\n editUrl.searchParams.set('at', urlData.ref);\n return editUrl.toString();\n }\n}\n"],"names":["config","readBitbucketIntegrationConfigs","basicIntegrations","defaultScmResolveUrl","parseGitUrl"],"mappings":";;;;;;;;;;AA8BO,MAAM,oBAAA,CAA+C;AAAA,EAoB1D,YAA6B,iBAAA,EAA+C;AAA/C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAAA,EAAgD;AAAA,EAnB7E,OAAO,UAAwD,CAAC;AAAA,YAC9DA;AAAA,GACF,KAAM;AACJ,IAAA,MAAM,OAAA,GAAUC,sCAAA;AAAA,MACdD,QAAA,CAAO,sBAAA,CAAuB,wBAAwB,CAAA,IAAK;AAAA;AAAA;AAAA;AAAA,QAIzD,GAAIA,QAAA,CAAO,sBAAA,CAAuB,6BAA6B,KAAK,EAAC;AAAA,QACrE,GAAIA,QAAA,CAAO,sBAAA,CAAuB,8BAA8B,KAC9D;AAAC;AACL,KACF;AACA,IAAA,OAAOE,yBAAA;AAAA,MACL,QAAQ,GAAA,CAAI,CAAA,CAAA,KAAK,IAAI,oBAAA,CAAqB,CAAC,CAAC,CAAA;AAAA,MAC5C,CAAA,CAAA,KAAK,EAAE,MAAA,CAAO;AAAA,KAChB;AAAA,EACF,CAAA;AAAA,EAIA,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,WAAA;AAAA,EACT;AAAA,EAEA,IAAI,KAAA,GAAgB;AAClB,IAAA,OAAO,KAAK,iBAAA,CAAkB,IAAA;AAAA,EAChC;AAAA,EAEA,IAAI,MAAA,GAAqC;AACvC,IAAA,OAAO,IAAA,CAAK,iBAAA;AAAA,EACd;AAAA,EAEA,WAAW,OAAA,EAIA;AACT,IAAA,MAAM,QAAA,GAAWC,6BAAqB,OAAO,CAAA;AAC7C,IAAA,IAAI,CAAC,QAAQ,UAAA,EAAY;AACvB,MAAA,OAAO,QAAA;AAAA,IACT;AAEA,IAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,QAAQ,CAAA;AAE5B,IAAA,IAAI,IAAA,CAAK,iBAAA,CAAkB,IAAA,KAAS,eAAA,EAAiB;AAEnD,MAAA,GAAA,CAAI,IAAA,GAAO,CAAA,MAAA,EAAS,OAAA,CAAQ,UAAU,CAAA,CAAA;AAAA,IACxC,CAAA,MAAO;AAEL,MAAA,GAAA,CAAI,IAAA,GAAO,CAAA,EAAG,OAAA,CAAQ,UAAU,CAAA,CAAA;AAAA,IAClC;AAEA,IAAA,OAAO,IAAI,QAAA,EAAS;AAAA,EACtB;AAAA,EAEA,eAAe,GAAA,EAAqB;AAClC,IAAA,MAAM,OAAA,GAAUC,6BAAY,GAAG,CAAA;AAC/B,IAAA,MAAM,OAAA,GAAU,IAAI,GAAA,CAAI,GAAG,CAAA;AAE3B,IAAA,OAAA,CAAQ,YAAA,CAAa,GAAA,CAAI,MAAA,EAAQ,MAAM,CAAA;AAGvC,IAAA,OAAA,CAAQ,YAAA,CAAa,GAAA,CAAI,KAAA,EAAO,GAAG,CAAA;AACnC,IAAA,OAAA,CAAQ,YAAA,CAAa,GAAA,CAAI,IAAA,EAAM,OAAA,CAAQ,GAAG,CAAA;AAC1C,IAAA,OAAO,QAAQ,QAAA,EAAS;AAAA,EAC1B;AACF;;;;"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import parseGitUrl from 'git-url-parse';
|
|
2
|
-
import { basicIntegrations, defaultScmResolveUrl } from '../helpers.esm.js';
|
|
3
|
-
import { readBitbucketIntegrationConfigs } from './config.esm.js';
|
|
4
|
-
|
|
5
|
-
class BitbucketIntegration {
|
|
6
|
-
constructor(integrationConfig) {
|
|
7
|
-
this.integrationConfig = integrationConfig;
|
|
8
|
-
}
|
|
9
|
-
static factory = ({
|
|
10
|
-
config
|
|
11
|
-
}) => {
|
|
12
|
-
const configs = readBitbucketIntegrationConfigs(
|
|
13
|
-
config.getOptionalConfigArray("integrations.bitbucket") ?? [
|
|
14
|
-
// if integrations.bitbucket was not used assume the use was migrated to the new configs
|
|
15
|
-
// and backport for the deprecated integration to be usable for other parts of the system
|
|
16
|
-
// until these got migrated
|
|
17
|
-
...config.getOptionalConfigArray("integrations.bitbucketCloud") ?? [],
|
|
18
|
-
...config.getOptionalConfigArray("integrations.bitbucketServer") ?? []
|
|
19
|
-
]
|
|
20
|
-
);
|
|
21
|
-
return basicIntegrations(
|
|
22
|
-
configs.map((c) => new BitbucketIntegration(c)),
|
|
23
|
-
(i) => i.config.host
|
|
24
|
-
);
|
|
25
|
-
};
|
|
26
|
-
get type() {
|
|
27
|
-
return "bitbucket";
|
|
28
|
-
}
|
|
29
|
-
get title() {
|
|
30
|
-
return this.integrationConfig.host;
|
|
31
|
-
}
|
|
32
|
-
get config() {
|
|
33
|
-
return this.integrationConfig;
|
|
34
|
-
}
|
|
35
|
-
resolveUrl(options) {
|
|
36
|
-
const resolved = defaultScmResolveUrl(options);
|
|
37
|
-
if (!options.lineNumber) {
|
|
38
|
-
return resolved;
|
|
39
|
-
}
|
|
40
|
-
const url = new URL(resolved);
|
|
41
|
-
if (this.integrationConfig.host === "bitbucket.org") {
|
|
42
|
-
url.hash = `lines-${options.lineNumber}`;
|
|
43
|
-
} else {
|
|
44
|
-
url.hash = `${options.lineNumber}`;
|
|
45
|
-
}
|
|
46
|
-
return url.toString();
|
|
47
|
-
}
|
|
48
|
-
resolveEditUrl(url) {
|
|
49
|
-
const urlData = parseGitUrl(url);
|
|
50
|
-
const editUrl = new URL(url);
|
|
51
|
-
editUrl.searchParams.set("mode", "edit");
|
|
52
|
-
editUrl.searchParams.set("spa", "0");
|
|
53
|
-
editUrl.searchParams.set("at", urlData.ref);
|
|
54
|
-
return editUrl.toString();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export { BitbucketIntegration };
|
|
59
|
-
//# sourceMappingURL=BitbucketIntegration.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BitbucketIntegration.esm.js","sources":["../../src/bitbucket/BitbucketIntegration.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport parseGitUrl from 'git-url-parse';\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport {\n BitbucketIntegrationConfig,\n readBitbucketIntegrationConfigs,\n} from './config';\n\n/**\n * A Bitbucket based integration.\n *\n * @public\n * @deprecated replaced by the integrations bitbucketCloud and bitbucketServer.\n */\nexport class BitbucketIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<BitbucketIntegration> = ({\n config,\n }) => {\n const configs = readBitbucketIntegrationConfigs(\n config.getOptionalConfigArray('integrations.bitbucket') ?? [\n // if integrations.bitbucket was not used assume the use was migrated to the new configs\n // and backport for the deprecated integration to be usable for other parts of the system\n // until these got migrated\n ...(config.getOptionalConfigArray('integrations.bitbucketCloud') ?? []),\n ...(config.getOptionalConfigArray('integrations.bitbucketServer') ??\n []),\n ],\n );\n return basicIntegrations(\n configs.map(c => new BitbucketIntegration(c)),\n i => i.config.host,\n );\n };\n\n constructor(private readonly integrationConfig: BitbucketIntegrationConfig) {}\n\n get type(): string {\n return 'bitbucket';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): BitbucketIntegrationConfig {\n return this.integrationConfig;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n }): string {\n const resolved = defaultScmResolveUrl(options);\n if (!options.lineNumber) {\n return resolved;\n }\n\n const url = new URL(resolved);\n\n if (this.integrationConfig.host === 'bitbucket.org') {\n // Bitbucket Cloud uses the syntax #lines-{start}[:{end}][,...]\n url.hash = `lines-${options.lineNumber}`;\n } else {\n // Bitbucket Server uses the syntax #{start}[-{end}][,...]\n url.hash = `${options.lineNumber}`;\n }\n\n return url.toString();\n }\n\n resolveEditUrl(url: string): string {\n const urlData = parseGitUrl(url);\n const editUrl = new URL(url);\n\n editUrl.searchParams.set('mode', 'edit');\n // TODO: Not sure what spa=0 does, at least bitbucket.org doesn't support it\n // but this is taken over from the initial implementation.\n editUrl.searchParams.set('spa', '0');\n editUrl.searchParams.set('at', urlData.ref);\n return editUrl.toString();\n }\n}\n"],"names":[],"mappings":";;;;AA8BO,MAAM,oBAAA,CAA+C;AAAA,EAoB1D,YAA6B,iBAAA,EAA+C;AAA/C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAAA,EAAgD;AAAA,EAnB7E,OAAO,UAAwD,CAAC;AAAA,IAC9D;AAAA,GACF,KAAM;AACJ,IAAA,MAAM,OAAA,GAAU,+BAAA;AAAA,MACd,MAAA,CAAO,sBAAA,CAAuB,wBAAwB,CAAA,IAAK;AAAA;AAAA;AAAA;AAAA,QAIzD,GAAI,MAAA,CAAO,sBAAA,CAAuB,6BAA6B,KAAK,EAAC;AAAA,QACrE,GAAI,MAAA,CAAO,sBAAA,CAAuB,8BAA8B,KAC9D;AAAC;AACL,KACF;AACA,IAAA,OAAO,iBAAA;AAAA,MACL,QAAQ,GAAA,CAAI,CAAA,CAAA,KAAK,IAAI,oBAAA,CAAqB,CAAC,CAAC,CAAA;AAAA,MAC5C,CAAA,CAAA,KAAK,EAAE,MAAA,CAAO;AAAA,KAChB;AAAA,EACF,CAAA;AAAA,EAIA,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,WAAA;AAAA,EACT;AAAA,EAEA,IAAI,KAAA,GAAgB;AAClB,IAAA,OAAO,KAAK,iBAAA,CAAkB,IAAA;AAAA,EAChC;AAAA,EAEA,IAAI,MA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KET_API_BASE_URL = "https://api.bitbucket.org/2.0";
|
|
8
|
-
function readBitbucketIntegrationConfig(config) {
|
|
9
|
-
const host = config.getOptionalString("host") ?? BITBUCKET_HOST;
|
|
10
|
-
let apiBaseUrl = config.getOptionalString("apiBaseUrl");
|
|
11
|
-
const token = config.getOptionalString("token")?.trim();
|
|
12
|
-
const username = config.getOptionalString("username");
|
|
13
|
-
const appPassword = config.getOptionalString("appPassword")?.trim();
|
|
14
|
-
if (!helpers.isValidHost(host)) {
|
|
15
|
-
throw new Error(
|
|
16
|
-
`Invalid Bitbucket integration config, '${host}' is not a valid host`
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
if (apiBaseUrl) {
|
|
20
|
-
apiBaseUrl = lodash.trimEnd(apiBaseUrl, "/");
|
|
21
|
-
} else if (host === BITBUCKET_HOST) {
|
|
22
|
-
apiBaseUrl = BITBUCKET_API_BASE_URL;
|
|
23
|
-
} else {
|
|
24
|
-
apiBaseUrl = `https://${host}/rest/api/1.0`;
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
host,
|
|
28
|
-
apiBaseUrl,
|
|
29
|
-
token,
|
|
30
|
-
username,
|
|
31
|
-
appPassword,
|
|
32
|
-
commitSigningKey: config.getOptionalString("commitSigningKey")
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function readBitbucketIntegrationConfigs(configs) {
|
|
36
|
-
const result = configs.map(readBitbucketIntegrationConfig);
|
|
37
|
-
if (!result.some((c) => c.host === BITBUCKET_HOST)) {
|
|
38
|
-
result.push({
|
|
39
|
-
host: BITBUCKET_HOST,
|
|
40
|
-
apiBaseUrl: BITBUCKET_API_BASE_URL
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
exports.readBitbucketIntegrationConfig = readBitbucketIntegrationConfig;
|
|
47
|
-
exports.readBitbucketIntegrationConfigs = readBitbucketIntegrationConfigs;
|
|
48
|
-
//# sourceMappingURL=config.cjs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs.js","sources":["../../src/bitbucket/config.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport { trimEnd } from 'lodash';\nimport { isValidHost } from '../helpers';\n\nconst BITBUCKET_HOST = 'bitbucket.org';\nconst BITBUCKET_API_BASE_URL = 'https://api.bitbucket.org/2.0';\n\n/**\n * The configuration parameters for a single Bitbucket API provider.\n *\n * @public\n * @deprecated bitbucket integration replaced by integrations bitbucketCloud and bitbucketServer.\n */\nexport type BitbucketIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. \"bitbucket.org\"\n */\n host: string;\n\n /**\n * The base URL of the API of this provider, e.g. \"https://api.bitbucket.org/2.0\",\n * with no trailing slash.\n *\n * Values omitted at the optional property at the app-config will be deduced\n * from the \"host\" value.\n */\n apiBaseUrl: string;\n\n /**\n * The authorization token to use for requests to a Bitbucket Server provider.\n *\n * See https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html\n *\n * If no token is specified, anonymous access is used.\n */\n token?: string;\n\n /**\n * The username to use for requests to Bitbucket Cloud (bitbucket.org).\n */\n username?: string;\n\n /**\n * Authentication with Bitbucket Cloud (bitbucket.org) is done using app passwords.\n *\n * See https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/\n */\n appPassword?: string;\n\n /**\n * Signing key for commits\n */\n commitSigningKey?: string;\n};\n\n/**\n * Reads a single Bitbucket integration config.\n *\n * @param config - The config object of a single integration\n * @public\n * @deprecated bitbucket integration replaced by integrations bitbucketCloud and bitbucketServer.\n */\nexport function readBitbucketIntegrationConfig(\n config: Config,\n): BitbucketIntegrationConfig {\n const host = config.getOptionalString('host') ?? BITBUCKET_HOST;\n let apiBaseUrl = config.getOptionalString('apiBaseUrl');\n const token = config.getOptionalString('token')?.trim();\n const username = config.getOptionalString('username');\n const appPassword = config.getOptionalString('appPassword')?.trim();\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid Bitbucket integration config, '${host}' is not a valid host`,\n );\n }\n\n if (apiBaseUrl) {\n apiBaseUrl = trimEnd(apiBaseUrl, '/');\n } else if (host === BITBUCKET_HOST) {\n apiBaseUrl = BITBUCKET_API_BASE_URL;\n } else {\n apiBaseUrl = `https://${host}/rest/api/1.0`;\n }\n\n return {\n host,\n apiBaseUrl,\n token,\n username,\n appPassword,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\n };\n}\n\n/**\n * Reads a set of Bitbucket integration configs, and inserts some defaults for\n * public Bitbucket if not specified.\n *\n * @param configs - All of the integration config objects\n * @public\n * @deprecated bitbucket integration replaced by integrations bitbucketCloud and bitbucketServer.\n */\nexport function readBitbucketIntegrationConfigs(\n configs: Config[],\n): BitbucketIntegrationConfig[] {\n // First read all the explicit integrations\n const result = configs.map(readBitbucketIntegrationConfig);\n\n // If no explicit bitbucket.org integration was added, put one in the list as\n // a convenience\n if (!result.some(c => c.host === BITBUCKET_HOST)) {\n result.push({\n host: BITBUCKET_HOST,\n apiBaseUrl: BITBUCKET_API_BASE_URL,\n });\n }\n\n return result;\n}\n"],"names":["isValidHost","trimEnd"],"mappings":";;;;;AAoBA,MAAM,cAAA,GAAiB,eAAA;AACvB,MAAM,sBAAA,GAAyB,+BAAA;AAyDxB,SAAS,+BACd,MAAA,EAC4B;AAC5B,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,iBAAA,CAAkB,MAAM,CAAA,IAAK,cAAA;AACjD,EAAA,IAAI,UAAA,GAAa,MAAA,CAAO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import { trimEnd } from 'lodash';
|
|
2
|
-
import { isValidHost } from '../helpers.esm.js';
|
|
3
|
-
|
|
4
|
-
const BITBUCKET_HOST = "bitbucket.org";
|
|
5
|
-
const BITBUCKET_API_BASE_URL = "https://api.bitbucket.org/2.0";
|
|
6
|
-
function readBitbucketIntegrationConfig(config) {
|
|
7
|
-
const host = config.getOptionalString("host") ?? BITBUCKET_HOST;
|
|
8
|
-
let apiBaseUrl = config.getOptionalString("apiBaseUrl");
|
|
9
|
-
const token = config.getOptionalString("token")?.trim();
|
|
10
|
-
const username = config.getOptionalString("username");
|
|
11
|
-
const appPassword = config.getOptionalString("appPassword")?.trim();
|
|
12
|
-
if (!isValidHost(host)) {
|
|
13
|
-
throw new Error(
|
|
14
|
-
`Invalid Bitbucket integration config, '${host}' is not a valid host`
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
if (apiBaseUrl) {
|
|
18
|
-
apiBaseUrl = trimEnd(apiBaseUrl, "/");
|
|
19
|
-
} else if (host === BITBUCKET_HOST) {
|
|
20
|
-
apiBaseUrl = BITBUCKET_API_BASE_URL;
|
|
21
|
-
} else {
|
|
22
|
-
apiBaseUrl = `https://${host}/rest/api/1.0`;
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
host,
|
|
26
|
-
apiBaseUrl,
|
|
27
|
-
token,
|
|
28
|
-
username,
|
|
29
|
-
appPassword,
|
|
30
|
-
commitSigningKey: config.getOptionalString("commitSigningKey")
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function readBitbucketIntegrationConfigs(configs) {
|
|
34
|
-
const result = configs.map(readBitbucketIntegrationConfig);
|
|
35
|
-
if (!result.some((c) => c.host === BITBUCKET_HOST)) {
|
|
36
|
-
result.push({
|
|
37
|
-
host: BITBUCKET_HOST,
|
|
38
|
-
apiBaseUrl: BITBUCKET_API_BASE_URL
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export { readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs };
|
|
45
|
-
//# sourceMappingURL=config.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.esm.js","sources":["../../src/bitbucket/config.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport { trimEnd } from 'lodash';\nimport { isValidHost } from '../helpers';\n\nconst BITBUCKET_HOST = 'bitbucket.org';\nconst BITBUCKET_API_BASE_URL = 'https://api.bitbucket.org/2.0';\n\n/**\n * The configuration parameters for a single Bitbucket API provider.\n *\n * @public\n * @deprecated bitbucket integration replaced by integrations bitbucketCloud and bitbucketServer.\n */\nexport type BitbucketIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. \"bitbucket.org\"\n */\n host: string;\n\n /**\n * The base URL of the API of this provider, e.g. \"https://api.bitbucket.org/2.0\",\n * with no trailing slash.\n *\n * Values omitted at the optional property at the app-config will be deduced\n * from the \"host\" value.\n */\n apiBaseUrl: string;\n\n /**\n * The authorization token to use for requests to a Bitbucket Server provider.\n *\n * See https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html\n *\n * If no token is specified, anonymous access is used.\n */\n token?: string;\n\n /**\n * The username to use for requests to Bitbucket Cloud (bitbucket.org).\n */\n username?: string;\n\n /**\n * Authentication with Bitbucket Cloud (bitbucket.org) is done using app passwords.\n *\n * See https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/\n */\n appPassword?: string;\n\n /**\n * Signing key for commits\n */\n commitSigningKey?: string;\n};\n\n/**\n * Reads a single Bitbucket integration config.\n *\n * @param config - The config object of a single integration\n * @public\n * @deprecated bitbucket integration replaced by integrations bitbucketCloud and bitbucketServer.\n */\nexport function readBitbucketIntegrationConfig(\n config: Config,\n): BitbucketIntegrationConfig {\n const host = config.getOptionalString('host') ?? BITBUCKET_HOST;\n let apiBaseUrl = config.getOptionalString('apiBaseUrl');\n const token = config.getOptionalString('token')?.trim();\n const username = config.getOptionalString('username');\n const appPassword = config.getOptionalString('appPassword')?.trim();\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid Bitbucket integration config, '${host}' is not a valid host`,\n );\n }\n\n if (apiBaseUrl) {\n apiBaseUrl = trimEnd(apiBaseUrl, '/');\n } else if (host === BITBUCKET_HOST) {\n apiBaseUrl = BITBUCKET_API_BASE_URL;\n } else {\n apiBaseUrl = `https://${host}/rest/api/1.0`;\n }\n\n return {\n host,\n apiBaseUrl,\n token,\n username,\n appPassword,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\n };\n}\n\n/**\n * Reads a set of Bitbucket integration configs, and inserts some defaults for\n * public Bitbucket if not specified.\n *\n * @param configs - All of the integration config objects\n * @public\n * @deprecated bitbucket integration replaced by integrations bitbucketCloud and bitbucketServer.\n */\nexport function readBitbucketIntegrationConfigs(\n configs: Config[],\n): BitbucketIntegrationConfig[] {\n // First read all the explicit integrations\n const result = configs.map(readBitbucketIntegrationConfig);\n\n // If no explicit bitbucket.org integration was added, put one in the list as\n // a convenience\n if (!result.some(c => c.host === BITBUCKET_HOST)) {\n result.push({\n host: BITBUCKET_HOST,\n apiBaseUrl: BITBUCKET_API_BASE_URL,\n });\n }\n\n return result;\n}\n"],"names":[],"mappings":";;;AAoBA,MAAM,cAAA,GAAiB,eAAA;AACvB,MAAM,sBAAA,GAAyB,+BAAA;AAyDxB,SAAS,+BACd,MAAA,EAC4B;AAC5B,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,iBAAA,CAAkB,MAAM,CAAA,IAAK,cAA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
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var fetch = require('cross-fetch');
|
|
4
|
-
var parseGitUrl = require('git-url-parse');
|
|
5
|
-
|
|
6
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
7
|
-
|
|
8
|
-
var fetch__default = /*#__PURE__*/_interopDefaultCompat(fetch);
|
|
9
|
-
var parseGitUrl__default = /*#__PURE__*/_interopDefaultCompat(parseGitUrl);
|
|
10
|
-
|
|
11
|
-
async function getBitbucketDefaultBranch(url, config) {
|
|
12
|
-
const { name: repoName, owner: project, resource } = parseGitUrl__default.default(url);
|
|
13
|
-
const isHosted = resource === "bitbucket.org";
|
|
14
|
-
let branchUrl = isHosted ? `${config.apiBaseUrl}/repositories/${project}/${repoName}` : `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/default-branch`;
|
|
15
|
-
let response = await fetch__default.default(branchUrl, getBitbucketRequestOptions(config));
|
|
16
|
-
if (response.status === 404 && !isHosted) {
|
|
17
|
-
branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/branches/default`;
|
|
18
|
-
response = await fetch__default.default(branchUrl, getBitbucketRequestOptions(config));
|
|
19
|
-
}
|
|
20
|
-
if (!response.ok) {
|
|
21
|
-
const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;
|
|
22
|
-
throw new Error(message);
|
|
23
|
-
}
|
|
24
|
-
let defaultBranch;
|
|
25
|
-
if (isHosted) {
|
|
26
|
-
const repoInfo = await response.json();
|
|
27
|
-
defaultBranch = repoInfo.mainbranch.name;
|
|
28
|
-
} else {
|
|
29
|
-
const { displayId } = await response.json();
|
|
30
|
-
defaultBranch = displayId;
|
|
31
|
-
}
|
|
32
|
-
if (!defaultBranch) {
|
|
33
|
-
throw new Error(
|
|
34
|
-
`Failed to read default branch from ${branchUrl}. Response ${response.status} ${response.json()}`
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
return defaultBranch;
|
|
38
|
-
}
|
|
39
|
-
async function getBitbucketDownloadUrl(url, config) {
|
|
40
|
-
const {
|
|
41
|
-
name: repoName,
|
|
42
|
-
owner: project,
|
|
43
|
-
ref,
|
|
44
|
-
protocol,
|
|
45
|
-
resource,
|
|
46
|
-
filepath
|
|
47
|
-
} = parseGitUrl__default.default(url);
|
|
48
|
-
const isHosted = resource === "bitbucket.org";
|
|
49
|
-
let branch = ref;
|
|
50
|
-
if (!branch) {
|
|
51
|
-
branch = await getBitbucketDefaultBranch(url, config);
|
|
52
|
-
}
|
|
53
|
-
const path = filepath ? `&path=${encodeURIComponent(decodeURIComponent(filepath))}` : "";
|
|
54
|
-
const archiveUrl = isHosted ? `${protocol}://${resource}/${project}/${repoName}/get/${branch}.tar.gz` : `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=tgz&at=${branch}&prefix=${project}-${repoName}${path}`;
|
|
55
|
-
return archiveUrl;
|
|
56
|
-
}
|
|
57
|
-
function getBitbucketFileFetchUrl(url, config) {
|
|
58
|
-
try {
|
|
59
|
-
const { owner, name, ref, filepathtype, filepath } = parseGitUrl__default.default(url);
|
|
60
|
-
if (!owner || !name || filepathtype !== "browse" && filepathtype !== "raw" && filepathtype !== "src") {
|
|
61
|
-
throw new Error("Invalid Bitbucket URL or file path");
|
|
62
|
-
}
|
|
63
|
-
const pathWithoutSlash = filepath.replace(/^\//, "");
|
|
64
|
-
if (config.host === "bitbucket.org") {
|
|
65
|
-
if (!ref) {
|
|
66
|
-
throw new Error("Invalid Bitbucket URL or file path");
|
|
67
|
-
}
|
|
68
|
-
return `${config.apiBaseUrl}/repositories/${owner}/${name}/src/${ref}/${pathWithoutSlash}`;
|
|
69
|
-
}
|
|
70
|
-
return `${config.apiBaseUrl}/projects/${owner}/repos/${name}/raw/${pathWithoutSlash}?at=${ref}`;
|
|
71
|
-
} catch (e) {
|
|
72
|
-
throw new Error(`Incorrect URL: ${url}, ${e}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function getBitbucketRequestOptions(config) {
|
|
76
|
-
const headers = {};
|
|
77
|
-
if (config.token) {
|
|
78
|
-
headers.Authorization = `Bearer ${config.token}`;
|
|
79
|
-
} else if (config.username && config.appPassword) {
|
|
80
|
-
const buffer = Buffer.from(
|
|
81
|
-
`${config.username}:${config.appPassword}`,
|
|
82
|
-
"utf8"
|
|
83
|
-
);
|
|
84
|
-
headers.Authorization = `Basic ${buffer.toString("base64")}`;
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
headers
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
exports.getBitbucketDefaultBranch = getBitbucketDefaultBranch;
|
|
92
|
-
exports.getBitbucketDownloadUrl = getBitbucketDownloadUrl;
|
|
93
|
-
exports.getBitbucketFileFetchUrl = getBitbucketFileFetchUrl;
|
|
94
|
-
exports.getBitbucketRequestOptions = getBitbucketRequestOptions;
|
|
95
|
-
//# sourceMappingURL=core.cjs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs.js","sources":["../../src/bitbucket/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 { BitbucketIntegrationConfig } 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 * @deprecated no longer in use, bitbucket integration replaced by integrations bitbucketCloud and bitbucketServer.\n */\nexport async function getBitbucketDefaultBranch(\n url: string,\n config: BitbucketIntegrationConfig,\n): Promise<string> {\n const { name: repoName, owner: project, resource } = parseGitUrl(url);\n\n const isHosted = resource === 'bitbucket.org';\n // Bitbucket Server https://docs.atlassian.com/bitbucket-server/rest/7.9.0/bitbucket-rest.html#idp184\n let branchUrl = isHosted\n ? `${config.apiBaseUrl}/repositories/${project}/${repoName}`\n : `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/default-branch`;\n\n let response = await fetch(branchUrl, getBitbucketRequestOptions(config));\n\n if (response.status === 404 && !isHosted) {\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 v5.11.1 format )\n branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/branches/default`;\n response = await fetch(branchUrl, getBitbucketRequestOptions(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 let defaultBranch;\n if (isHosted) {\n const repoInfo = await response.json();\n defaultBranch = repoInfo.mainbranch.name;\n } else {\n const { displayId } = await response.json();\n defaultBranch = displayId;\n }\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 * @deprecated no longer in use, bitbucket integration replaced by integrations bitbucketCloud and bitbucketServer.\n */\nexport async function getBitbucketDownloadUrl(\n url: string,\n config: BitbucketIntegrationConfig,\n): Promise<string> {\n const {\n name: repoName,\n owner: project,\n ref,\n protocol,\n resource,\n filepath,\n } = parseGitUrl(url);\n\n const isHosted = resource === 'bitbucket.org';\n\n let branch = ref;\n if (!branch) {\n branch = await getBitbucketDefaultBranch(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 const archiveUrl = isHosted\n ? `${protocol}://${resource}/${project}/${repoName}/get/${branch}.tar.gz`\n : `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=tgz&at=${branch}&prefix=${project}-${repoName}${path}`;\n\n return archiveUrl;\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.org/orgname/reponame/src/master/file.yaml\n * to: https://api.bitbucket.org/2.0/repositories/orgname/reponame/src/master/file.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n * @deprecated no longer in use, bitbucket integration replaced by integrations bitbucketCloud and bitbucketServer.\n */\nexport function getBitbucketFileFetchUrl(\n url: string,\n config: BitbucketIntegrationConfig,\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 URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n\n if (config.host === 'bitbucket.org') {\n if (!ref) {\n throw new Error('Invalid Bitbucket URL or file path');\n }\n return `${config.apiBaseUrl}/repositories/${owner}/${name}/src/${ref}/${pathWithoutSlash}`;\n }\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 * @deprecated no longer in use, bitbucket integration replaced by integrations bitbucketCloud and bitbucketServer.\n */\nexport function getBitbucketRequestOptions(\n config: BitbucketIntegrationConfig,\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.appPassword) {\n const buffer = Buffer.from(\n `${config.username}:${config.appPassword}`,\n 'utf8',\n );\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n }\n\n return {\n headers,\n };\n}\n"],"names":["parseGitUrl","fetch"],"mappings":";;;;;;;;;;AA4BA,eAAsB,yBAAA,CACpB,KACA,MAAA,EACiB;AACjB,EAAA,MAAM,EAAE,MAAM,QAAA,EAAU,KAAA,EAAO,SAAS,QAAA,EAAS,GAAIA,6BAAY,GAAG,CAAA;AAEpE,EAAA,MAAM,WAAW,QAAA,KAAa,eAAA;AAE9B,EAAA,IAAI,YAAY,QAAA,GACZ,CAAA,EAAG,MAAA,CAAO,UAAU,iBAAiB,OAAO,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAA,GACxD,GAAG,MAAA,CAAO,UAAU,CAAA,UAAA,EAAa,OAAO,UAAU,QAAQ,CAAA,eAAA,CAAA;AAE9D,EAAA,IAAI,WAAW,MAAMC,sBAAA,CAAM,SAAA,EAAW,0BAAA,CAA2B,MAAM,CAAC,CAAA;AAExE,EAAA,IAAI,QAAA,CAAS,MAAA,KAAW,GAAA,IAAO,CAAC,QAAA,EAAU;AAGxC,IAAA,SAAA,GAAY,GAAG,MAAA,CAAO,UAAU,CAAA,UAAA,EAAa,OAAO,UAAU,QAAQ,CAAA,iBAAA,CAAA;AACtE,IAAA,QAAA,GAAW,MAAMA,sBAAA,CAAM,SAAA,EAAW,0BAAA,CAA2B,MAAM,CAAC,CAAA;AAAA,EACtE;AAEA,EAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,IAAA,MAAM,OAAA,GAAU,0CAA0C,SAAS,CAAA,EAAA,EAAK,SAAS,MAAM,CAAA,CAAA,EAAI,SAAS,UAAU,CAAA,CAAA;AAC9G,IAAA,MAAM,IAAI,MAAM,OAAO,CAAA;AAAA,EACzB;AAEA,EAAA,IAAI,aAAA;AACJ,EAAA,IAAI,QAAA,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,MAAM,UAAkC,EAAC;AAEzC,EAAA,IAAI,OAAO,KAAA,EAAO;AAChB,IAAA,OAAA,CAAQ,aAAA,GAAgB,CAAA,OAAA,EAAU,MAAA,CAAO,KAAK,CAAA,CAAA;AAAA,EAChD,CAAA,MAAA,IAAW,MAAA,CAAO,QAAA,IAAY,MAAA,CAAO,WAAA,EAAa;AAChD,IAAA,MAAM,SAAS,MAAA,CAAO,IAAA;AAAA,MACpB,CAAA,EAAG,MAAA,CAAO,QAAQ,CAAA,CAAA,EAAI,OAAO,WAAW,CAAA,CAAA;AAAA,MACxC;AAAA,KACF;AACA,IAAA,OAAA,CAAQ,aAAA,GAAgB,CAAA,MAAA,EAAS,MAAA,CAAO,QAAA,CAAS,QAAQ,CAAC,CAAA,CAAA;AAAA,EAC5D;AAEA,EAAA,OAAO;AAAA,IACL;AAAA,GACF;AACF;;;;;;;"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import fetch from 'cross-fetch';
|
|
2
|
-
import parseGitUrl from 'git-url-parse';
|
|
3
|
-
|
|
4
|
-
async function getBitbucketDefaultBranch(url, config) {
|
|
5
|
-
const { name: repoName, owner: project, resource } = parseGitUrl(url);
|
|
6
|
-
const isHosted = resource === "bitbucket.org";
|
|
7
|
-
let branchUrl = isHosted ? `${config.apiBaseUrl}/repositories/${project}/${repoName}` : `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/default-branch`;
|
|
8
|
-
let response = await fetch(branchUrl, getBitbucketRequestOptions(config));
|
|
9
|
-
if (response.status === 404 && !isHosted) {
|
|
10
|
-
branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/branches/default`;
|
|
11
|
-
response = await fetch(branchUrl, getBitbucketRequestOptions(config));
|
|
12
|
-
}
|
|
13
|
-
if (!response.ok) {
|
|
14
|
-
const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;
|
|
15
|
-
throw new Error(message);
|
|
16
|
-
}
|
|
17
|
-
let defaultBranch;
|
|
18
|
-
if (isHosted) {
|
|
19
|
-
const repoInfo = await response.json();
|
|
20
|
-
defaultBranch = repoInfo.mainbranch.name;
|
|
21
|
-
} else {
|
|
22
|
-
const { displayId } = await response.json();
|
|
23
|
-
defaultBranch = displayId;
|
|
24
|
-
}
|
|
25
|
-
if (!defaultBranch) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
`Failed to read default branch from ${branchUrl}. Response ${response.status} ${response.json()}`
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
return defaultBranch;
|
|
31
|
-
}
|
|
32
|
-
async function getBitbucketDownloadUrl(url, config) {
|
|
33
|
-
const {
|
|
34
|
-
name: repoName,
|
|
35
|
-
owner: project,
|
|
36
|
-
ref,
|
|
37
|
-
protocol,
|
|
38
|
-
resource,
|
|
39
|
-
filepath
|
|
40
|
-
} = parseGitUrl(url);
|
|
41
|
-
const isHosted = resource === "bitbucket.org";
|
|
42
|
-
let branch = ref;
|
|
43
|
-
if (!branch) {
|
|
44
|
-
branch = await getBitbucketDefaultBranch(url, config);
|
|
45
|
-
}
|
|
46
|
-
const path = filepath ? `&path=${encodeURIComponent(decodeURIComponent(filepath))}` : "";
|
|
47
|
-
const archiveUrl = isHosted ? `${protocol}://${resource}/${project}/${repoName}/get/${branch}.tar.gz` : `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=tgz&at=${branch}&prefix=${project}-${repoName}${path}`;
|
|
48
|
-
return archiveUrl;
|
|
49
|
-
}
|
|
50
|
-
function getBitbucketFileFetchUrl(url, config) {
|
|
51
|
-
try {
|
|
52
|
-
const { owner, name, ref, filepathtype, filepath } = parseGitUrl(url);
|
|
53
|
-
if (!owner || !name || filepathtype !== "browse" && filepathtype !== "raw" && filepathtype !== "src") {
|
|
54
|
-
throw new Error("Invalid Bitbucket URL or file path");
|
|
55
|
-
}
|
|
56
|
-
const pathWithoutSlash = filepath.replace(/^\//, "");
|
|
57
|
-
if (config.host === "bitbucket.org") {
|
|
58
|
-
if (!ref) {
|
|
59
|
-
throw new Error("Invalid Bitbucket URL or file path");
|
|
60
|
-
}
|
|
61
|
-
return `${config.apiBaseUrl}/repositories/${owner}/${name}/src/${ref}/${pathWithoutSlash}`;
|
|
62
|
-
}
|
|
63
|
-
return `${config.apiBaseUrl}/projects/${owner}/repos/${name}/raw/${pathWithoutSlash}?at=${ref}`;
|
|
64
|
-
} catch (e) {
|
|
65
|
-
throw new Error(`Incorrect URL: ${url}, ${e}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function getBitbucketRequestOptions(config) {
|
|
69
|
-
const headers = {};
|
|
70
|
-
if (config.token) {
|
|
71
|
-
headers.Authorization = `Bearer ${config.token}`;
|
|
72
|
-
} else if (config.username && config.appPassword) {
|
|
73
|
-
const buffer = Buffer.from(
|
|
74
|
-
`${config.username}:${config.appPassword}`,
|
|
75
|
-
"utf8"
|
|
76
|
-
);
|
|
77
|
-
headers.Authorization = `Basic ${buffer.toString("base64")}`;
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
headers
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export { getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions };
|
|
85
|
-
//# sourceMappingURL=core.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.esm.js","sources":["../../src/bitbucket/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 { BitbucketIntegrationConfig } 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 * @deprecated no longer in use, bitbucket integration replaced by integrations bitbucketCloud and bitbucketServer.\n */\nexport async function getBitbucketDefaultBranch(\n url: string,\n config: BitbucketIntegrationConfig,\n): Promise<string> {\n const { name: repoName, owner: project, resource } = parseGitUrl(url);\n\n const isHosted = resource === 'bitbucket.org';\n // Bitbucket Server https://docs.atlassian.com/bitbucket-server/rest/7.9.0/bitbucket-rest.html#idp184\n let branchUrl = isHosted\n ? `${config.apiBaseUrl}/repositories/${project}/${repoName}`\n : `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/default-branch`;\n\n let response = await fetch(branchUrl, getBitbucketRequestOptions(config));\n\n if (response.status === 404 && !isHosted) {\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 v5.11.1 format )\n branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/branches/default`;\n response = await fetch(branchUrl, getBitbucketRequestOptions(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 let defaultBranch;\n if (isHosted) {\n const repoInfo = await response.json();\n defaultBranch = repoInfo.mainbranch.name;\n } else {\n const { displayId } = await response.json();\n defaultBranch = displayId;\n }\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 * @deprecated no longer in use, bitbucket integration replaced by integrations bitbucketCloud and bitbucketServer.\n */\nexport async function getBitbucketDownloadUrl(\n url: string,\n config: BitbucketIntegrationConfig,\n): Promise<string> {\n const {\n name: repoName,\n owner: project,\n ref,\n protocol,\n resource,\n filepath,\n } = parseGitUrl(url);\n\n const isHosted = resource === 'bitbucket.org';\n\n let branch = ref;\n if (!branch) {\n branch = await getBitbucketDefaultBranch(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 const archiveUrl = isHosted\n ? `${protocol}://${resource}/${project}/${repoName}/get/${branch}.tar.gz`\n : `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=tgz&at=${branch}&prefix=${project}-${repoName}${path}`;\n\n return archiveUrl;\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.org/orgname/reponame/src/master/file.yaml\n * to: https://api.bitbucket.org/2.0/repositories/orgname/reponame/src/master/file.yaml\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n * @deprecated no longer in use, bitbucket integration replaced by integrations bitbucketCloud and bitbucketServer.\n */\nexport function getBitbucketFileFetchUrl(\n url: string,\n config: BitbucketIntegrationConfig,\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 URL or file path');\n }\n\n const pathWithoutSlash = filepath.replace(/^\\//, '');\n\n if (config.host === 'bitbucket.org') {\n if (!ref) {\n throw new Error('Invalid Bitbucket URL or file path');\n }\n return `${config.apiBaseUrl}/repositories/${owner}/${name}/src/${ref}/${pathWithoutSlash}`;\n }\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 * @deprecated no longer in use, bitbucket integration replaced by integrations bitbucketCloud and bitbucketServer.\n */\nexport function getBitbucketRequestOptions(\n config: BitbucketIntegrationConfig,\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.appPassword) {\n const buffer = Buffer.from(\n `${config.username}:${config.appPassword}`,\n 'utf8',\n );\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n }\n\n return {\n headers,\n };\n}\n"],"names":[],"mappings":";;;AA4BA,eAAsB,yBAAA,CACpB,KACA,MAAA,EACiB;AACjB,EAAA,MAAM,EAAE,MAAM,QAAA,EAAU,KAAA,EAAO,SAAS,QAAA,EAAS,GAAI,YAAY,GAAG,CAAA;AAEpE,EAAA,MAAM,WAAW,QAAA,KAAa,eAAA;AAE9B,EAAA,IAAI,YAAY,QAAA,GACZ,CAAA,EAAG,MAAA,CAAO,UAAU,iBAAiB,OAAO,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAA,GACxD,GAAG,MAAA,CAAO,UAAU,CAAA,UAAA,EAAa,OAAO,UAAU,QAAQ,CAAA,eAAA,CAAA;AAE9D,EAAA,IAAI,WAAW,MAAM,KAAA,CAAM,SAAA,EAAW,0BAAA,CAA2B,MAAM,CAAC,CAAA;AAExE,EAAA,IAAI,QAAA,CAAS,MAAA,KAAW,GAAA,IAAO,CAAC,QAAA,EAAU;AAGxC,IAAA,SAAA,GAAY,GAAG,MAAA,CAAO,UAAU,CAAA,UAAA,EAAa,OAAO,UAAU,QAAQ,CAAA,iBAAA,CAAA;AACtE,IAAA,QAAA,GAAW,MAAM,KAAA,CAAM,SAAA,EAAW,0BAAA,CAA2B,MAAM,CAAC,CAAA;AAAA,EACtE;AAEA,EAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,IAAA,MAAM,OAAA,GAAU,0CAA0C,SAAS,CAAA,EAAA,EAAK,SAAS,MAAM,CAAA,CAAA,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