@backstage/integration 1.6.1 → 1.6.2

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
@@ -1028,13 +1028,23 @@ function getAuthenticationPrefix(config) {
1028
1028
  return config.password ? "/a/" : "/";
1029
1029
  }
1030
1030
  function getGitilesAuthenticationUrl(config) {
1031
- const parsedUrl = new URL(config.gitilesBaseUrl);
1032
- parsedUrl.pathname = parsedUrl.pathname.replace(/\/?$/, "");
1033
- parsedUrl.pathname = parsedUrl.pathname.replace(
1034
- /\/([^\/]*)$/,
1035
- `${getAuthenticationPrefix(config)}$1`
1036
- );
1037
- return parsedUrl.toString();
1031
+ if (!config.baseUrl || !config.gitilesBaseUrl) {
1032
+ throw new Error(
1033
+ "Unexpected Gerrit config values. baseUrl or gitilesBaseUrl not set."
1034
+ );
1035
+ }
1036
+ if (config.gitilesBaseUrl.startsWith(config.baseUrl)) {
1037
+ return config.gitilesBaseUrl.replace(
1038
+ config.baseUrl.concat("/"),
1039
+ config.baseUrl.concat(getAuthenticationPrefix(config))
1040
+ );
1041
+ }
1042
+ if (config.password) {
1043
+ throw new Error(
1044
+ "Since the baseUrl (Gerrit) is not part of the gitilesBaseUrl, an authentication URL could not be constructed."
1045
+ );
1046
+ }
1047
+ return config.gitilesBaseUrl;
1038
1048
  }
1039
1049
  function getGerritBranchApiUrl(config, url) {
1040
1050
  const { branch, project } = parseGerritGitilesUrl(config, url);