@backstage/integration 1.2.0-next.0 → 1.2.1-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 CHANGED
@@ -1,5 +1,64 @@
1
1
  # @backstage/integration
2
2
 
3
+ ## 1.2.1-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 72dfcbc8bf: Gerrit Integration: Handle absolute paths in `resolveUrl` properly.
8
+
9
+ ## 1.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - e295ce87de: added the possibility to handle raw Gitlab URLs with nested namespaces
14
+ - 6673babab9: Gerrit UrlReader: Implemented `readTree`
15
+ - 1b4e1e2306: Split `bitbucket` integration into `bitbucketCloud` and `bitbucketServer`
16
+ (backwards compatible).
17
+
18
+ In order to migrate to the new integration configs,
19
+ move your configs from `integrations.bitbucket`
20
+ to `integrations.bitbucketCloud` or `integrations.bitbucketServer`.
21
+
22
+ Migration example:
23
+
24
+ **Before:**
25
+
26
+ ```yaml
27
+ integrations:
28
+ bitbucket:
29
+ - host: bitbucket.org
30
+ username: bitbucket_user
31
+ appPassword: app-password
32
+ - host: bitbucket-server.company.com
33
+ token: my-token
34
+ ```
35
+
36
+ **After:**
37
+
38
+ ```yaml
39
+ integrations:
40
+ bitbucketCloud:
41
+ - username: bitbucket_user
42
+ appPassword: app-password
43
+ bitbucketServer:
44
+ - host: bitbucket-server.company.com
45
+ token: my-token
46
+ ```
47
+
48
+ - 566407bf8a: Gerrit Integration: Added the `getGerritProjectsApiUrl` function
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies
53
+ - @backstage/config@1.0.1
54
+
55
+ ## 1.2.0-next.1
56
+
57
+ ### Patch Changes
58
+
59
+ - Updated dependencies
60
+ - @backstage/config@1.0.1-next.0
61
+
3
62
  ## 1.2.0-next.0
4
63
 
5
64
  ### Minor Changes
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
 
@@ -803,43 +804,6 @@ function readGerritIntegrationConfigs(configs) {
803
804
  return configs.map(readGerritIntegrationConfig);
804
805
  }
805
806
 
806
- const _GerritIntegration = class {
807
- constructor(integrationConfig) {
808
- this.integrationConfig = integrationConfig;
809
- }
810
- get type() {
811
- return "gerrit";
812
- }
813
- get title() {
814
- return this.integrationConfig.host;
815
- }
816
- get config() {
817
- return this.integrationConfig;
818
- }
819
- resolveUrl(options) {
820
- const { url, base, lineNumber } = options;
821
- let updated;
822
- if (url) {
823
- updated = new URL(url, base);
824
- } else {
825
- updated = new URL(base);
826
- }
827
- if (lineNumber) {
828
- updated.hash = lineNumber.toString();
829
- }
830
- return updated.toString();
831
- }
832
- resolveEditUrl(url) {
833
- return url;
834
- }
835
- };
836
- let GerritIntegration = _GerritIntegration;
837
- GerritIntegration.factory = ({ config }) => {
838
- var _a;
839
- const configs = readGerritIntegrationConfigs((_a = config.getOptionalConfigArray("integrations.gerrit")) != null ? _a : []);
840
- return basicIntegrations(configs.map((c) => new _GerritIntegration(c)), (i) => i.config.host);
841
- };
842
-
843
807
  const GERRIT_BODY_PREFIX = ")]}'";
844
808
  function parseGerritGitilesUrl(config, url) {
845
809
  const urlPath = url.replace(config.gitilesBaseUrl, "");
@@ -861,6 +825,9 @@ function parseGerritGitilesUrl(config, url) {
861
825
  project
862
826
  };
863
827
  }
