@backstage/integration 1.3.0-next.0 → 1.3.0-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.d.ts CHANGED
@@ -1183,7 +1183,7 @@ declare class SingleInstanceGithubCredentialsProvider implements GithubCredentia
1183
1183
  *
1184
1184
  * Converts
1185
1185
  * from: https://gitlab.example.com/a/b/blob/master/c.yaml
1186
- * to: https://gitlab.example.com/a/b/raw/master/c.yaml
1186
+ * to: https://gitlab.com/api/v4/projects/projectId/repository/c.yaml?ref=master
1187
1187
  * -or-
1188
1188
  * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath
1189
1189
  * to: https://gitlab.com/api/v4/projects/projectId/repository/files/filepath?ref=branch
package/dist/index.esm.js CHANGED
@@ -4,7 +4,6 @@ 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';
8
7
 
9
8
  function isValidHost(host) {
10
9
  const check = new URL("http://example.com");
@@ -733,19 +732,16 @@ const _BitbucketServerIntegration = class {
733
732
  const resolved = defaultScmResolveUrl(options);
734
733
  if (options.lineNumber) {
735
734
  const url = new URL(resolved);
736
- const filename = url.pathname.split("/").slice(-1)[0];
737
- url.hash = `${filename}-${options.lineNumber}`;
735
+ url.hash = options.lineNumber.toString();
738
736
  return url.toString();
739
737
  }
740
738
  return resolved;
741
739
  }
742
740
  resolveEditUrl(url) {
743
- const urlData = parseGitUrl(url);
744
- const editUrl = new URL(url);
745
- editUrl.searchParams.set("mode", "edit");
746
- editUrl.searchParams.set("spa", "0");
747
- editUrl.searchParams.set("at", urlData.ref);
748
- return editUrl.toString();
741
+ if (url.includes("?")) {
742
+ return url.substring(0, url.indexOf("?"));
743
+ }
744
+ return url;
749
745
  }
750
746
  };
751
747
  let BitbucketServerIntegration = _BitbucketServerIntegration;
@@ -1358,11 +1354,8 @@ function getGitLabIntegrationRelativePath(config) {
1358
1354
  }
1359
1355
 
1360
1356
  async function getGitLabFileFetchUrl(url, config) {
1361
- if (url.includes("/-/blob/")) {
1362
- const projectID = await getProjectId(url, config);
1363
- return buildProjectUrl(url, projectID, config).toString();
1364
- }
1365
- return buildRawUrl(url).toString();
1357
+ const projectID = await getProjectId(url, config);
1358
+ return buildProjectUrl(url, projectID, config).toString();
1366
1359
  }
1367
1360
  function getGitLabRequestOptions(config) {
1368
1361
  const { token = "" } = config;
@@ -1372,29 +1365,10 @@ function getGitLabRequestOptions(config) {
1372
1365
  }
1373
1366
  };
1374
1367
  }
1375
- function buildRawUrl(target) {
1376
- try {
1377
- const url = new URL(target);
1378
- const splitPath = url.pathname.split("/").filter(Boolean);
1379
- const blobIndex = splitPath.indexOf("blob", 2);
1380
- if (blobIndex < 2 || blobIndex === splitPath.length - 1) {
1381
- throw new InputError("Wrong GitLab URL");
1382
- }
1383
- const repoPath = splitPath.slice(0, blobIndex);
1384
- const restOfPath = splitPath.slice(blobIndex + 1);
1385
- if (!restOfPath.join("/").match(/\.(yaml|yml)$/)) {
1386
- throw new InputError("Wrong GitLab URL");
1387
- }
1388
- url.pathname = [...repoPath, "raw", ...restOfPath].join("/");
1389
- return url;
1390
- } catch (e) {
1391
- throw new InputError(`Incorrect url: ${target}, ${e}`);
1392
- }
1393
- }
1394
1368
  function buildProjectUrl(target, projectID, config) {
1395
1369
  try {
1396
1370
  const url = new URL(target);
1397
- const branchAndFilePath = url.pathname.split("/-/blob/")[1];
1371
+ const branchAndFilePath = url.pathname.split("/blob/").slice(1).join("/blob/");
1398
1372
  const [branch, ...filePath] = branchAndFilePath.split("/");
1399
1373
  const relativePath = getGitLabIntegrationRelativePath(config);
1400
1374
  url.pathname = [
@@ -1413,11 +1387,11 @@ function buildProjectUrl(target, projectID, config) {
1413
1387
  }
1414
1388
  async function getProjectId(target, config) {
1415
1389
  const url = new URL(target);
1416
- if (!url.pathname.includes("/-/blob/")) {
1390
+ if (!url.pathname.includes("/blob/")) {
1417
1391
  throw new Error("Please provide full path to yaml file from GitLab");
1418
1392
  }
1419
1393
  try {
1420
- let repo = url.pathname.split("/-/blob/")[0];
1394
+ let repo = url.pathname.split("/-/blob/")[0].split("/blob/")[0];
1421
1395
  const relativePath = getGitLabIntegrationRelativePath(config);
1422
1396
  if (relativePath) {
1423
1397
  repo = repo.replace(relativePath, "");
@@ -1536,7 +1510,16 @@ class ScmIntegrations {
1536
1510
  );
1537
1511
  }
1538
1512
  byUrl(url) {
1539
- return Object.values(this.byType).map((i) => i.byUrl(url)).find(Boolean);
1513
+ let candidates = Object.values(this.byType).map((i) => i.byUrl(url)).filter(Boolean);
1514
+ if (candidates.length > 1) {
1515
+ const filteredCandidates = candidates.filter(
1516
+ (x) => !(x instanceof BitbucketIntegration)
1517
+ );
1518
+ if (filteredCandidates.length !== 0) {
1519
+ candidates = filteredCandidates;
1520
+ }
1521
+ }
1522
+ return candidates[0];
1540
1523
  }
1541
1524
  byHost(host) {
1542
1525
  return Object.values(this.byType).map((i) => i.byHost(host)).find(Boolean);