@backstage/integration 1.2.0-next.1 → 1.2.1-next.1

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/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");
@@ -794,43 +795,6 @@ function readGerritIntegrationConfigs(configs) {
794
795
  return configs.map(readGerritIntegrationConfig);
795
796
  }
796
797
 
797
- const _GerritIntegration = class {
798
- constructor(integrationConfig) {
799
- this.integrationConfig = integrationConfig;
800
- }
801
- get type() {
802
- return "gerrit";
803
- }
804
- get title() {
805
- return this.integrationConfig.host;
806
- }
807
- get config() {
808
- return this.integrationConfig;
809
- }
810
- resolveUrl(options) {
811
- const { url, base, lineNumber } = options;
812
- let updated;
813
- if (url) {
814
- updated = new URL(url, base);
815
- } else {
816
- updated = new URL(base);
817
- }
818
- if (lineNumber) {
819
- updated.hash = lineNumber.toString();
820
- }
821
- return updated.toString();
822
- }
823
- resolveEditUrl(url) {
824
- return url;
825
- }
826
- };
827
- let GerritIntegration = _GerritIntegration;
828
- GerritIntegration.factory = ({ config }) => {
829
- var _a;
830
- const configs = readGerritIntegrationConfigs((_a = config.getOptionalConfigArray("integrations.gerrit")) != null ? _a : []);
831
- return basicIntegrations(configs.map((c) => new _GerritIntegration(c)), (i) => i.config.host);
832
- };
833
-
834
798
  const GERRIT_BODY_PREFIX = ")]}'";
835
799
  function parseGerritGitilesUrl(config, url) {
836
800
  const urlPath = url.replace(config.gitilesBaseUrl, "");
@@ -852,6 +816,9 @@ function parseGerritGitilesUrl(config, url) {
852
816
  project
853
817
  };
854
818
  }
819
+ function builldGerritGitilesUrl(config, project, branch, filePath) {
820
+ return `${config.gitilesBaseUrl}/${project}/+/refs/heads/${branch}/${trimStart(filePath, "/")}`;
821
+ }
855
822
  function getAuthenticationPrefix(config) {
856
823
  return config.password ? "/a/" : "/";
857
824
  }
@@ -893,6 +860,47 @@ async function parseGerritJsonResponse(response) {
893
860
  throw new Error(`Gerrit JSON body prefix missing. Found: ${responseBody.slice(0, 10)}`);
894
861
  }
895
862
 
863
+ const _GerritIntegration = class {
864
+ constructor(integrationConfig) {
865
+ this.integrationConfig = integrationConfig;
866
+ }
867
+ get type() {
868
+ return "gerrit";
869
+ }
870
+ get title() {
871
+ return this.integrationConfig.host;
872
+ }
873
+ get config() {
874
+ return this.integrationConfig;
875
+ }
876
+ resolveUrl(options) {
877
+ const { url, base, lineNumber } = options;
878
+ let updated;
879
+ if (url.startsWith("/")) {
880
+ const { branch, project } = parseGerritGitilesUrl(this.config, base);
881
+ return builldGerritGitilesUrl(this.config, project, branch, url);
882
+ }
883
+ if (url) {
884
+ updated = new URL(url, base);
885
+ } else {
886
+ updated = new URL(base);
887
+ }
888
+ if (lineNumber) {
889
+ updated.hash = lineNumber.toString();
890
+ }
891
+ return updated.toString();
892
+ }
893
+ resolveEditUrl(url) {
894
+ return url;
895
+ }
896
+ };
897
+ let GerritIntegration = _GerritIntegration;
898
+ GerritIntegration.factory = ({ config }) => {
899
+ var _a;
900
+ const configs = readGerritIntegrationConfigs((_a = config.getOptionalConfigArray("integrations.gerrit")) != null ? _a : []);
901
+ return basicIntegrations(configs.map((c) => new _GerritIntegration(c)), (i) => i.config.host);
902
+ };
903
+
896
904
  const GITHUB_HOST = "github.com";
897
905
  const GITHUB_API_BASE_URL = "https://api.github.com";
898
906
  const GITHUB_RAW_BASE_URL = "https://raw.githubusercontent.com";
@@ -1225,14 +1233,20 @@ function getGitLabRequestOptions(config) {
1225
1233
  function buildRawUrl(target) {
1226
1234
  try {
1227
1235
  const url = new URL(target);
1228
- const [empty, userOrOrg, repoName, blobKeyword, ...restOfPath] = url.pathname.split("/");
1229
- if (empty !== "" || userOrOrg === "" || repoName === "" || blobKeyword !== "blob" || !restOfPath.join("/").match(/\.(yaml|yml)$/)) {
1230
- throw new Error("Wrong GitLab URL");
1236
+ const splitPath = url.pathname.split("/").filter(Boolean);
1237
+ const blobIndex = splitPath.indexOf("blob", 2);
1238
+ if (blobIndex < 2 || blobIndex === splitPath.length - 1) {
1239
+ throw new InputError("Wrong GitLab URL");
1231
1240
  }
1232
- url.pathname = [empty, userOrOrg, repoName, "raw", ...restOfPath].join("/");
1241
+ const repoPath = splitPath.slice(0, blobIndex);
1242
+ const restOfPath = splitPath.slice(blobIndex + 1);
1243
+ if (!restOfPath.join("/").match(/\.(yaml|yml)$/)) {
1244
+ throw new InputError("Wrong GitLab URL");
1245
+ }
1246
+ url.pathname = [...repoPath, "raw", ...restOfPath].join("/");
1233
1247
  return url;
1234
1248
  } catch (e) {
1235
- throw new Error(`Incorrect url: ${target}, ${e}`);
1249
+ throw new InputError(`Incorrect url: ${target}, ${e}`);
1236
1250
  }
1237
1251
  }
1238
1252
  function buildProjectUrl(target, projectID) {