@backstage/integration 0.7.4 → 1.0.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 +29 -1
- package/config.d.ts +25 -0
- package/dist/index.cjs.js +83 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +71 -6
- package/dist/index.esm.js +81 -11
- package/dist/index.esm.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -195,12 +195,10 @@ declare type BitbucketIntegrationConfig = {
|
|
|
195
195
|
* The base URL of the API of this provider, e.g. "https://api.bitbucket.org/2.0",
|
|
196
196
|
* with no trailing slash.
|
|
197
197
|
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* The API will always be preferred if both its base URL and a token are
|
|
201
|
-
* present.
|
|
198
|
+
* Values omitted at the optional property at the app-config will be deduced
|
|
199
|
+
* from the "host" value.
|
|
202
200
|
*/
|
|
203
|
-
apiBaseUrl
|
|
201
|
+
apiBaseUrl: string;
|
|
204
202
|
/**
|
|
205
203
|
* The authorization token to use for requests to a Bitbucket Server provider.
|
|
206
204
|
*
|
|
@@ -298,6 +296,70 @@ declare function getBitbucketRequestOptions(config: BitbucketIntegrationConfig):
|
|
|
298
296
|
headers: Record<string, string>;
|
|
299
297
|
};
|
|
300
298
|
|
|
299
|
+
/**
|
|
300
|
+
* The configuration parameters for a single Gerrit API provider.
|
|
301
|
+
*
|
|
302
|
+
* @public
|
|
303
|
+
*/
|
|
304
|
+
declare type GerritIntegrationConfig = {
|
|
305
|
+
/**
|
|
306
|
+
* The host of the target that this matches on, e.g. "gerrit-review.com"
|
|
307
|
+
*/
|
|
308
|
+
host: string;
|
|
309
|
+
/**
|
|
310
|
+
* The optional base URL of the Gerrit instance. It is assumed that https
|
|
311
|
+
* is used and that the base path is "/" on the host. If that is not the
|
|
312
|
+
* case set the complete base url to the gerrit instance, e.g.
|
|
313
|
+
* "https://gerrit-review.com/gerrit". This is the url that you would open
|
|
314
|
+
* in a browser.
|
|
315
|
+
*/
|
|
316
|
+
baseUrl?: string;
|
|
317
|
+
/**
|
|
318
|
+
* The username to use for requests to gerrit.
|
|
319
|
+
*/
|
|
320
|
+
username?: string;
|
|
321
|
+
/**
|
|
322
|
+
* The password or http token to use for authentication.
|
|
323
|
+
*/
|
|
324
|
+
password?: string;
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Reads a single Gerrit integration config.
|
|
328
|
+
*
|
|
329
|
+
* @param config - The config object of a single integration
|
|
330
|
+
*
|
|
331
|
+
* @public
|
|
332
|
+
*/
|
|
333
|
+
declare function readGerritIntegrationConfig(config: Config): GerritIntegrationConfig;
|
|
334
|
+
/**
|
|
335
|
+
* Reads a set of Gerrit integration configs.
|
|
336
|
+
*
|
|
337
|
+
* @param configs - All of the integration config objects
|
|
338
|
+
*
|
|
339
|
+
* @public
|
|
340
|
+
*/
|
|
341
|
+
declare function readGerritIntegrationConfigs(configs: Config[]): GerritIntegrationConfig[];
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* A Gerrit based integration.
|
|
345
|
+
*
|
|
346
|
+
* @public
|
|
347
|
+
*/
|
|
348
|
+
declare class GerritIntegration implements ScmIntegration {
|
|
349
|
+
private readonly integrationConfig;
|
|
350
|
+
static factory: ScmIntegrationsFactory<GerritIntegration>;
|
|
351
|
+
constructor(integrationConfig: GerritIntegrationConfig);
|
|
352
|
+
get type(): string;
|
|
353
|
+
get title(): string;
|
|
354
|
+
get config(): GerritIntegrationConfig;
|
|
355
|
+
resolveUrl(options: {
|
|
356
|
+
url: string;
|
|
357
|
+
base: string;
|
|
358
|
+
lineNumber?: number;
|
|
359
|
+
}): string;
|
|
360
|
+
resolveEditUrl(url: string): string;
|
|
361
|
+
}
|
|
362
|
+
|
|
301
363
|
/**
|
|
302
364
|
* The configuration parameters for a single GitHub integration.
|
|
303
365
|
*
|
|
@@ -631,6 +693,7 @@ interface ScmIntegrationRegistry extends ScmIntegrationsGroup<ScmIntegration> {
|
|
|
631
693
|
awsS3: ScmIntegrationsGroup<AwsS3Integration>;
|
|
632
694
|
azure: ScmIntegrationsGroup<AzureIntegration>;
|
|
633
695
|
bitbucket: ScmIntegrationsGroup<BitbucketIntegration>;
|
|
696
|
+
gerrit: ScmIntegrationsGroup<GerritIntegration>;
|
|
634
697
|
github: ScmIntegrationsGroup<GitHubIntegration>;
|
|
635
698
|
gitlab: ScmIntegrationsGroup<GitLabIntegration>;
|
|
636
699
|
/**
|
|
@@ -835,6 +898,7 @@ interface IntegrationsByType {
|
|
|
835
898
|
awsS3: ScmIntegrationsGroup<AwsS3Integration>;
|
|
836
899
|
azure: ScmIntegrationsGroup<AzureIntegration>;
|
|
837
900
|
bitbucket: ScmIntegrationsGroup<BitbucketIntegration>;
|
|
901
|
+
gerrit: ScmIntegrationsGroup<GerritIntegration>;
|
|
838
902
|
github: ScmIntegrationsGroup<GitHubIntegration>;
|
|
839
903
|
gitlab: ScmIntegrationsGroup<GitLabIntegration>;
|
|
840
904
|
}
|
|
@@ -850,6 +914,7 @@ declare class ScmIntegrations implements ScmIntegrationRegistry {
|
|
|
850
914
|
get awsS3(): ScmIntegrationsGroup<AwsS3Integration>;
|
|
851
915
|
get azure(): ScmIntegrationsGroup<AzureIntegration>;
|
|
852
916
|
get bitbucket(): ScmIntegrationsGroup<BitbucketIntegration>;
|
|
917
|
+
get gerrit(): ScmIntegrationsGroup<GerritIntegration>;
|
|
853
918
|
get github(): ScmIntegrationsGroup<GitHubIntegration>;
|
|
854
919
|
get gitlab(): ScmIntegrationsGroup<GitLabIntegration>;
|
|
855
920
|
list(): ScmIntegration[];
|
|
@@ -863,4 +928,4 @@ declare class ScmIntegrations implements ScmIntegrationRegistry {
|
|
|
863
928
|
resolveEditUrl(url: string): string;
|
|
864
929
|
}
|
|
865
930
|
|
|
866
|
-
export { AwsS3Integration, AwsS3IntegrationConfig, AzureIntegration, AzureIntegrationConfig, BitbucketIntegration, BitbucketIntegrationConfig, DefaultGithubCredentialsProvider, GitHubIntegration, GitHubIntegrationConfig, GitLabIntegration, GitLabIntegrationConfig, GithubAppConfig, GithubAppCredentialsMux, GithubCredentialType, GithubCredentials, GithubCredentialsProvider, GoogleGcsIntegrationConfig, IntegrationsByType, ScmIntegration, ScmIntegrationRegistry, ScmIntegrations, ScmIntegrationsFactory, ScmIntegrationsGroup, SingleInstanceGithubCredentialsProvider, defaultScmResolveUrl, getAzureCommitsUrl, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAwsS3IntegrationConfig, readAwsS3IntegrationConfigs, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs, readGoogleGcsIntegrationConfig, replaceGitHubUrlType };
|
|
931
|
+
export { AwsS3Integration, AwsS3IntegrationConfig, AzureIntegration, AzureIntegrationConfig, BitbucketIntegration, BitbucketIntegrationConfig, DefaultGithubCredentialsProvider, GerritIntegration, GerritIntegrationConfig, GitHubIntegration, GitHubIntegrationConfig, GitLabIntegration, GitLabIntegrationConfig, GithubAppConfig, GithubAppCredentialsMux, GithubCredentialType, GithubCredentials, GithubCredentialsProvider, GoogleGcsIntegrationConfig, IntegrationsByType, ScmIntegration, ScmIntegrationRegistry, ScmIntegrations, ScmIntegrationsFactory, ScmIntegrationsGroup, SingleInstanceGithubCredentialsProvider, defaultScmResolveUrl, getAzureCommitsUrl, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAwsS3IntegrationConfig, readAwsS3IntegrationConfigs, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGerritIntegrationConfig, readGerritIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs, readGoogleGcsIntegrationConfig, replaceGitHubUrlType };
|
package/dist/index.esm.js
CHANGED
|
@@ -301,6 +301,8 @@ function readBitbucketIntegrationConfig(config) {
|
|
|
301
301
|
apiBaseUrl = trimEnd(apiBaseUrl, "/");
|
|
302
302
|
} else if (host === BITBUCKET_HOST) {
|
|
303
303
|
apiBaseUrl = BITBUCKET_API_BASE_URL;
|
|
304
|
+
} else {
|
|
305
|
+
apiBaseUrl = `https://${host}/rest/api/1.0`;
|
|
304
306
|
}
|
|
305
307
|
return {
|
|
306
308
|
host,
|
|
@@ -336,13 +338,16 @@ const _BitbucketIntegration = class {
|
|
|
336
338
|
}
|
|
337
339
|
resolveUrl(options) {
|
|
338
340
|
const resolved = defaultScmResolveUrl(options);
|
|
339
|
-
if (options.lineNumber) {
|
|
340
|
-
|
|
341
|
-
const filename = url.pathname.split("/").slice(-1)[0];
|
|
342
|
-
url.hash = `${filename}-${options.lineNumber}`;
|
|
343
|
-
return url.toString();
|
|
341
|
+
if (!options.lineNumber) {
|
|
342
|
+
return resolved;
|
|
344
343
|
}
|
|
345
|
-
|
|
344
|
+
const url = new URL(resolved);
|
|
345
|
+
if (this.integrationConfig.host === "bitbucket.org") {
|
|
346
|
+
url.hash = `lines-${options.lineNumber}`;
|
|
347
|
+
} else {
|
|
348
|
+
url.hash = `${options.lineNumber}`;
|
|
349
|
+
}
|
|
350
|
+
return url.toString();
|
|
346
351
|
}
|
|
347
352
|
resolveEditUrl(url) {
|
|
348
353
|
const urlData = parseGitUrl(url);
|
|
@@ -437,6 +442,69 @@ function getBitbucketRequestOptions(config) {
|
|
|
437
442
|
};
|
|
438
443
|
}
|
|
439
444
|
|
|
445
|
+
function readGerritIntegrationConfig(config) {
|
|
446
|
+
const host = config.getString("host");
|
|
447
|
+
let baseUrl = config.getOptionalString("baseUrl");
|
|
448
|
+
const username = config.getOptionalString("username");
|
|
449
|
+
const password = config.getOptionalString("password");
|
|
450
|
+
if (!isValidHost(host)) {
|
|
451
|
+
throw new Error(`Invalid Gerrit integration config, '${host}' is not a valid host`);
|
|
452
|
+
} else if (baseUrl && !isValidUrl(baseUrl)) {
|
|
453
|
+
throw new Error(`Invalid Gerrit integration config, '${baseUrl}' is not a valid baseUrl`);
|
|
454
|
+
}
|
|
455
|
+
if (baseUrl) {
|
|
456
|
+
baseUrl = trimEnd(baseUrl, "/");
|
|
457
|
+
} else {
|
|
458
|
+
baseUrl = `https://${host}`;
|
|
459
|
+
}
|
|
460
|
+
return {
|
|
461
|
+
host,
|
|
462
|
+
baseUrl,
|
|
463
|
+
username,
|
|
464
|
+
password
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
function readGerritIntegrationConfigs(configs) {
|
|
468
|
+
return configs.map(readGerritIntegrationConfig);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const _GerritIntegration = class {
|
|
472
|
+
constructor(integrationConfig) {
|
|
473
|
+
this.integrationConfig = integrationConfig;
|
|
474
|
+
}
|
|
475
|
+
get type() {
|
|
476
|
+
return "gerrit";
|
|
477
|
+
}
|
|
478
|
+
get title() {
|
|
479
|
+
return this.integrationConfig.host;
|
|
480
|
+
}
|
|
481
|
+
get config() {
|
|
482
|
+
return this.integrationConfig;
|
|
483
|
+
}
|
|
484
|
+
resolveUrl(options) {
|
|
485
|
+
const { url, base, lineNumber } = options;
|
|
486
|
+
let updated;
|
|
487
|
+
if (url) {
|
|
488
|
+
updated = new URL(url, base);
|
|
489
|
+
} else {
|
|
490
|
+
updated = new URL(base);
|
|
491
|
+
}
|
|
492
|
+
if (lineNumber) {
|
|
493
|
+
updated.hash = lineNumber.toString();
|
|
494
|
+
}
|
|
495
|
+
return updated.toString();
|
|
496
|
+
}
|
|
497
|
+
resolveEditUrl(url) {
|
|
498
|
+
return url;
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
let GerritIntegration = _GerritIntegration;
|
|
502
|
+
GerritIntegration.factory = ({ config }) => {
|
|
503
|
+
var _a;
|
|
504
|
+
const configs = readGerritIntegrationConfigs((_a = config.getOptionalConfigArray("integrations.gerrit")) != null ? _a : []);
|
|
505
|
+
return basicIntegrations(configs.map((c) => new _GerritIntegration(c)), (i) => i.config.host);
|
|
506
|
+
};
|
|
507
|
+
|
|
440
508
|
const GITHUB_HOST = "github.com";
|
|
441
509
|
const GITHUB_API_BASE_URL = "https://api.github.com";
|
|
442
510
|
const GITHUB_RAW_BASE_URL = "https://raw.githubusercontent.com";
|
|
@@ -730,9 +798,7 @@ function readGitLabIntegrationConfig(config) {
|
|
|
730
798
|
} else {
|
|
731
799
|
baseUrl = `https://${host}`;
|
|
732
800
|
}
|
|
733
|
-
if (host
|
|
734
|
-
throw new Error(`Invalid GitLab integration config, host '${host}' should just be the host name (e.g. "github.com"), not a URL`);
|
|
735
|
-
} else if (!isValidHost(host)) {
|
|
801
|
+
if (!isValidHost(host)) {
|
|
736
802
|
throw new Error(`Invalid GitLab integration config, '${host}' is not a valid host`);
|
|
737
803
|
} else if (!apiBaseUrl || !isValidUrl(apiBaseUrl)) {
|
|
738
804
|
throw new Error(`Invalid GitLab integration config, '${apiBaseUrl}' is not a valid apiBaseUrl`);
|
|
@@ -806,7 +872,7 @@ async function getProjectId(target, config) {
|
|
|
806
872
|
}
|
|
807
873
|
try {
|
|
808
874
|
const repo = url.pathname.split("/-/blob/")[0];
|
|
809
|
-
const repoIDLookup = new URL(`${url.
|
|
875
|
+
const repoIDLookup = new URL(`${url.origin}/api/v4/projects/${encodeURIComponent(repo.replace(/^\//, ""))}`);
|
|
810
876
|
const response = await fetch(repoIDLookup.toString(), getGitLabRequestOptions(config));
|
|
811
877
|
const data = await response.json();
|
|
812
878
|
if (!response.ok) {
|
|
@@ -937,6 +1003,7 @@ class ScmIntegrations {
|
|
|
937
1003
|
awsS3: AwsS3Integration.factory({ config }),
|
|
938
1004
|
azure: AzureIntegration.factory({ config }),
|
|
939
1005
|
bitbucket: BitbucketIntegration.factory({ config }),
|
|
1006
|
+
gerrit: GerritIntegration.factory({ config }),
|
|
940
1007
|
github: GitHubIntegration.factory({ config }),
|
|
941
1008
|
gitlab: GitLabIntegration.factory({ config })
|
|
942
1009
|
});
|
|
@@ -953,6 +1020,9 @@ class ScmIntegrations {
|
|
|
953
1020
|
get bitbucket() {
|
|
954
1021
|
return this.byType.bitbucket;
|
|
955
1022
|
}
|
|
1023
|
+
get gerrit() {
|
|
1024
|
+
return this.byType.gerrit;
|
|
1025
|
+
}
|
|
956
1026
|
get github() {
|
|
957
1027
|
return this.byType.github;
|
|
958
1028
|
}
|
|
@@ -984,5 +1054,5 @@ class ScmIntegrations {
|
|
|
984
1054
|
}
|
|
985
1055
|
}
|
|
986
1056
|
|
|
987
|
-
export { AwsS3Integration, AzureIntegration, BitbucketIntegration, DefaultGithubCredentialsProvider, GitHubIntegration, GitLabIntegration, GithubAppCredentialsMux, ScmIntegrations, SingleInstanceGithubCredentialsProvider, defaultScmResolveUrl, getAzureCommitsUrl, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAwsS3IntegrationConfig, readAwsS3IntegrationConfigs, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs, readGoogleGcsIntegrationConfig, replaceGitHubUrlType };
|
|
1057
|
+
export { AwsS3Integration, AzureIntegration, BitbucketIntegration, DefaultGithubCredentialsProvider, GerritIntegration, GitHubIntegration, GitLabIntegration, GithubAppCredentialsMux, ScmIntegrations, SingleInstanceGithubCredentialsProvider, defaultScmResolveUrl, getAzureCommitsUrl, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAwsS3IntegrationConfig, readAwsS3IntegrationConfigs, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGerritIntegrationConfig, readGerritIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs, readGoogleGcsIntegrationConfig, replaceGitHubUrlType };
|
|
988
1058
|
//# sourceMappingURL=index.esm.js.map
|