@backstage/integration 1.1.0 → 1.2.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 +93 -0
- package/config.d.ts +42 -1
- package/dist/index.cjs.js +370 -82
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +364 -78
- package/dist/index.esm.js +353 -83
- package/dist/index.esm.js.map +1 -1
- package/package.json +7 -6
package/dist/index.cjs.js
CHANGED
|
@@ -8,6 +8,7 @@ var fetch = require('cross-fetch');
|
|
|
8
8
|
var authApp = require('@octokit/auth-app');
|
|
9
9
|
var rest = require('@octokit/rest');
|
|
10
10
|
var luxon = require('luxon');
|
|
11
|
+
var errors = require('@backstage/errors');
|
|
11
12
|
|
|
12
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
14
|
|
|
@@ -68,6 +69,79 @@ function defaultScmResolveUrl(options) {
|
|
|
68
69
|
return updated.toString();
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
const AMAZON_AWS_HOST = "amazonaws.com";
|
|
73
|
+
function readAwsS3IntegrationConfig(config) {
|
|
74
|
+
var _a;
|
|
75
|
+
const endpoint = config.getOptionalString("endpoint");
|
|
76
|
+
const s3ForcePathStyle = (_a = config.getOptionalBoolean("s3ForcePathStyle")) != null ? _a : false;
|
|
77
|
+
let host;
|
|
78
|
+
let pathname;
|
|
79
|
+
if (endpoint) {
|
|
80
|
+
try {
|
|
81
|
+
const url = new URL(endpoint);
|
|
82
|
+
host = url.host;
|
|
83
|
+
pathname = url.pathname;
|
|
84
|
+
} catch {
|
|
85
|
+
throw new Error(`invalid awsS3 integration config, endpoint '${endpoint}' is not a valid URL`);
|
|
86
|
+
}
|
|
87
|
+
if (pathname !== "/") {
|
|
88
|
+
throw new Error(`invalid awsS3 integration config, endpoints cannot contain path, got '${endpoint}'`);
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
host = AMAZON_AWS_HOST;
|
|
92
|
+
}
|
|
93
|
+
const accessKeyId = config.getOptionalString("accessKeyId");
|
|
94
|
+
const secretAccessKey = config.getOptionalString("secretAccessKey");
|
|
95
|
+
const roleArn = config.getOptionalString("roleArn");
|
|
96
|
+
const externalId = config.getOptionalString("externalId");
|
|
97
|
+
return {
|
|
98
|
+
host,
|
|
99
|
+
endpoint,
|
|
100
|
+
s3ForcePathStyle,
|
|
101
|
+
accessKeyId,
|
|
102
|
+
secretAccessKey,
|
|
103
|
+
roleArn,
|
|
104
|
+
externalId
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function readAwsS3IntegrationConfigs(configs) {
|
|
108
|
+
const result = configs.map(readAwsS3IntegrationConfig);
|
|
109
|
+
if (!result.some((c) => c.host === AMAZON_AWS_HOST)) {
|
|
110
|
+
result.push({
|
|
111
|
+
host: AMAZON_AWS_HOST
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const _AwsS3Integration = class {
|
|
118
|
+
constructor(integrationConfig) {
|
|
119
|
+
this.integrationConfig = integrationConfig;
|
|
120
|
+
}
|
|
121
|
+
get type() {
|
|
122
|
+
return "awsS3";
|
|
123
|
+
}
|
|
124
|
+
get title() {
|
|
125
|
+
return this.integrationConfig.host;
|
|
126
|
+
}
|
|
127
|
+
get config() {
|
|
128
|
+
return this.integrationConfig;
|
|
129
|
+
}
|
|
130
|
+
resolveUrl(options) {
|
|
131
|
+
const resolved = defaultScmResolveUrl(options);
|
|
132
|
+
return resolved;
|
|
133
|
+
}
|
|
134
|
+
resolveEditUrl(url) {
|
|
135
|
+
return url;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
let AwsS3Integration = _AwsS3Integration;
|
|
139
|
+
AwsS3Integration.factory = ({ config }) => {
|
|
140
|
+
var _a;
|
|
141
|
+
const configs = readAwsS3IntegrationConfigs((_a = config.getOptionalConfigArray("integrations.awsS3")) != null ? _a : []);
|
|
142
|
+
return basicIntegrations(configs.map((c) => new _AwsS3Integration(c)), (i) => i.config.host);
|
|
143
|
+
};
|
|
144
|
+
|
|
71
145
|
var __accessCheck = (obj, member, msg) => {
|
|
72
146
|
if (!member.has(obj))
|
|
73
147
|
throw TypeError("Cannot " + msg);
|
|
@@ -371,8 +445,11 @@ let BitbucketIntegration = _BitbucketIntegration;
|
|
|
371
445
|
BitbucketIntegration.factory = ({
|
|
372
446
|
config
|
|
373
447
|
}) => {
|
|
374
|
-
var _a;
|
|
375
|
-
const configs = readBitbucketIntegrationConfigs((
|
|
448
|
+
var _a, _b, _c;
|
|
449
|
+
const configs = readBitbucketIntegrationConfigs((_c = config.getOptionalConfigArray("integrations.bitbucket")) != null ? _c : [
|
|
450
|
+
...(_a = config.getOptionalConfigArray("integrations.bitbucketCloud")) != null ? _a : [],
|
|
451
|
+
...(_b = config.getOptionalConfigArray("integrations.bitbucketServer")) != null ? _b : []
|
|
452
|
+
]);
|
|
376
453
|
return basicIntegrations(configs.map((c) => new _BitbucketIntegration(c)), (i) => i.config.host);
|
|
377
454
|
};
|
|
378
455
|
|
|
@@ -451,9 +528,242 @@ function getBitbucketRequestOptions(config) {
|
|
|
451
528
|
};
|
|
452
529
|
}
|
|
453
530
|
|
|
531
|
+
const BITBUCKET_CLOUD_HOST = "bitbucket.org";
|
|
532
|
+
const BITBUCKET_CLOUD_API_BASE_URL = "https://api.bitbucket.org/2.0";
|
|
533
|
+
function readBitbucketCloudIntegrationConfig(config) {
|
|
534
|
+
const host = BITBUCKET_CLOUD_HOST;
|
|
535
|
+
const apiBaseUrl = BITBUCKET_CLOUD_API_BASE_URL;
|
|
536
|
+
const username = config.getString("username");
|
|
537
|
+
const appPassword = config.getString("appPassword");
|
|
538
|
+
return {
|
|
539
|
+
host,
|
|
540
|
+
apiBaseUrl,
|
|
541
|
+
username,
|
|
542
|
+
appPassword
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
function readBitbucketCloudIntegrationConfigs(configs) {
|
|
546
|
+
const result = configs.map(readBitbucketCloudIntegrationConfig);
|
|
547
|
+
if (result.length === 0) {
|
|
548
|
+
result.push({
|
|
549
|
+
host: BITBUCKET_CLOUD_HOST,
|
|
550
|
+
apiBaseUrl: BITBUCKET_CLOUD_API_BASE_URL
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
return result;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
const _BitbucketCloudIntegration = class {
|
|
557
|
+
constructor(integrationConfig) {
|
|
558
|
+
this.integrationConfig = integrationConfig;
|
|
559
|
+
}
|
|
560
|
+
get type() {
|
|
561
|
+
return "bitbucketCloud";
|
|
562
|
+
}
|
|
563
|
+
get title() {
|
|
564
|
+
return this.integrationConfig.host;
|
|
565
|
+
}
|
|
566
|
+
get config() {
|
|
567
|
+
return this.integrationConfig;
|
|
568
|
+
}
|
|
569
|
+
resolveUrl(options) {
|
|
570
|
+
const resolved = defaultScmResolveUrl(options);
|
|
571
|
+
if (options.lineNumber) {
|
|
572
|
+
const url = new URL(resolved);
|
|
573
|
+
url.hash = `lines-${options.lineNumber}`;
|
|
574
|
+
return url.toString();
|
|
575
|
+
}
|
|
576
|
+
return resolved;
|
|
577
|
+
}
|
|
578
|
+
resolveEditUrl(url) {
|
|
579
|
+
const urlData = parseGitUrl__default["default"](url);
|
|
580
|
+
const editUrl = new URL(url);
|
|
581
|
+
editUrl.searchParams.set("mode", "edit");
|
|
582
|
+
editUrl.searchParams.set("at", urlData.ref);
|
|
583
|
+
return editUrl.toString();
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
let BitbucketCloudIntegration = _BitbucketCloudIntegration;
|
|
587
|
+
BitbucketCloudIntegration.factory = ({
|
|
588
|
+
config
|
|
589
|
+
}) => {
|
|
590
|
+
var _a;
|
|
591
|
+
const configs = readBitbucketCloudIntegrationConfigs((_a = config.getOptionalConfigArray("integrations.bitbucketCloud")) != null ? _a : []);
|
|
592
|
+
return basicIntegrations(configs.map((c) => new _BitbucketCloudIntegration(c)), (i) => i.config.host);
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
async function getBitbucketCloudDefaultBranch(url, config) {
|
|
596
|
+
const { name: repoName, owner: project } = parseGitUrl__default["default"](url);
|
|
597
|
+
const branchUrl = `${config.apiBaseUrl}/repositories/${project}/${repoName}`;
|
|
598
|
+
const response = await fetch__default["default"](branchUrl, getBitbucketCloudRequestOptions(config));
|
|
599
|
+
if (!response.ok) {
|
|
600
|
+
const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;
|
|
601
|
+
throw new Error(message);
|
|
602
|
+
}
|
|
603
|
+
const repoInfo = await response.json();
|
|
604
|
+
const defaultBranch = repoInfo.mainbranch.name;
|
|
605
|
+
if (!defaultBranch) {
|
|
606
|
+
throw new Error(`Failed to read default branch from ${branchUrl}. Response ${response.status} ${response.json()}`);
|
|
607
|
+
}
|
|
608
|
+
return defaultBranch;
|
|
609
|
+
}
|
|
610
|
+
async function getBitbucketCloudDownloadUrl(url, config) {
|
|
611
|
+
const {
|
|
612
|
+
name: repoName,
|
|
613
|
+
owner: project,
|
|
614
|
+
ref,
|
|
615
|
+
protocol,
|
|
616
|
+
resource
|
|
617
|
+
} = parseGitUrl__default["default"](url);
|
|
618
|
+
let branch = ref;
|
|
619
|
+
if (!branch) {
|
|
620
|
+
branch = await getBitbucketCloudDefaultBranch(url, config);
|
|
621
|
+
}
|
|
622
|
+
return `${protocol}://${resource}/${project}/${repoName}/get/${branch}.tar.gz`;
|
|
623
|
+
}
|
|
624
|
+
function getBitbucketCloudFileFetchUrl(url, config) {
|
|
625
|
+
try {
|
|
626
|
+
const { owner, name, ref, filepathtype, filepath } = parseGitUrl__default["default"](url);
|
|
627
|
+
if (!owner || !name || filepathtype !== "src" && filepathtype !== "raw") {
|
|
628
|
+
throw new Error("Invalid Bitbucket Cloud URL or file path");
|
|
629
|
+
}
|
|
630
|
+
const pathWithoutSlash = filepath.replace(/^\//, "");
|
|
631
|
+
if (!ref) {
|
|
632
|
+
throw new Error("Invalid Bitbucket Cloud URL or file path");
|
|
633
|
+
}
|
|
634
|
+
return `${config.apiBaseUrl}/repositories/${owner}/${name}/src/${ref}/${pathWithoutSlash}`;
|
|
635
|
+
} catch (e) {
|
|
636
|
+
throw new Error(`Incorrect URL: ${url}, ${e}`);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
function getBitbucketCloudRequestOptions(config) {
|
|
640
|
+
const headers = {};
|
|
641
|
+
if (config.username && config.appPassword) {
|
|
642
|
+
const buffer = Buffer.from(`${config.username}:${config.appPassword}`, "utf8");
|
|
643
|
+
headers.Authorization = `Basic ${buffer.toString("base64")}`;
|
|
644
|
+
}
|
|
645
|
+
return {
|
|
646
|
+
headers
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
function readBitbucketServerIntegrationConfig(config) {
|
|
651
|
+
const host = config.getString("host");
|
|
652
|
+
let apiBaseUrl = config.getOptionalString("apiBaseUrl");
|
|
653
|
+
const token = config.getOptionalString("token");
|
|
654
|
+
if (!isValidHost(host)) {
|
|
655
|
+
throw new Error(`Invalid Bitbucket Server integration config, '${host}' is not a valid host`);
|
|
656
|
+
}
|
|
657
|
+
if (apiBaseUrl) {
|
|
658
|
+
apiBaseUrl = lodash.trimEnd(apiBaseUrl, "/");
|
|
659
|
+
} else {
|
|
660
|
+
apiBaseUrl = `https://${host}/rest/api/1.0`;
|
|
661
|
+
}
|
|
662
|
+
return {
|
|
663
|
+
host,
|
|
664
|
+
apiBaseUrl,
|
|
665
|
+
token
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
function readBitbucketServerIntegrationConfigs(configs) {
|
|
669
|
+
return configs.map(readBitbucketServerIntegrationConfig);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
const _BitbucketServerIntegration = class {
|
|
673
|
+
constructor(integrationConfig) {
|
|
674
|
+
this.integrationConfig = integrationConfig;
|
|
675
|
+
}
|
|
676
|
+
get type() {
|
|
677
|
+
return "bitbucketServer";
|
|
678
|
+
}
|
|
679
|
+
get title() {
|
|
680
|
+
return this.integrationConfig.host;
|
|
681
|
+
}
|
|
682
|
+
get config() {
|
|
683
|
+
return this.integrationConfig;
|
|
684
|
+
}
|
|
685
|
+
resolveUrl(options) {
|
|
686
|
+
const resolved = defaultScmResolveUrl(options);
|
|
687
|
+
if (options.lineNumber) {
|
|
688
|
+
const url = new URL(resolved);
|
|
689
|
+
const filename = url.pathname.split("/").slice(-1)[0];
|
|
690
|
+
url.hash = `${filename}-${options.lineNumber}`;
|
|
691
|
+
return url.toString();
|
|
692
|
+
}
|
|
693
|
+
return resolved;
|
|
694
|
+
}
|
|
695
|
+
resolveEditUrl(url) {
|
|
696
|
+
const urlData = parseGitUrl__default["default"](url);
|
|
697
|
+
const editUrl = new URL(url);
|
|
698
|
+
editUrl.searchParams.set("mode", "edit");
|
|
699
|
+
editUrl.searchParams.set("spa", "0");
|
|
700
|
+
editUrl.searchParams.set("at", urlData.ref);
|
|
701
|
+
return editUrl.toString();
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
let BitbucketServerIntegration = _BitbucketServerIntegration;
|
|
705
|
+
BitbucketServerIntegration.factory = ({
|
|
706
|
+
config
|
|
707
|
+
}) => {
|
|
708
|
+
var _a;
|
|
709
|
+
const configs = readBitbucketServerIntegrationConfigs((_a = config.getOptionalConfigArray("integrations.bitbucketServer")) != null ? _a : []);
|
|
710
|
+
return basicIntegrations(configs.map((c) => new _BitbucketServerIntegration(c)), (i) => i.config.host);
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
async function getBitbucketServerDefaultBranch(url, config) {
|
|
714
|
+
const { name: repoName, owner: project } = parseGitUrl__default["default"](url);
|
|
715
|
+
let branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/default-branch`;
|
|
716
|
+
let response = await fetch__default["default"](branchUrl, getBitbucketServerRequestOptions(config));
|
|
717
|
+
if (response.status === 404) {
|
|
718
|
+
branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/branches/default`;
|
|
719
|
+
response = await fetch__default["default"](branchUrl, getBitbucketServerRequestOptions(config));
|
|
720
|
+
}
|
|
721
|
+
if (!response.ok) {
|
|
722
|
+
const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;
|
|
723
|
+
throw new Error(message);
|
|
724
|
+
}
|
|
725
|
+
const { displayId } = await response.json();
|
|
726
|
+
const defaultBranch = displayId;
|
|
727
|
+
if (!defaultBranch) {
|
|
728
|
+
throw new Error(`Failed to read default branch from ${branchUrl}. Response ${response.status} ${response.json()}`);
|
|
729
|
+
}
|
|
730
|
+
return defaultBranch;
|
|
731
|
+
}
|
|
732
|
+
async function getBitbucketServerDownloadUrl(url, config) {
|
|
733
|
+
const { name: repoName, owner: project, ref, filepath } = parseGitUrl__default["default"](url);
|
|
734
|
+
let branch = ref;
|
|
735
|
+
if (!branch) {
|
|
736
|
+
branch = await getBitbucketServerDefaultBranch(url, config);
|
|
737
|
+
}
|
|
738
|
+
const path = filepath ? `&path=${encodeURIComponent(filepath)}` : "";
|
|
739
|
+
return `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=tgz&at=${branch}&prefix=${project}-${repoName}${path}`;
|
|
740
|
+
}
|
|
741
|
+
function getBitbucketServerFileFetchUrl(url, config) {
|
|
742
|
+
try {
|
|
743
|
+
const { owner, name, ref, filepathtype, filepath } = parseGitUrl__default["default"](url);
|
|
744
|
+
if (!owner || !name || filepathtype !== "browse" && filepathtype !== "raw" && filepathtype !== "src") {
|
|
745
|
+
throw new Error("Invalid Bitbucket Server URL or file path");
|
|
746
|
+
}
|
|
747
|
+
const pathWithoutSlash = filepath.replace(/^\//, "");
|
|
748
|
+
return `${config.apiBaseUrl}/projects/${owner}/repos/${name}/raw/${pathWithoutSlash}?at=${ref}`;
|
|
749
|
+
} catch (e) {
|
|
750
|
+
throw new Error(`Incorrect URL: ${url}, ${e}`);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
function getBitbucketServerRequestOptions(config) {
|
|
754
|
+
const headers = {};
|
|
755
|
+
if (config.token) {
|
|
756
|
+
headers.Authorization = `Bearer ${config.token}`;
|
|
757
|
+
}
|
|
758
|
+
return {
|
|
759
|
+
headers
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
|
|
454
763
|
function readGerritIntegrationConfig(config) {
|
|
455
764
|
const host = config.getString("host");
|
|
456
765
|
let baseUrl = config.getOptionalString("baseUrl");
|
|
766
|
+
let cloneUrl = config.getOptionalString("cloneUrl");
|
|
457
767
|
let gitilesBaseUrl = config.getOptionalString("gitilesBaseUrl");
|
|
458
768
|
const username = config.getOptionalString("username");
|
|
459
769
|
const password = config.getOptionalString("password");
|
|
@@ -461,6 +771,8 @@ function readGerritIntegrationConfig(config) {
|
|
|
461
771
|
throw new Error(`Invalid Gerrit integration config, '${host}' is not a valid host`);
|
|
462
772
|
} else if (baseUrl && !isValidUrl(baseUrl)) {
|
|
463
773
|
throw new Error(`Invalid Gerrit integration config, '${baseUrl}' is not a valid baseUrl`);
|
|
774
|
+
} else if (cloneUrl && !isValidUrl(cloneUrl)) {
|
|
775
|
+
throw new Error(`Invalid Gerrit integration config, '${cloneUrl}' is not a valid cloneUrl`);
|
|
464
776
|
} else if (gitilesBaseUrl && !isValidUrl(gitilesBaseUrl)) {
|
|
465
777
|
throw new Error(`Invalid Gerrit integration config, '${gitilesBaseUrl}' is not a valid gitilesBaseUrl`);
|
|
466
778
|
}
|
|
@@ -474,9 +786,15 @@ function readGerritIntegrationConfig(config) {
|
|
|
474
786
|
} else {
|
|
475
787
|
gitilesBaseUrl = `https://${host}`;
|
|
476
788
|
}
|
|
789
|
+
if (cloneUrl) {
|
|
790
|
+
cloneUrl = lodash.trimEnd(cloneUrl, "/");
|
|
791
|
+
} else {
|
|
792
|
+
cloneUrl = baseUrl;
|
|
793
|
+
}
|
|
477
794
|
return {
|
|
478
795
|
host,
|
|
479
796
|
baseUrl,
|
|
797
|
+
cloneUrl,
|
|
480
798
|
gitilesBaseUrl,
|
|
481
799
|
username,
|
|
482
800
|
password
|
|
@@ -524,7 +842,7 @@ GerritIntegration.factory = ({ config }) => {
|
|
|
524
842
|
};
|
|
525
843
|
|
|
526
844
|
const GERRIT_BODY_PREFIX = ")]}'";
|
|
527
|
-
function
|
|
845
|
+
function parseGerritGitilesUrl(config, url) {
|
|
528
846
|
const urlPath = url.replace(config.gitilesBaseUrl, "");
|
|
529
847
|
const parts = urlPath.split("/").filter((p) => !!p);
|
|
530
848
|
const projectEndIndex = parts.indexOf("+");
|
|
@@ -547,10 +865,21 @@ function parseGitilesUrl(config, url) {
|
|
|
547
865
|
function getAuthenticationPrefix(config) {
|
|
548
866
|
return config.password ? "/a/" : "/";
|
|
549
867
|
}
|
|
868
|
+
function getGerritBranchApiUrl(config, url) {
|
|
869
|
+
const { branch, project } = parseGerritGitilesUrl(config, url);
|
|
870
|
+
return `${config.baseUrl}${getAuthenticationPrefix(config)}projects/${encodeURIComponent(project)}/branches/${branch}`;
|
|
871
|
+
}
|
|
872
|
+
function getGerritCloneRepoUrl(config, url) {
|
|
873
|
+
const { project } = parseGerritGitilesUrl(config, url);
|
|
874
|
+
return `${config.cloneUrl}${getAuthenticationPrefix(config)}${project}`;
|
|
875
|
+
}
|
|
550
876
|
function getGerritFileContentsApiUrl(config, url) {
|
|
551
|
-
const { branch, filePath, project } =
|
|
877
|
+
const { branch, filePath, project } = parseGerritGitilesUrl(config, url);
|
|
552
878
|
return `${config.baseUrl}${getAuthenticationPrefix(config)}projects/${encodeURIComponent(project)}/branches/${branch}/files/${encodeURIComponent(filePath)}/content`;
|
|
553
879
|
}
|
|
880
|
+
function getGerritProjectsApiUrl(config) {
|
|
881
|
+
return `${config.baseUrl}${getAuthenticationPrefix(config)}projects/`;
|
|
882
|
+
}
|
|
554
883
|
function getGerritRequestOptions(config) {
|
|
555
884
|
const headers = {};
|
|
556
885
|
if (!config.password) {
|
|
@@ -906,14 +1235,20 @@ function getGitLabRequestOptions(config) {
|
|
|
906
1235
|
function buildRawUrl(target) {
|
|
907
1236
|
try {
|
|
908
1237
|
const url = new URL(target);
|
|
909
|
-
const
|
|
910
|
-
|
|
911
|
-
|
|
1238
|
+
const splitPath = url.pathname.split("/").filter(Boolean);
|
|
1239
|
+
const blobIndex = splitPath.indexOf("blob", 2);
|
|
1240
|
+
if (blobIndex < 2 || blobIndex === splitPath.length - 1) {
|
|
1241
|
+
throw new errors.InputError("Wrong GitLab URL");
|
|
1242
|
+
}
|
|
1243
|
+
const repoPath = splitPath.slice(0, blobIndex);
|
|
1244
|
+
const restOfPath = splitPath.slice(blobIndex + 1);
|
|
1245
|
+
if (!restOfPath.join("/").match(/\.(yaml|yml)$/)) {
|
|
1246
|
+
throw new errors.InputError("Wrong GitLab URL");
|
|
912
1247
|
}
|
|
913
|
-
url.pathname = [
|
|
1248
|
+
url.pathname = [...repoPath, "raw", ...restOfPath].join("/");
|
|
914
1249
|
return url;
|
|
915
1250
|
} catch (e) {
|
|
916
|
-
throw new
|
|
1251
|
+
throw new errors.InputError(`Incorrect url: ${target}, ${e}`);
|
|
917
1252
|
}
|
|
918
1253
|
}
|
|
919
1254
|
function buildProjectUrl(target, projectID) {
|
|
@@ -995,85 +1330,14 @@ function readGoogleGcsIntegrationConfig(config) {
|
|
|
995
1330
|
return { clientEmail, privateKey };
|
|
996
1331
|
}
|
|
997
1332
|
|
|
998
|
-
const AMAZON_AWS_HOST = "amazonaws.com";
|
|
999
|
-
function readAwsS3IntegrationConfig(config) {
|
|
1000
|
-
var _a;
|
|
1001
|
-
const endpoint = config.getOptionalString("endpoint");
|
|
1002
|
-
const s3ForcePathStyle = (_a = config.getOptionalBoolean("s3ForcePathStyle")) != null ? _a : false;
|
|
1003
|
-
let host;
|
|
1004
|
-
let pathname;
|
|
1005
|
-
if (endpoint) {
|
|
1006
|
-
try {
|
|
1007
|
-
const url = new URL(endpoint);
|
|
1008
|
-
host = url.host;
|
|
1009
|
-
pathname = url.pathname;
|
|
1010
|
-
} catch {
|
|
1011
|
-
throw new Error(`invalid awsS3 integration config, endpoint '${endpoint}' is not a valid URL`);
|
|
1012
|
-
}
|
|
1013
|
-
if (pathname !== "/") {
|
|
1014
|
-
throw new Error(`invalid awsS3 integration config, endpoints cannot contain path, got '${endpoint}'`);
|
|
1015
|
-
}
|
|
1016
|
-
} else {
|
|
1017
|
-
host = AMAZON_AWS_HOST;
|
|
1018
|
-
}
|
|
1019
|
-
const accessKeyId = config.getOptionalString("accessKeyId");
|
|
1020
|
-
const secretAccessKey = config.getOptionalString("secretAccessKey");
|
|
1021
|
-
const roleArn = config.getOptionalString("roleArn");
|
|
1022
|
-
const externalId = config.getOptionalString("externalId");
|
|
1023
|
-
return {
|
|
1024
|
-
host,
|
|
1025
|
-
endpoint,
|
|
1026
|
-
s3ForcePathStyle,
|
|
1027
|
-
accessKeyId,
|
|
1028
|
-
secretAccessKey,
|
|
1029
|
-
roleArn,
|
|
1030
|
-
externalId
|
|
1031
|
-
};
|
|
1032
|
-
}
|
|
1033
|
-
function readAwsS3IntegrationConfigs(configs) {
|
|
1034
|
-
const result = configs.map(readAwsS3IntegrationConfig);
|
|
1035
|
-
if (!result.some((c) => c.host === AMAZON_AWS_HOST)) {
|
|
1036
|
-
result.push({
|
|
1037
|
-
host: AMAZON_AWS_HOST
|
|
1038
|
-
});
|
|
1039
|
-
}
|
|
1040
|
-
return result;
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
const _AwsS3Integration = class {
|
|
1044
|
-
constructor(integrationConfig) {
|
|
1045
|
-
this.integrationConfig = integrationConfig;
|
|
1046
|
-
}
|
|
1047
|
-
get type() {
|
|
1048
|
-
return "awsS3";
|
|
1049
|
-
}
|
|
1050
|
-
get title() {
|
|
1051
|
-
return this.integrationConfig.host;
|
|
1052
|
-
}
|
|
1053
|
-
get config() {
|
|
1054
|
-
return this.integrationConfig;
|
|
1055
|
-
}
|
|
1056
|
-
resolveUrl(options) {
|
|
1057
|
-
const resolved = defaultScmResolveUrl(options);
|
|
1058
|
-
return resolved;
|
|
1059
|
-
}
|
|
1060
|
-
resolveEditUrl(url) {
|
|
1061
|
-
return url;
|
|
1062
|
-
}
|
|
1063
|
-
};
|
|
1064
|
-
let AwsS3Integration = _AwsS3Integration;
|
|
1065
|
-
AwsS3Integration.factory = ({ config }) => {
|
|
1066
|
-
var _a;
|
|
1067
|
-
const configs = readAwsS3IntegrationConfigs((_a = config.getOptionalConfigArray("integrations.awsS3")) != null ? _a : []);
|
|
1068
|
-
return basicIntegrations(configs.map((c) => new _AwsS3Integration(c)), (i) => i.config.host);
|
|
1069
|
-
};
|
|
1070
|
-
|
|
1071
1333
|
class ScmIntegrations {
|
|
1072
1334
|
static fromConfig(config) {
|
|
1073
1335
|
return new ScmIntegrations({
|
|
1074
1336
|
awsS3: AwsS3Integration.factory({ config }),
|
|
1075
1337
|
azure: AzureIntegration.factory({ config }),
|
|
1076
1338
|
bitbucket: BitbucketIntegration.factory({ config }),
|
|
1339
|
+
bitbucketCloud: BitbucketCloudIntegration.factory({ config }),
|
|
1340
|
+
bitbucketServer: BitbucketServerIntegration.factory({ config }),
|
|
1077
1341
|
gerrit: GerritIntegration.factory({ config }),
|
|
1078
1342
|
github: GitHubIntegration.factory({ config }),
|
|
1079
1343
|
gitlab: GitLabIntegration.factory({ config })
|
|
@@ -1091,6 +1355,12 @@ class ScmIntegrations {
|
|
|
1091
1355
|
get bitbucket() {
|
|
1092
1356
|
return this.byType.bitbucket;
|
|
1093
1357
|
}
|
|
1358
|
+
get bitbucketCloud() {
|
|
1359
|
+
return this.byType.bitbucketCloud;
|
|
1360
|
+
}
|
|
1361
|
+
get bitbucketServer() {
|
|
1362
|
+
return this.byType.bitbucketServer;
|
|
1363
|
+
}
|
|
1094
1364
|
get gerrit() {
|
|
1095
1365
|
return this.byType.gerrit;
|
|
1096
1366
|
}
|
|
@@ -1127,7 +1397,9 @@ class ScmIntegrations {
|
|
|
1127
1397
|
|
|
1128
1398
|
exports.AwsS3Integration = AwsS3Integration;
|
|
1129
1399
|
exports.AzureIntegration = AzureIntegration;
|
|
1400
|
+
exports.BitbucketCloudIntegration = BitbucketCloudIntegration;
|
|
1130
1401
|
exports.BitbucketIntegration = BitbucketIntegration;
|
|
1402
|
+
exports.BitbucketServerIntegration = BitbucketServerIntegration;
|
|
1131
1403
|
exports.DefaultGithubCredentialsProvider = DefaultGithubCredentialsProvider;
|
|
1132
1404
|
exports.GerritIntegration = GerritIntegration;
|
|
1133
1405
|
exports.GitHubIntegration = GitHubIntegration;
|
|
@@ -1140,23 +1412,39 @@ exports.getAzureCommitsUrl = getAzureCommitsUrl;
|
|
|
1140
1412
|
exports.getAzureDownloadUrl = getAzureDownloadUrl;
|
|
1141
1413
|
exports.getAzureFileFetchUrl = getAzureFileFetchUrl;
|
|
1142
1414
|
exports.getAzureRequestOptions = getAzureRequestOptions;
|
|
1415
|
+
exports.getBitbucketCloudDefaultBranch = getBitbucketCloudDefaultBranch;
|
|
1416
|
+
exports.getBitbucketCloudDownloadUrl = getBitbucketCloudDownloadUrl;
|
|
1417
|
+
exports.getBitbucketCloudFileFetchUrl = getBitbucketCloudFileFetchUrl;
|
|
1418
|
+
exports.getBitbucketCloudRequestOptions = getBitbucketCloudRequestOptions;
|
|
1143
1419
|
exports.getBitbucketDefaultBranch = getBitbucketDefaultBranch;
|
|
1144
1420
|
exports.getBitbucketDownloadUrl = getBitbucketDownloadUrl;
|
|
1145
1421
|
exports.getBitbucketFileFetchUrl = getBitbucketFileFetchUrl;
|
|
1146
1422
|
exports.getBitbucketRequestOptions = getBitbucketRequestOptions;
|
|
1423
|
+
exports.getBitbucketServerDefaultBranch = getBitbucketServerDefaultBranch;
|
|
1424
|
+
exports.getBitbucketServerDownloadUrl = getBitbucketServerDownloadUrl;
|
|
1425
|
+
exports.getBitbucketServerFileFetchUrl = getBitbucketServerFileFetchUrl;
|
|
1426
|
+
exports.getBitbucketServerRequestOptions = getBitbucketServerRequestOptions;
|
|
1427
|
+
exports.getGerritBranchApiUrl = getGerritBranchApiUrl;
|
|
1428
|
+
exports.getGerritCloneRepoUrl = getGerritCloneRepoUrl;
|
|
1147
1429
|
exports.getGerritFileContentsApiUrl = getGerritFileContentsApiUrl;
|
|
1430
|
+
exports.getGerritProjectsApiUrl = getGerritProjectsApiUrl;
|
|
1148
1431
|
exports.getGerritRequestOptions = getGerritRequestOptions;
|
|
1149
1432
|
exports.getGitHubFileFetchUrl = getGitHubFileFetchUrl;
|
|
1150
1433
|
exports.getGitHubRequestOptions = getGitHubRequestOptions;
|
|
1151
1434
|
exports.getGitLabFileFetchUrl = getGitLabFileFetchUrl;
|
|
1152
1435
|
exports.getGitLabRequestOptions = getGitLabRequestOptions;
|
|
1436
|
+
exports.parseGerritGitilesUrl = parseGerritGitilesUrl;
|
|
1153
1437
|
exports.parseGerritJsonResponse = parseGerritJsonResponse;
|
|
1154
1438
|
exports.readAwsS3IntegrationConfig = readAwsS3IntegrationConfig;
|
|
1155
1439
|
exports.readAwsS3IntegrationConfigs = readAwsS3IntegrationConfigs;
|
|
1156
1440
|
exports.readAzureIntegrationConfig = readAzureIntegrationConfig;
|
|
1157
1441
|
exports.readAzureIntegrationConfigs = readAzureIntegrationConfigs;
|
|
1442
|
+
exports.readBitbucketCloudIntegrationConfig = readBitbucketCloudIntegrationConfig;
|
|
1443
|
+
exports.readBitbucketCloudIntegrationConfigs = readBitbucketCloudIntegrationConfigs;
|
|
1158
1444
|
exports.readBitbucketIntegrationConfig = readBitbucketIntegrationConfig;
|
|
1159
1445
|
exports.readBitbucketIntegrationConfigs = readBitbucketIntegrationConfigs;
|
|
1446
|
+
exports.readBitbucketServerIntegrationConfig = readBitbucketServerIntegrationConfig;
|
|
1447
|
+
exports.readBitbucketServerIntegrationConfigs = readBitbucketServerIntegrationConfigs;
|
|
1160
1448
|
exports.readGerritIntegrationConfig = readGerritIntegrationConfig;
|
|
1161
1449
|
exports.readGerritIntegrationConfigs = readGerritIntegrationConfigs;
|
|
1162
1450
|
exports.readGitHubIntegrationConfig = readGitHubIntegrationConfig;
|