828
+ function builldGerritGitilesUrl(config, project, branch, filePath) {
829
+ return `${config.gitilesBaseUrl}/${project}/+/refs/heads/${branch}/${lodash.trimStart(filePath, "/")}`;
830
+ }
864
831
  function getAuthenticationPrefix(config) {
865
832
  return config.password ? "/a/" : "/";
866
833
  }
@@ -902,6 +869,47 @@ async function parseGerritJsonResponse(response) {
902
869
  throw new Error(`Gerrit JSON body prefix missing. Found: ${responseBody.slice(0, 10)}`);
903
870
  }
904
871
 
872
+ const _GerritIntegration = class {
873
+ constructor(integrationConfig) {
874
+ this.integrationConfig = integrationConfig;
875
+ }
876
+ get type() {
877
+ return "gerrit";
878
+ }
879
+ get title() {
880
+ return this.integrationConfig.host;
881
+ }
882
+ get config() {
883
+ return this.integrationConfig;
884
+ }
885
+ resolveUrl(options) {
886
+ const { url, base, lineNumber } = options;
887
+ let updated;
888
+ if (url.startsWith("/")) {
889
+ const { branch, project } = parseGerritGitilesUrl(this.config, base);
890
+ return builldGerritGitilesUrl(this.config, project, branch, url);
891
+ }
892
+ if (url) {
893
+ updated = new URL(url, base);
894
+ } else {
895
+ updated = new URL(base);
896
+ }
897
+ if (lineNumber) {
898
+ updated.hash = lineNumber.toString();
899
+ }
900
+ return updated.toString();
901
+ }
902
+ resolveEditUrl(url) {
903
+ return url;
904
+ }
905
+ };
906
+ let GerritIntegration = _GerritIntegration;
907
+ GerritIntegration.factory = ({ config }) => {
908
+ var _a;
909
+ const configs = readGerritIntegrationConfigs((_a = config.getOptionalConfigArray("integrations.gerrit")) != null ? _a : []);
910
+ return basicIntegrations(configs.map((c) => new _GerritIntegration(c)), (i) => i.config.host);
911
+ };
912
+
905
913
  const GITHUB_HOST = "github.com";
906
914
  const GITHUB_API_BASE_URL = "https://api.github.com";
907
915
  const GITHUB_RAW_BASE_URL = "https://raw.githubusercontent.com";
@@ -1234,14 +1242,20 @@ function getGitLabRequestOptions(config) {
1234
1242
  function buildRawUrl(target) {
1235
1243
  try {
1236
1244
  const url = new URL(target);
1237
- const [empty, userOrOrg, repoName, blobKeyword, ...restOfPath] = url.pathname.split("/");
1238
- if (empty !== "" || userOrOrg === "" || repoName === "" || blobKeyword !== "blob" || !restOfPath.join("/").match(/\.(yaml|yml)$/)) {
1239
- throw new Error("Wrong GitLab URL");
1245
+ const splitPath = url.pathname.split("/").filter(Boolean);
1246
+ const blobIndex = splitPath.indexOf("blob", 2);
1247
+ if (blobIndex < 2 || blobIndex === splitPath.length - 1) {
1248
+ throw new errors.InputError("Wrong GitLab URL");
1240
1249
  }
1241
- url.pathname = [empty, userOrOrg, repoName, "raw", ...restOfPath].join("/");
1250
+ const repoPath = splitPath.slice(0, blobIndex);
1251
+ const restOfPath = splitPath.slice(blobIndex + 1);
1252
+ if (!restOfPath.join("/").match(/\.(yaml|yml)$/)) {
1253
+ throw new errors.InputError("Wrong GitLab URL");
1254
+ }
1255
+ url.pathname = [...repoPath, "raw", ...restOfPath].join("/");
1242
1256
  return url;
1243
1257
  } catch (e) {
1244
- throw new Error(`Incorrect url: ${target}, ${e}`);
1258
+ throw new errors.InputError(`Incorrect url: ${target}, ${e}`);
1245
1259
  }
1246
1260
  }
1247
1261
  function buildProjectUrl(target, projectID) {