@backstage/integration 1.3.2-next.2 → 1.4.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/config.d.ts +26 -5
- package/dist/index.cjs.js +134 -16
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +132 -16
- package/dist/index.esm.js +126 -17
- package/dist/index.esm.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# @backstage/integration
|
|
2
2
|
|
|
3
|
+
## 1.4.0-next.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d05e1841ce: This patch brings Gitea as a valid integration: target, via the ScmIntegration interface. It adds gitea to the relevant static properties (get integration by name, get integration by type) for plugins to be able to reference the same Gitea server.
|
|
8
|
+
- c1784a4980: Replaces in-code uses of `GitHub` with `Github` and deprecates old versions.
|
|
9
|
+
|
|
10
|
+
Deprecates:
|
|
11
|
+
|
|
12
|
+
- `getGitHubFileFetchUrl` replaced by `getGithubFileFetchUrl`
|
|
13
|
+
- `GitHubIntegrationConfig` replaced by `GithubIntegrationConfig`
|
|
14
|
+
- `GitHubIntegration` replaced by `GithubIntegration`
|
|
15
|
+
- `readGitHubIntegrationConfig` replaced by `readGithubIntegrationConfig`
|
|
16
|
+
- `readGitHubIntegrationConfigs` replaced by `readGithubIntegrationConfigs`
|
|
17
|
+
- `replaceGitHubUrlType` replaced by `replaceGithubUrlType`
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 7573b65232: Internal refactor of imports to avoid circular dependencies
|
|
22
|
+
- a6d779d58a: Remove explicit default visibility at `config.d.ts` files.
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
/**
|
|
26
|
+
* @visibility backend
|
|
27
|
+
*/
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
- Updated dependencies
|
|
31
|
+
- @backstage/config@1.0.4-next.0
|
|
32
|
+
- @backstage/errors@1.1.3-next.0
|
|
33
|
+
|
|
34
|
+
## 1.3.2
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- Updated dependencies
|
|
39
|
+
- @backstage/config@1.0.3
|
|
40
|
+
- @backstage/errors@1.1.2
|
|
41
|
+
|
|
3
42
|
## 1.3.2-next.2
|
|
4
43
|
|
|
5
44
|
### Patch Changes
|
package/config.d.ts
CHANGED
|
@@ -164,7 +164,6 @@ export interface Config {
|
|
|
164
164
|
|
|
165
165
|
/**
|
|
166
166
|
* GitHub Apps configuration
|
|
167
|
-
* @visibility backend
|
|
168
167
|
*/
|
|
169
168
|
apps?: Array<{
|
|
170
169
|
/**
|
|
@@ -233,7 +232,6 @@ export interface Config {
|
|
|
233
232
|
googleGcs?: {
|
|
234
233
|
/**
|
|
235
234
|
* Service account email used to authenticate requests.
|
|
236
|
-
* @visibility backend
|
|
237
235
|
*/
|
|
238
236
|
clientEmail?: string;
|
|
239
237
|
/**
|
|
@@ -265,7 +263,6 @@ export interface Config {
|
|
|
265
263
|
|
|
266
264
|
/**
|
|
267
265
|
* Account access key used to authenticate requests.
|
|
268
|
-
* @visibility backend
|
|
269
266
|
*/
|
|
270
267
|
accessKeyId?: string;
|
|
271
268
|
/**
|
|
@@ -276,15 +273,39 @@ export interface Config {
|
|
|
276
273
|
|
|
277
274
|
/**
|
|
278
275
|
* ARN of the role to be assumed
|
|
279
|
-
* @visibility backend
|
|
280
276
|
*/
|
|
281
277
|
roleArn?: string;
|
|
282
278
|
|
|
283
279
|
/**
|
|
284
280
|
* External ID to use when assuming role
|
|
285
|
-
* @visibility backend
|
|
286
281
|
*/
|
|
287
282
|
externalId?: string;
|
|
288
283
|
}>;
|
|
284
|
+
|
|
285
|
+
/** Integration configuration for Gitea */
|
|
286
|
+
gitea?: Array<{
|
|
287
|
+
/**
|
|
288
|
+
* The hostname of the given Gitea instance
|
|
289
|
+
* @visibility frontend
|
|
290
|
+
*/
|
|
291
|
+
host: string;
|
|
292
|
+
/**
|
|
293
|
+
* The base url for the Gitea instance.
|
|
294
|
+
* @visibility frontend
|
|
295
|
+
*/
|
|
296
|
+
baseUrl?: string;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* The username to use for authenticated requests.
|
|
300
|
+
* @visibility secret
|
|
301
|
+
*/
|
|
302
|
+
username?: string;
|
|
303
|
+
/**
|
|
304
|
+
* Gitea password used to authenticate requests. This can be either a password
|
|
305
|
+
* or a generated access token.
|
|
306
|
+
* @visibility secret
|
|
307
|
+
*/
|
|
308
|
+
password?: string;
|
|
309
|
+
}>;
|
|
289
310
|
};
|
|
290
311
|
}
|
package/dist/index.cjs.js
CHANGED
|
@@ -898,7 +898,7 @@ function parseGerritGitilesUrl(config, url) {
|
|
|
898
898
|
project
|
|
899
899
|
};
|
|
900
900
|
}
|
|
901
|
-
function
|
|
901
|
+
function buildGerritGitilesUrl(config, project, branch, filePath) {
|
|
902
902
|
return `${config.gitilesBaseUrl}/${project}/+/refs/heads/${branch}/${lodash.trimStart(filePath, "/")}`;
|
|
903
903
|
}
|
|
904
904
|
function getAuthenticationPrefix(config) {
|
|
@@ -970,7 +970,7 @@ const _GerritIntegration = class {
|
|
|
970
970
|
let updated;
|
|
971
971
|
if (url.startsWith("/")) {
|
|
972
972
|
const { branch, project } = parseGerritGitilesUrl(this.config, base);
|
|
973
|
-
return
|
|
973
|
+
return buildGerritGitilesUrl(this.config, project, branch, url);
|
|
974
974
|
}
|
|
975
975
|
if (url) {
|
|
976
976
|
updated = new URL(url, base);
|
|
@@ -998,10 +998,101 @@ GerritIntegration.factory = ({ config }) => {
|
|
|
998
998
|
);
|
|
999
999
|
};
|
|
1000
1000
|
|
|
1001
|
+
function readGiteaConfig(config) {
|
|
1002
|
+
const host = config.getString("host");
|
|
1003
|
+
let baseUrl = config.getOptionalString("baseUrl");
|
|
1004
|
+
const username = config.getOptionalString("username");
|
|
1005
|
+
const password = config.getOptionalString("password");
|
|
1006
|
+
if (!isValidHost(host)) {
|
|
1007
|
+
throw new Error(
|
|
1008
|
+
`Invalid Gitea integration config, '${host}' is not a valid host`
|
|
1009
|
+
);
|
|
1010
|
+
}
|
|
1011
|
+
if (baseUrl) {
|
|
1012
|
+
baseUrl = lodash.trimEnd(baseUrl, "/");
|
|
1013
|
+
} else {
|
|
1014
|
+
baseUrl = `https://${host}`;
|
|
1015
|
+
}
|
|
1016
|
+
return {
|
|
1017
|
+
host,
|
|
1018
|
+
baseUrl,
|
|
1019
|
+
username,
|
|
1020
|
+
password
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
function getGiteaEditContentsUrl(config, url) {
|
|
1025
|
+
var _a;
|
|
1026
|
+
try {
|
|
1027
|
+
const baseUrl = (_a = config.baseUrl) != null ? _a : `https://${config.host}`;
|
|
1028
|
+
const [_blank, owner, name, _src, _branch, ref, ...path] = url.replace(baseUrl, "").split("/");
|
|
1029
|
+
const pathWithoutSlash = path.join("/").replace(/^\//, "");
|
|
1030
|
+
return `${baseUrl}/${owner}/${name}/_edit/${ref}/${pathWithoutSlash}`;
|
|
1031
|
+
} catch (e) {
|
|
1032
|
+
throw new Error(`Incorrect URL: ${url}, ${e}`);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
function getGiteaFileContentsUrl(config, url) {
|
|
1036
|
+
var _a;
|
|
1037
|
+
try {
|
|
1038
|
+
const baseUrl = (_a = config.baseUrl) != null ? _a : `https://${config.host}`;
|
|
1039
|
+
const [_blank, owner, name, _src, _branch, ref, ...path] = url.replace(baseUrl, "").split("/");
|
|
1040
|
+
const pathWithoutSlash = path.join("/").replace(/^\//, "");
|
|
1041
|
+
return `${baseUrl}/api/v1/repos/${owner}/${name}/contents/${pathWithoutSlash}?ref=${ref}`;
|
|
1042
|
+
} catch (e) {
|
|
1043
|
+
throw new Error(`Incorrect URL: ${url}, ${e}`);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
function getGiteaRequestOptions(config) {
|
|
1047
|
+
const headers = {};
|
|
1048
|
+
const { username, password } = config;
|
|
1049
|
+
if (!password) {
|
|
1050
|
+
return headers;
|
|
1051
|
+
}
|
|
1052
|
+
if (username) {
|
|
1053
|
+
headers.Authorization = `basic ${Buffer.from(
|
|
1054
|
+
`${username}:${password}`
|
|
1055
|
+
).toString("base64")}`;
|
|
1056
|
+
} else {
|
|
1057
|
+
headers.Authorization = `token ${password}`;
|
|
1058
|
+
}
|
|
1059
|
+
return {
|
|
1060
|
+
headers
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
const _GiteaIntegration = class {
|
|
1065
|
+
constructor(config) {
|
|
1066
|
+
this.config = config;
|
|
1067
|
+
}
|
|
1068
|
+
get type() {
|
|
1069
|
+
return "gitea";
|
|
1070
|
+
}
|
|
1071
|
+
get title() {
|
|
1072
|
+
return this.config.host;
|
|
1073
|
+
}
|
|
1074
|
+
resolveUrl(options) {
|
|
1075
|
+
return defaultScmResolveUrl(options);
|
|
1076
|
+
}
|
|
1077
|
+
resolveEditUrl(url) {
|
|
1078
|
+
return getGiteaEditContentsUrl(this.config, url);
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
let GiteaIntegration = _GiteaIntegration;
|
|
1082
|
+
GiteaIntegration.factory = ({ config }) => {
|
|
1083
|
+
var _a;
|
|
1084
|
+
const configs = (_a = config.getOptionalConfigArray("integrations.gitea")) != null ? _a : [];
|
|
1085
|
+
const giteaConfigs = configs.map((c) => readGiteaConfig(c));
|
|
1086
|
+
return basicIntegrations(
|
|
1087
|
+
giteaConfigs.map((c) => new _GiteaIntegration(c)),
|
|
1088
|
+
(gitea) => gitea.config.host
|
|
1089
|
+
);
|
|
1090
|
+
};
|
|
1091
|
+
|
|
1001
1092
|
const GITHUB_HOST = "github.com";
|
|
1002
1093
|
const GITHUB_API_BASE_URL = "https://api.github.com";
|
|
1003
1094
|
const GITHUB_RAW_BASE_URL = "https://raw.githubusercontent.com";
|
|
1004
|
-
function
|
|
1095
|
+
function readGithubIntegrationConfig(config) {
|
|
1005
1096
|
var _a, _b;
|
|
1006
1097
|
const host = (_a = config.getOptionalString("host")) != null ? _a : GITHUB_HOST;
|
|
1007
1098
|
let apiBaseUrl = config.getOptionalString("apiBaseUrl");
|
|
@@ -1034,8 +1125,8 @@ function readGitHubIntegrationConfig(config) {
|
|
|
1034
1125
|
}
|
|
1035
1126
|
return { host, apiBaseUrl, rawBaseUrl, token, apps };
|
|
1036
1127
|
}
|
|
1037
|
-
function
|
|
1038
|
-
const result = configs.map(
|
|
1128
|
+
function readGithubIntegrationConfigs(configs) {
|
|
1129
|
+
const result = configs.map(readGithubIntegrationConfig);
|
|
1039
1130
|
if (!result.some((c) => c.host === GITHUB_HOST)) {
|
|
1040
1131
|
result.push({
|
|
1041
1132
|
host: GITHUB_HOST,
|
|
@@ -1046,7 +1137,7 @@ function readGitHubIntegrationConfigs(configs) {
|
|
|
1046
1137
|
return result;
|
|
1047
1138
|
}
|
|
1048
1139
|
|
|
1049
|
-
function
|
|
1140
|
+
function getGithubFileFetchUrl(url, config, credentials) {
|
|
1050
1141
|
try {
|
|
1051
1142
|
const { owner, name, ref, filepathtype, filepath } = parseGitUrl__default["default"](url);
|
|
1052
1143
|
if (!owner || !name || !ref || filepathtype !== "blob" && filepathtype !== "raw" && filepathtype !== "tree") {
|
|
@@ -1280,7 +1371,7 @@ class DefaultGithubCredentialsProvider {
|
|
|
1280
1371
|
}
|
|
1281
1372
|
}
|
|
1282
1373
|
|
|
1283
|
-
const
|
|
1374
|
+
const _GithubIntegration = class {
|
|
1284
1375
|
constructor(integrationConfig) {
|
|
1285
1376
|
this.integrationConfig = integrationConfig;
|
|
1286
1377
|
}
|
|
@@ -1294,24 +1385,24 @@ const _GitHubIntegration = class {
|
|
|
1294
1385
|
return this.integrationConfig;
|
|
1295
1386
|
}
|
|
1296
1387
|
resolveUrl(options) {
|
|
1297
|
-
return
|
|
1388
|
+
return replaceGithubUrlType(defaultScmResolveUrl(options), "tree");
|
|
1298
1389
|
}
|
|
1299
1390
|
resolveEditUrl(url) {
|
|
1300
|
-
return
|
|
1391
|
+
return replaceGithubUrlType(url, "edit");
|
|
1301
1392
|
}
|
|
1302
1393
|
};
|
|
1303
|
-
let
|
|
1304
|
-
|
|
1394
|
+
let GithubIntegration = _GithubIntegration;
|
|
1395
|
+
GithubIntegration.factory = ({ config }) => {
|
|
1305
1396
|
var _a;
|
|
1306
|
-
const configs =
|
|
1397
|
+
const configs = readGithubIntegrationConfigs(
|
|
1307
1398
|
(_a = config.getOptionalConfigArray("integrations.github")) != null ? _a : []
|
|
1308
1399
|
);
|
|
1309
1400
|
return basicIntegrations(
|
|
1310
|
-
configs.map((c) => new
|
|
1401
|
+
configs.map((c) => new _GithubIntegration(c)),
|
|
1311
1402
|
(i) => i.config.host
|
|
1312
1403
|
);
|
|
1313
1404
|
};
|
|
1314
|
-
function
|
|
1405
|
+
function replaceGithubUrlType(url, type) {
|
|
1315
1406
|
return url.replace(
|
|
1316
1407
|
/\/\/([^/]+)\/([^/]+)\/([^/]+)\/(blob|tree|edit)\//,
|
|
1317
1408
|
(_, host, owner, repo) => {
|
|
@@ -1320,6 +1411,20 @@ function replaceGitHubUrlType(url, type) {
|
|
|
1320
1411
|
);
|
|
1321
1412
|
}
|
|
1322
1413
|
|
|
1414
|
+
const getGitHubFileFetchUrl = getGithubFileFetchUrl;
|
|
1415
|
+
class GitHubIntegration extends GithubIntegration {
|
|
1416
|
+
constructor(integrationConfig) {
|
|
1417
|
+
super(integrationConfig);
|
|
1418
|
+
}
|
|
1419
|
+
get config() {
|
|
1420
|
+
return super.config;
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
GitHubIntegration.factory = GithubIntegration.factory;
|
|
1424
|
+
const readGitHubIntegrationConfig = readGithubIntegrationConfig;
|
|
1425
|
+
const readGitHubIntegrationConfigs = readGithubIntegrationConfigs;
|
|
1426
|
+
const replaceGitHubUrlType = replaceGithubUrlType;
|
|
1427
|
+
|
|
1323
1428
|
const GITLAB_HOST = "gitlab.com";
|
|
1324
1429
|
const GITLAB_API_BASE_URL = "https://gitlab.com/api/v4";
|
|
1325
1430
|
function readGitLabIntegrationConfig(config) {
|
|
@@ -1491,8 +1596,9 @@ class ScmIntegrations {
|
|
|
1491
1596
|
bitbucketCloud: BitbucketCloudIntegration.factory({ config }),
|
|
1492
1597
|
bitbucketServer: BitbucketServerIntegration.factory({ config }),
|
|
1493
1598
|
gerrit: GerritIntegration.factory({ config }),
|
|
1494
|
-
github:
|
|
1495
|
-
gitlab: GitLabIntegration.factory({ config })
|
|
1599
|
+
github: GithubIntegration.factory({ config }),
|
|
1600
|
+
gitlab: GitLabIntegration.factory({ config }),
|
|
1601
|
+
gitea: GiteaIntegration.factory({ config })
|
|
1496
1602
|
});
|
|
1497
1603
|
}
|
|
1498
1604
|
constructor(integrationsByType) {
|
|
@@ -1522,6 +1628,9 @@ class ScmIntegrations {
|
|
|
1522
1628
|
get gitlab() {
|
|
1523
1629
|
return this.byType.gitlab;
|
|
1524
1630
|
}
|
|
1631
|
+
get gitea() {
|
|
1632
|
+
return this.byType.gitea;
|
|
1633
|
+
}
|
|
1525
1634
|
list() {
|
|
1526
1635
|
return Object.values(this.byType).flatMap(
|
|
1527
1636
|
(i) => i.list()
|
|
@@ -1567,7 +1676,9 @@ exports.DefaultGithubCredentialsProvider = DefaultGithubCredentialsProvider;
|
|
|
1567
1676
|
exports.GerritIntegration = GerritIntegration;
|
|
1568
1677
|
exports.GitHubIntegration = GitHubIntegration;
|
|
1569
1678
|
exports.GitLabIntegration = GitLabIntegration;
|
|
1679
|
+
exports.GiteaIntegration = GiteaIntegration;
|
|
1570
1680
|
exports.GithubAppCredentialsMux = GithubAppCredentialsMux;
|
|
1681
|
+
exports.GithubIntegration = GithubIntegration;
|
|
1571
1682
|
exports.ScmIntegrations = ScmIntegrations;
|
|
1572
1683
|
exports.SingleInstanceGithubCredentialsProvider = SingleInstanceGithubCredentialsProvider;
|
|
1573
1684
|
exports.defaultScmResolveUrl = defaultScmResolveUrl;
|
|
@@ -1597,6 +1708,9 @@ exports.getGitHubRequestOptions = getGitHubRequestOptions;
|
|
|
1597
1708
|
exports.getGitLabFileFetchUrl = getGitLabFileFetchUrl;
|
|
1598
1709
|
exports.getGitLabIntegrationRelativePath = getGitLabIntegrationRelativePath;
|
|
1599
1710
|
exports.getGitLabRequestOptions = getGitLabRequestOptions;
|
|
1711
|
+
exports.getGiteaFileContentsUrl = getGiteaFileContentsUrl;
|
|
1712
|
+
exports.getGiteaRequestOptions = getGiteaRequestOptions;
|
|
1713
|
+
exports.getGithubFileFetchUrl = getGithubFileFetchUrl;
|
|
1600
1714
|
exports.parseGerritGitilesUrl = parseGerritGitilesUrl;
|
|
1601
1715
|
exports.parseGerritJsonResponse = parseGerritJsonResponse;
|
|
1602
1716
|
exports.readAwsS3IntegrationConfig = readAwsS3IntegrationConfig;
|
|
@@ -1615,7 +1729,11 @@ exports.readGitHubIntegrationConfig = readGitHubIntegrationConfig;
|
|
|
1615
1729
|
exports.readGitHubIntegrationConfigs = readGitHubIntegrationConfigs;
|
|
1616
1730
|
exports.readGitLabIntegrationConfig = readGitLabIntegrationConfig;
|
|
1617
1731
|
exports.readGitLabIntegrationConfigs = readGitLabIntegrationConfigs;
|
|
1732
|
+
exports.readGiteaConfig = readGiteaConfig;
|
|
1733
|
+
exports.readGithubIntegrationConfig = readGithubIntegrationConfig;
|
|
1734
|
+
exports.readGithubIntegrationConfigs = readGithubIntegrationConfigs;
|
|
1618
1735
|
exports.readGoogleGcsIntegrationConfig = readGoogleGcsIntegrationConfig;
|
|
1619
1736
|
exports.replaceGitHubUrlType = replaceGitHubUrlType;
|
|
1620
1737
|
exports.replaceGitLabUrlType = replaceGitLabUrlType;
|
|
1738
|
+
exports.replaceGithubUrlType = replaceGithubUrlType;
|
|
1621
1739
|
//# sourceMappingURL=index.cjs.js.map
|