@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.esm.js
CHANGED
|
@@ -4,6 +4,7 @@ import fetch from 'cross-fetch';
|
|
|
4
4
|
import { createAppAuth } from '@octokit/auth-app';
|
|
5
5
|
import { Octokit } from '@octokit/rest';
|
|
6
6
|
import { DateTime } from 'luxon';
|
|
7
|
+
import { InputError } from '@backstage/errors';
|
|
7
8
|
|
|
8
9
|
function isValidHost(host) {
|
|
9
10
|
const check = new URL("http://example.com");
|
|
@@ -59,6 +60,79 @@ function defaultScmResolveUrl(options) {
|
|
|
59
60
|
return updated.toString();
|
|
60
61
|
}
|
|
61
62
|
|
|
63
|
+
const AMAZON_AWS_HOST = "amazonaws.com";
|
|
64
|
+
function readAwsS3IntegrationConfig(config) {
|
|
65
|
+
var _a;
|
|
66
|
+
const endpoint = config.getOptionalString("endpoint");
|
|
67
|
+
const s3ForcePathStyle = (_a = config.getOptionalBoolean("s3ForcePathStyle")) != null ? _a : false;
|
|
68
|
+
let host;
|
|
69
|
+
let pathname;
|
|
70
|
+
if (endpoint) {
|
|
71
|
+
try {
|
|
72
|
+
const url = new URL(endpoint);
|
|
73
|
+
host = url.host;
|
|
74
|
+
pathname = url.pathname;
|
|
75
|
+
} catch {
|
|
76
|
+
throw new Error(`invalid awsS3 integration config, endpoint '${endpoint}' is not a valid URL`);
|
|
77
|
+
}
|
|
78
|
+
if (pathname !== "/") {
|
|
79
|
+
throw new Error(`invalid awsS3 integration config, endpoints cannot contain path, got '${endpoint}'`);
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
host = AMAZON_AWS_HOST;
|
|
83
|
+
}
|
|
84
|
+
const accessKeyId = config.getOptionalString("accessKeyId");
|
|
85
|
+
const secretAccessKey = config.getOptionalString("secretAccessKey");
|
|
86
|
+
const roleArn = config.getOptionalString("roleArn");
|
|
87
|
+
const externalId = config.getOptionalString("externalId");
|
|
88
|
+
return {
|
|
89
|
+
host,
|
|
90
|
+
endpoint,
|
|
91
|
+
s3ForcePathStyle,
|
|
92
|
+
accessKeyId,
|
|
93
|
+
secretAccessKey,
|
|
94
|
+
roleArn,
|
|
95
|
+
externalId
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function readAwsS3IntegrationConfigs(configs) {
|
|
99
|
+
const result = configs.map(readAwsS3IntegrationConfig);
|
|
100
|
+
if (!result.some((c) => c.host === AMAZON_AWS_HOST)) {
|
|
101
|
+
result.push({
|
|
102
|
+
host: AMAZON_AWS_HOST
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const _AwsS3Integration = class {
|
|
109
|
+
constructor(integrationConfig) {
|
|
110
|
+
this.integrationConfig = integrationConfig;
|
|
111
|
+
}
|
|
112
|
+
get type() {
|
|
113
|
+
return "awsS3";
|
|
114
|
+
}
|
|
115
|
+
get title() {
|
|
116
|
+
return this.integrationConfig.host;
|
|
117
|
+
}
|
|
118
|
+
get config() {
|
|
119
|
+
return this.integrationConfig;
|
|
120
|
+
}
|
|
121
|
+
resolveUrl(options) {
|
|
122
|
+
const resolved = defaultScmResolveUrl(options);
|
|
123
|
+
return resolved;
|
|
124
|
+
}
|
|
125
|
+
resolveEditUrl(url) {
|
|
126
|
+
return url;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
let AwsS3Integration = _AwsS3Integration;
|
|
130
|
+
AwsS3Integration.factory = ({ config }) => {
|
|
131
|
+
var _a;
|
|
132
|
+
const configs = readAwsS3IntegrationConfigs((_a = config.getOptionalConfigArray("integrations.awsS3")) != null ? _a : []);
|
|
133
|
+
return basicIntegrations(configs.map((c) => new _AwsS3Integration(c)), (i) => i.config.host);
|
|
134
|
+
};
|
|
135
|
+
|
|
62
136
|
var __accessCheck = (obj, member, msg) => {
|
|
63
137
|
if (!member.has(obj))
|
|
64
138
|
throw TypeError("Cannot " + msg);
|
|
@@ -362,8 +436,11 @@ let BitbucketIntegration = _BitbucketIntegration;
|
|
|
362
436
|
BitbucketIntegration.factory = ({
|
|
363
437
|
config
|
|
364
438
|
}) => {
|
|
365
|
-
var _a;
|
|
366
|
-
const configs = readBitbucketIntegrationConfigs((
|
|
439
|
+
var _a, _b, _c;
|
|
440
|
+
const configs = readBitbucketIntegrationConfigs((_c = config.getOptionalConfigArray("integrations.bitbucket")) != null ? _c : [
|
|
441
|
+
...(_a = config.getOptionalConfigArray("integrations.bitbucketCloud")) != null ? _a : [],
|
|
442
|
+
...(_b = config.getOptionalConfigArray("integrations.bitbucketServer")) != null ? _b : []
|
|
443
|
+
]);
|
|
367
444
|
return basicIntegrations(configs.map((c) => new _BitbucketIntegration(c)), (i) => i.config.host);
|
|
368
445
|
};
|
|
369
446
|
|
|
@@ -442,9 +519,242 @@ function getBitbucketRequestOptions(config) {
|
|
|
442
519
|
};
|
|
443
520
|
}
|
|
444
521
|
|
|
522
|
+
const BITBUCKET_CLOUD_HOST = "bitbucket.org";
|
|
523
|
+
const BITBUCKET_CLOUD_API_BASE_URL = "https://api.bitbucket.org/2.0";
|
|
524
|
+
function readBitbucketCloudIntegrationConfig(config) {
|
|
525
|
+
const host = BITBUCKET_CLOUD_HOST;
|
|
526
|
+
const apiBaseUrl = BITBUCKET_CLOUD_API_BASE_URL;
|
|
527
|
+
const username = config.getString("username");
|
|
528
|
+
const appPassword = config.getString("appPassword");
|
|
529
|
+
return {
|
|
530
|
+
host,
|
|
531
|
+
apiBaseUrl,
|
|
532
|
+
username,
|
|
533
|
+
appPassword
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
function readBitbucketCloudIntegrationConfigs(configs) {
|
|
537
|
+
const result = configs.map(readBitbucketCloudIntegrationConfig);
|
|
538
|
+
if (result.length === 0) {
|
|
539
|
+
result.push({
|
|
540
|
+
host: BITBUCKET_CLOUD_HOST,
|
|
541
|
+
apiBaseUrl: BITBUCKET_CLOUD_API_BASE_URL
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
return result;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const _BitbucketCloudIntegration = class {
|
|
548
|
+
constructor(integrationConfig) {
|
|
549
|
+
this.integrationConfig = integrationConfig;
|
|
550
|
+
}
|
|
551
|
+
get type() {
|
|
552
|
+
return "bitbucketCloud";
|
|
553
|
+
}
|
|
554
|
+
get title() {
|
|
555
|
+
return this.integrationConfig.host;
|
|
556
|
+
}
|
|
557
|
+
get config() {
|
|
558
|
+
return this.integrationConfig;
|
|
559
|
+
}
|
|
560
|
+
resolveUrl(options) {
|
|
561
|
+
const resolved = defaultScmResolveUrl(options);
|
|
562
|
+
if (options.lineNumber) {
|
|
563
|
+
const url = new URL(resolved);
|
|
564
|
+
url.hash = `lines-${options.lineNumber}`;
|
|
565
|
+
return url.toString();
|
|
566
|
+
}
|
|
567
|
+
return resolved;
|
|
568
|
+
}
|
|
569
|
+
resolveEditUrl(url) {
|
|
570
|
+
const urlData = parseGitUrl(url);
|
|
571
|
+
const editUrl = new URL(url);
|
|
572
|
+
editUrl.searchParams.set("mode", "edit");
|
|
573
|
+
editUrl.searchParams.set("at", urlData.ref);
|
|
574
|
+
return editUrl.toString();
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
let BitbucketCloudIntegration = _BitbucketCloudIntegration;
|
|
578
|
+
BitbucketCloudIntegration.factory = ({
|
|
579
|
+
config
|
|
580
|
+
}) => {
|
|
581
|
+
var _a;
|
|
582
|
+
const configs = readBitbucketCloudIntegrationConfigs((_a = config.getOptionalConfigArray("integrations.bitbucketCloud")) != null ? _a : []);
|
|
583
|
+
return basicIntegrations(configs.map((c) => new _BitbucketCloudIntegration(c)), (i) => i.config.host);
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
async function getBitbucketCloudDefaultBranch(url, config) {
|
|
587
|
+
const { name: repoName, owner: project } = parseGitUrl(url);
|
|
588
|
+
const branchUrl = `${config.apiBaseUrl}/repositories/${project}/${repoName}`;
|
|
589
|
+
const response = await fetch(branchUrl, getBitbucketCloudRequestOptions(config));
|
|
590
|
+
if (!response.ok) {
|
|
591
|
+
const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;
|
|
592
|
+
throw new Error(message);
|
|
593
|
+
}
|
|
594
|
+
const repoInfo = await response.json();
|
|
595
|
+
const defaultBranch = repoInfo.mainbranch.name;
|
|
596
|
+
if (!defaultBranch) {
|
|
597
|
+
throw new Error(`Failed to read default branch from ${branchUrl}. Response ${response.status} ${response.json()}`);
|
|
598
|
+
}
|
|
599
|
+
return defaultBranch;
|
|
600
|
+
}
|
|
601
|
+
async function getBitbucketCloudDownloadUrl(url, config) {
|
|
602
|
+
const {
|
|
603
|
+
name: repoName,
|
|
604
|
+
owner: project,
|
|
605
|
+
ref,
|
|
606
|
+
protocol,
|
|
607
|
+
resource
|
|
608
|
+
} = parseGitUrl(url);
|
|
609
|
+
let branch = ref;
|
|
610
|
+
if (!branch) {
|
|
611
|
+
branch = await getBitbucketCloudDefaultBranch(url, config);
|
|
612
|
+
}
|
|
613
|
+
return `${protocol}://${resource}/${project}/${repoName}/get/${branch}.tar.gz`;
|
|
614
|
+
}
|
|
615
|
+
function getBitbucketCloudFileFetchUrl(url, config) {
|
|
616
|
+
try {
|
|
617
|
+
const { owner, name, ref, filepathtype, filepath } = parseGitUrl(url);
|
|
618
|
+
if (!owner || !name || filepathtype !== "src" && filepathtype !== "raw") {
|
|
619
|
+
throw new Error("Invalid Bitbucket Cloud URL or file path");
|
|
620
|
+
}
|
|
621
|
+
const pathWithoutSlash = filepath.replace(/^\//, "");
|
|
622
|
+
if (!ref) {
|
|
623
|
+
throw new Error("Invalid Bitbucket Cloud URL or file path");
|
|
624
|
+
}
|
|
625
|
+
return `${config.apiBaseUrl}/repositories/${owner}/${name}/src/${ref}/${pathWithoutSlash}`;
|
|
626
|
+
} catch (e) {
|
|
627
|
+
throw new Error(`Incorrect URL: ${url}, ${e}`);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
function getBitbucketCloudRequestOptions(config) {
|
|
631
|
+
const headers = {};
|
|
632
|
+
if (config.username && config.appPassword) {
|
|
633
|
+
const buffer = Buffer.from(`${config.username}:${config.appPassword}`, "utf8");
|
|
634
|
+
headers.Authorization = `Basic ${buffer.toString("base64")}`;
|
|
635
|
+
}
|
|
636
|
+
return {
|
|
637
|
+
headers
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
function readBitbucketServerIntegrationConfig(config) {
|
|
642
|
+
const host = config.getString("host");
|
|
643
|
+
let apiBaseUrl = config.getOptionalString("apiBaseUrl");
|
|
644
|
+
const token = config.getOptionalString("token");
|
|
645
|
+
if (!isValidHost(host)) {
|
|
646
|
+
throw new Error(`Invalid Bitbucket Server integration config, '${host}' is not a valid host`);
|
|
647
|
+
}
|
|
648
|
+
if (apiBaseUrl) {
|
|
649
|
+
apiBaseUrl = trimEnd(apiBaseUrl, "/");
|
|
650
|
+
} else {
|
|
651
|
+
apiBaseUrl = `https://${host}/rest/api/1.0`;
|
|
652
|
+
}
|
|
653
|
+
return {
|
|
654
|
+
host,
|
|
655
|
+
apiBaseUrl,
|
|
656
|
+
token
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
function readBitbucketServerIntegrationConfigs(configs) {
|
|
660
|
+
return configs.map(readBitbucketServerIntegrationConfig);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
const _BitbucketServerIntegration = class {
|
|
664
|
+
constructor(integrationConfig) {
|
|
665
|
+
this.integrationConfig = integrationConfig;
|
|
666
|
+
}
|
|
667
|
+
get type() {
|
|
668
|
+
return "bitbucketServer";
|
|
669
|
+
}
|
|
670
|
+
get title() {
|
|
671
|
+
return this.integrationConfig.host;
|
|
672
|
+
}
|
|
673
|
+
get config() {
|
|
674
|
+
return this.integrationConfig;
|
|
675
|
+
}
|
|
676
|
+
resolveUrl(options) {
|
|
677
|
+
const resolved = defaultScmResolveUrl(options);
|
|
678
|
+
if (options.lineNumber) {
|
|
679
|
+
const url = new URL(resolved);
|
|
680
|
+
const filename = url.pathname.split("/").slice(-1)[0];
|
|
681
|
+
url.hash = `${filename}-${options.lineNumber}`;
|
|
682
|
+
return url.toString();
|
|
683
|
+
}
|
|
684
|
+
return resolved;
|
|
685
|
+
}
|
|
686
|
+
resolveEditUrl(url) {
|
|
687
|
+
const urlData = parseGitUrl(url);
|
|
688
|
+
const editUrl = new URL(url);
|
|
689
|
+
editUrl.searchParams.set("mode", "edit");
|
|
690
|
+
editUrl.searchParams.set("spa", "0");
|
|
691
|
+
editUrl.searchParams.set("at", urlData.ref);
|
|
692
|
+
return editUrl.toString();
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
let BitbucketServerIntegration = _BitbucketServerIntegration;
|
|
696
|
+
BitbucketServerIntegration.factory = ({
|
|
697
|
+
config
|
|
698
|
+
}) => {
|
|
699
|
+
var _a;
|
|
700
|
+
const configs = readBitbucketServerIntegrationConfigs((_a = config.getOptionalConfigArray("integrations.bitbucketServer")) != null ? _a : []);
|
|
701
|
+
return basicIntegrations(configs.map((c) => new _BitbucketServerIntegration(c)), (i) => i.config.host);
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
async function getBitbucketServerDefaultBranch(url, config) {
|
|
705
|
+
const { name: repoName, owner: project } = parseGitUrl(url);
|
|
706
|
+
let branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/default-branch`;
|
|
707
|
+
let response = await fetch(branchUrl, getBitbucketServerRequestOptions(config));
|
|
708
|
+
if (response.status === 404) {
|
|
709
|
+
branchUrl = `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/branches/default`;
|
|
710
|
+
response = await fetch(branchUrl, getBitbucketServerRequestOptions(config));
|
|
711
|
+
}
|
|
712
|
+
if (!response.ok) {
|
|
713
|
+
const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`;
|
|
714
|
+
throw new Error(message);
|
|
715
|
+
}
|
|
716
|
+
const { displayId } = await response.json();
|
|
717
|
+
const defaultBranch = displayId;
|
|
718
|
+
if (!defaultBranch) {
|
|
719
|
+
throw new Error(`Failed to read default branch from ${branchUrl}. Response ${response.status} ${response.json()}`);
|
|
720
|
+
}
|
|
721
|
+
return defaultBranch;
|
|
722
|
+
}
|
|
723
|
+
async function getBitbucketServerDownloadUrl(url, config) {
|
|
724
|
+
const { name: repoName, owner: project, ref, filepath } = parseGitUrl(url);
|
|
725
|
+
let branch = ref;
|
|
726
|
+
if (!branch) {
|
|
727
|
+
branch = await getBitbucketServerDefaultBranch(url, config);
|
|
728
|
+
}
|
|
729
|
+
const path = filepath ? `&path=${encodeURIComponent(filepath)}` : "";
|
|
730
|
+
return `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=tgz&at=${branch}&prefix=${project}-${repoName}${path}`;
|
|
731
|
+
}
|
|
732
|
+
function getBitbucketServerFileFetchUrl(url, config) {
|
|
733
|
+
try {
|
|
734
|
+
const { owner, name, ref, filepathtype, filepath } = parseGitUrl(url);
|
|
735
|
+
if (!owner || !name || filepathtype !== "browse" && filepathtype !== "raw" && filepathtype !== "src") {
|
|
736
|
+
throw new Error("Invalid Bitbucket Server URL or file path");
|
|
737
|
+
}
|
|
738
|
+
const pathWithoutSlash = filepath.replace(/^\//, "");
|
|
739
|
+
return `${config.apiBaseUrl}/projects/${owner}/repos/${name}/raw/${pathWithoutSlash}?at=${ref}`;
|
|
740
|
+
} catch (e) {
|
|
741
|
+
throw new Error(`Incorrect URL: ${url}, ${e}`);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
function getBitbucketServerRequestOptions(config) {
|
|
745
|
+
const headers = {};
|
|
746
|
+
if (config.token) {
|
|
747
|
+
headers.Authorization = `Bearer ${config.token}`;
|
|
748
|
+
}
|
|
749
|
+
return {
|
|
750
|
+
headers
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
|
|
445
754
|
function readGerritIntegrationConfig(config) {
|
|
446
755
|
const host = config.getString("host");
|
|
447
756
|
let baseUrl = config.getOptionalString("baseUrl");
|
|
757
|
+
let cloneUrl = config.getOptionalString("cloneUrl");
|
|
448
758
|
let gitilesBaseUrl = config.getOptionalString("gitilesBaseUrl");
|
|
449
759
|
const username = config.getOptionalString("username");
|
|
450
760
|
const password = config.getOptionalString("password");
|
|
@@ -452,6 +762,8 @@ function readGerritIntegrationConfig(config) {
|
|
|
452
762
|
throw new Error(`Invalid Gerrit integration config, '${host}' is not a valid host`);
|
|
453
763
|
} else if (baseUrl && !isValidUrl(baseUrl)) {
|
|
454
764
|
throw new Error(`Invalid Gerrit integration config, '${baseUrl}' is not a valid baseUrl`);
|
|
765
|
+
} else if (cloneUrl && !isValidUrl(cloneUrl)) {
|
|
766
|
+
throw new Error(`Invalid Gerrit integration config, '${cloneUrl}' is not a valid cloneUrl`);
|
|
455
767
|
} else if (gitilesBaseUrl && !isValidUrl(gitilesBaseUrl)) {
|
|
456
768
|
throw new Error(`Invalid Gerrit integration config, '${gitilesBaseUrl}' is not a valid gitilesBaseUrl`);
|
|
457
769
|
}
|
|
@@ -465,9 +777,15 @@ function readGerritIntegrationConfig(config) {
|
|
|
465
777
|
} else {
|
|
466
778
|
gitilesBaseUrl = `https://${host}`;
|
|
467
779
|
}
|
|
780
|
+
if (cloneUrl) {
|
|
781
|
+
cloneUrl = trimEnd(cloneUrl, "/");
|
|
782
|
+
} else {
|
|
783
|
+
cloneUrl = baseUrl;
|
|
784
|
+
}
|
|
468
785
|
return {
|
|
469
786
|
host,
|
|
470
787
|
baseUrl,
|
|
788
|
+
cloneUrl,
|
|
471
789
|
gitilesBaseUrl,
|
|
472
790
|
username,
|
|
473
791
|
password
|
|
@@ -515,7 +833,7 @@ GerritIntegration.factory = ({ config }) => {
|
|
|
515
833
|
};
|
|
516
834
|
|
|
517
835
|
const GERRIT_BODY_PREFIX = ")]}'";
|
|
518
|
-
function
|
|
836
|
+
function parseGerritGitilesUrl(config, url) {
|
|
519
837
|
const urlPath = url.replace(config.gitilesBaseUrl, "");
|
|
520
838
|
const parts = urlPath.split("/").filter((p) => !!p);
|
|
521
839
|
const projectEndIndex = parts.indexOf("+");
|
|
@@ -538,10 +856,21 @@ function parseGitilesUrl(config, url) {
|
|
|
538
856
|
function getAuthenticationPrefix(config) {
|
|
539
857
|
return config.password ? "/a/" : "/";
|
|
540
858
|
}
|
|
859
|
+
function getGerritBranchApiUrl(config, url) {
|
|
860
|
+
const { branch, project } = parseGerritGitilesUrl(config, url);
|
|
861
|
+
return `${config.baseUrl}${getAuthenticationPrefix(config)}projects/${encodeURIComponent(project)}/branches/${branch}`;
|
|
862
|
+
}
|
|
863
|
+
function getGerritCloneRepoUrl(config, url) {
|
|
864
|
+
const { project } = parseGerritGitilesUrl(config, url);
|
|
865
|
+
return `${config.cloneUrl}${getAuthenticationPrefix(config)}${project}`;
|
|
866
|
+
}
|
|
541
867
|
function getGerritFileContentsApiUrl(config, url) {
|
|
542
|
-
const { branch, filePath, project } =
|
|
868
|
+
const { branch, filePath, project } = parseGerritGitilesUrl(config, url);
|
|
543
869
|
return `${config.baseUrl}${getAuthenticationPrefix(config)}projects/${encodeURIComponent(project)}/branches/${branch}/files/${encodeURIComponent(filePath)}/content`;
|
|
544
870
|
}
|
|
871
|
+
function getGerritProjectsApiUrl(config) {
|
|
872
|
+
return `${config.baseUrl}${getAuthenticationPrefix(config)}projects/`;
|
|
873
|
+
}
|
|
545
874
|
function getGerritRequestOptions(config) {
|
|
546
875
|
const headers = {};
|
|
547
876
|
if (!config.password) {
|
|
@@ -897,14 +1226,20 @@ function getGitLabRequestOptions(config) {
|
|
|
897
1226
|
function buildRawUrl(target) {
|
|
898
1227
|
try {
|
|
899
1228
|
const url = new URL(target);
|
|
900
|
-
const
|
|
901
|
-
|
|
902
|
-
|
|
1229
|
+
const splitPath = url.pathname.split("/").filter(Boolean);
|
|
1230
|
+
const blobIndex = splitPath.indexOf("blob", 2);
|
|
1231
|
+
if (blobIndex < 2 || blobIndex === splitPath.length - 1) {
|
|
1232
|
+
throw new InputError("Wrong GitLab URL");
|
|
1233
|
+
}
|
|
1234
|
+
const repoPath = splitPath.slice(0, blobIndex);
|
|
1235
|
+
const restOfPath = splitPath.slice(blobIndex + 1);
|
|
1236
|
+
if (!restOfPath.join("/").match(/\.(yaml|yml)$/)) {
|
|
1237
|
+
throw new InputError("Wrong GitLab URL");
|
|
903
1238
|
}
|
|
904
|
-
url.pathname = [
|
|
1239
|
+
url.pathname = [...repoPath, "raw", ...restOfPath].join("/");
|
|
905
1240
|
return url;
|
|
906
1241
|
} catch (e) {
|
|
907
|
-
throw new
|
|
1242
|
+
throw new InputError(`Incorrect url: ${target}, ${e}`);
|
|
908
1243
|
}
|
|
909
1244
|
}
|
|
910
1245
|
function buildProjectUrl(target, projectID) {
|
|
@@ -986,85 +1321,14 @@ function readGoogleGcsIntegrationConfig(config) {
|
|
|
986
1321
|
return { clientEmail, privateKey };
|
|
987
1322
|
}
|
|
988
1323
|
|
|
989
|
-
const AMAZON_AWS_HOST = "amazonaws.com";
|
|
990
|
-
function readAwsS3IntegrationConfig(config) {
|
|
991
|
-
var _a;
|
|
992
|
-
const endpoint = config.getOptionalString("endpoint");
|
|
993
|
-
const s3ForcePathStyle = (_a = config.getOptionalBoolean("s3ForcePathStyle")) != null ? _a : false;
|
|
994
|
-
let host;
|
|
995
|
-
let pathname;
|
|
996
|
-
if (endpoint) {
|
|
997
|
-
try {
|
|
998
|
-
const url = new URL(endpoint);
|
|
999
|
-
host = url.host;
|
|
1000
|
-
pathname = url.pathname;
|
|
1001
|
-
} catch {
|
|
1002
|
-
throw new Error(`invalid awsS3 integration config, endpoint '${endpoint}' is not a valid URL`);
|
|
1003
|
-
}
|
|
1004
|
-
if (pathname !== "/") {
|
|
1005
|
-
throw new Error(`invalid awsS3 integration config, endpoints cannot contain path, got '${endpoint}'`);
|
|
1006
|
-
}
|
|
1007
|
-
} else {
|
|
1008
|
-
host = AMAZON_AWS_HOST;
|
|
1009
|
-
}
|
|
1010
|
-
const accessKeyId = config.getOptionalString("accessKeyId");
|
|
1011
|
-
const secretAccessKey = config.getOptionalString("secretAccessKey");
|
|
1012
|
-
const roleArn = config.getOptionalString("roleArn");
|
|
1013
|
-
const externalId = config.getOptionalString("externalId");
|
|
1014
|
-
return {
|
|
1015
|
-
host,
|
|
1016
|
-
endpoint,
|
|
1017
|
-
s3ForcePathStyle,
|
|
1018
|
-
accessKeyId,
|
|
1019
|
-
secretAccessKey,
|
|
1020
|
-
roleArn,
|
|
1021
|
-
externalId
|
|
1022
|
-
};
|
|
1023
|
-
}
|
|
1024
|
-
function readAwsS3IntegrationConfigs(configs) {
|
|
1025
|
-
const result = configs.map(readAwsS3IntegrationConfig);
|
|
1026
|
-
if (!result.some((c) => c.host === AMAZON_AWS_HOST)) {
|
|
1027
|
-
result.push({
|
|
1028
|
-
host: AMAZON_AWS_HOST
|
|
1029
|
-
});
|
|
1030
|
-
}
|
|
1031
|
-
return result;
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
const _AwsS3Integration = class {
|
|
1035
|
-
constructor(integrationConfig) {
|
|
1036
|
-
this.integrationConfig = integrationConfig;
|
|
1037
|
-
}
|
|
1038
|
-
get type() {
|
|
1039
|
-
return "awsS3";
|
|
1040
|
-
}
|
|
1041
|
-
get title() {
|
|
1042
|
-
return this.integrationConfig.host;
|
|
1043
|
-
}
|
|
1044
|
-
get config() {
|
|
1045
|
-
return this.integrationConfig;
|
|
1046
|
-
}
|
|
1047
|
-
resolveUrl(options) {
|
|
1048
|
-
const resolved = defaultScmResolveUrl(options);
|
|
1049
|
-
return resolved;
|
|
1050
|
-
}
|
|
1051
|
-
resolveEditUrl(url) {
|
|
1052
|
-
return url;
|
|
1053
|
-
}
|
|
1054
|
-
};
|
|
1055
|
-
let AwsS3Integration = _AwsS3Integration;
|
|
1056
|
-
AwsS3Integration.factory = ({ config }) => {
|
|
1057
|
-
var _a;
|
|
1058
|
-
const configs = readAwsS3IntegrationConfigs((_a = config.getOptionalConfigArray("integrations.awsS3")) != null ? _a : []);
|
|
1059
|
-
return basicIntegrations(configs.map((c) => new _AwsS3Integration(c)), (i) => i.config.host);
|
|
1060
|
-
};
|
|
1061
|
-
|
|
1062
1324
|
class ScmIntegrations {
|
|
1063
1325
|
static fromConfig(config) {
|
|
1064
1326
|
return new ScmIntegrations({
|
|
1065
1327
|
awsS3: AwsS3Integration.factory({ config }),
|
|
1066
1328
|
azure: AzureIntegration.factory({ config }),
|
|
1067
1329
|
bitbucket: BitbucketIntegration.factory({ config }),
|
|
1330
|
+
bitbucketCloud: BitbucketCloudIntegration.factory({ config }),
|
|
1331
|
+
bitbucketServer: BitbucketServerIntegration.factory({ config }),
|
|
1068
1332
|
gerrit: GerritIntegration.factory({ config }),
|
|
1069
1333
|
github: GitHubIntegration.factory({ config }),
|
|
1070
1334
|
gitlab: GitLabIntegration.factory({ config })
|
|
@@ -1082,6 +1346,12 @@ class ScmIntegrations {
|
|
|
1082
1346
|
get bitbucket() {
|
|
1083
1347
|
return this.byType.bitbucket;
|
|
1084
1348
|
}
|
|
1349
|
+
get bitbucketCloud() {
|
|
1350
|
+
return this.byType.bitbucketCloud;
|
|
1351
|
+
}
|
|
1352
|
+
get bitbucketServer() {
|
|
1353
|
+
return this.byType.bitbucketServer;
|
|
1354
|
+
}
|
|
1085
1355
|
get gerrit() {
|
|
1086
1356
|
return this.byType.gerrit;
|
|
1087
1357
|
}
|
|
@@ -1116,5 +1386,5 @@ class ScmIntegrations {
|
|
|
1116
1386
|
}
|
|
1117
1387
|
}
|
|
1118
1388
|
|
|
1119
|
-
export { AwsS3Integration, AzureIntegration, BitbucketIntegration, DefaultGithubCredentialsProvider, GerritIntegration, GitHubIntegration, GitLabIntegration, GithubAppCredentialsMux, ScmIntegrations, SingleInstanceGithubCredentialsProvider, defaultScmResolveUrl, getAzureCommitsUrl, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGerritFileContentsApiUrl, getGerritRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, parseGerritJsonResponse, readAwsS3IntegrationConfig, readAwsS3IntegrationConfigs, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGerritIntegrationConfig, readGerritIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs, readGoogleGcsIntegrationConfig, replaceGitHubUrlType, replaceGitLabUrlType };
|
|
1389
|
+
export { AwsS3Integration, AzureIntegration, BitbucketCloudIntegration, BitbucketIntegration, BitbucketServerIntegration, DefaultGithubCredentialsProvider, GerritIntegration, GitHubIntegration, GitLabIntegration, GithubAppCredentialsMux, ScmIntegrations, SingleInstanceGithubCredentialsProvider, defaultScmResolveUrl, getAzureCommitsUrl, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketCloudDefaultBranch, getBitbucketCloudDownloadUrl, getBitbucketCloudFileFetchUrl, getBitbucketCloudRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getBitbucketServerDefaultBranch, getBitbucketServerDownloadUrl, getBitbucketServerFileFetchUrl, getBitbucketServerRequestOptions, getGerritBranchApiUrl, getGerritCloneRepoUrl, getGerritFileContentsApiUrl, getGerritProjectsApiUrl, getGerritRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, parseGerritGitilesUrl, parseGerritJsonResponse, readAwsS3IntegrationConfig, readAwsS3IntegrationConfigs, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketCloudIntegrationConfig, readBitbucketCloudIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readBitbucketServerIntegrationConfig, readBitbucketServerIntegrationConfigs, readGerritIntegrationConfig, readGerritIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs, readGoogleGcsIntegrationConfig, replaceGitHubUrlType, replaceGitLabUrlType };
|
|
1120
1390
|
//# sourceMappingURL=index.esm.js.map
|