@backstage/integration 1.5.1 → 1.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @backstage/integration
2
2
 
3
+ ## 1.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 842eb24ef5e8: Gitiles: Fixed auth prefix issue
8
+ - Updated dependencies
9
+ - @backstage/config@1.0.8
10
+ - @backstage/errors@1.2.1
11
+
12
+ ## 1.6.0
13
+
14
+ ### Minor Changes
15
+
16
+ - 443afcf7f567: Added `buildGerritGitilesArchiveUrl()` to construct a Gitiles URL to download an archive.
17
+ Gitiles URL that uses an authenticated prefix (`/a/`) can now be parsed by the integration.
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies
22
+ - @backstage/config@1.0.8
23
+ - @backstage/errors@1.2.1
24
+
3
25
  ## 1.5.1
4
26
 
5
27
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -1003,7 +1003,9 @@ function readGerritIntegrationConfigs(configs) {
1003
1003
 
1004
1004
  const GERRIT_BODY_PREFIX = ")]}'";
1005
1005
  function parseGerritGitilesUrl(config, url) {
1006
- const urlPath = url.replace(config.gitilesBaseUrl, "");
1006
+ const baseUrlParse = new URL(config.gitilesBaseUrl);
1007
+ const urlParse = new URL(url);
1008
+ const urlPath = urlParse.pathname.substring(urlParse.pathname.startsWith("/a/") ? 2 : 0).replace(baseUrlParse.pathname, "");
1007
1009
  const parts = urlPath.split("/").filter((p) => !!p);
1008
1010
  const projectEndIndex = parts.indexOf("+");
1009
1011
  if (projectEndIndex <= 0) {
@@ -1025,9 +1027,24 @@ function parseGerritGitilesUrl(config, url) {
1025
1027
  function buildGerritGitilesUrl(config, project, branch, filePath) {
1026
1028
  return `${config.gitilesBaseUrl}/${project}/+/refs/heads/${branch}/${lodash.trimStart(filePath, "/")}`;
1027
1029
  }
1030
+ function buildGerritGitilesArchiveUrl(config, project, branch, filePath) {
1031
+ const archiveName = filePath === "/" || filePath === "" ? ".tar.gz" : `/${filePath}.tar.gz`;
1032
+ return `${getGitilesAuthenticationUrl(
1033
+ config
1034
+ )}/${project}/+archive/refs/heads/${branch}${archiveName}`;
1035
+ }
1028
1036
  function getAuthenticationPrefix(config) {
1029
1037
  return config.password ? "/a/" : "/";
1030
1038
  }
1039
+ function getGitilesAuthenticationUrl(config) {
1040
+ const parsedUrl = new URL(config.gitilesBaseUrl);
1041
+ parsedUrl.pathname = parsedUrl.pathname.replace(/\/?$/, "");
1042
+ parsedUrl.pathname = parsedUrl.pathname.replace(
1043
+ /\/([^\/]*)$/,
1044
+ `${getAuthenticationPrefix(config)}$1`
1045
+ );
1046
+ return parsedUrl.toString();
1047
+ }
1031
1048
  function getGerritBranchApiUrl(config, url) {
1032
1049
  const { branch, project } = parseGerritGitilesUrl(config, url);
1033
1050
  return `${config.baseUrl}${getAuthenticationPrefix(
@@ -1960,6 +1977,7 @@ exports.GithubAppCredentialsMux = GithubAppCredentialsMux;
1960
1977
  exports.GithubIntegration = GithubIntegration;
1961
1978
  exports.ScmIntegrations = ScmIntegrations;
1962
1979
  exports.SingleInstanceGithubCredentialsProvider = SingleInstanceGithubCredentialsProvider;
1980
+ exports.buildGerritGitilesArchiveUrl = buildGerritGitilesArchiveUrl;
1963
1981
  exports.defaultScmResolveUrl = defaultScmResolveUrl;
1964
1982
  exports.getAzureCommitsUrl = getAzureCommitsUrl;
1965
1983
  exports.getAzureDownloadUrl = getAzureDownloadUrl;