Check for unset config params.

Signed-off-by: Gustaf Lundh <gustaf.lundh@axis.com>
This commit is contained in:
Gustaf Lundh
2023-08-22 10:19:33 +02:00
parent 2d2fc9d20e
commit b26c173fab
2 changed files with 10 additions and 4 deletions
@@ -47,6 +47,7 @@ describe('gerrit core', () => {
};
const configWithDedicatedGitiles: GerritIntegrationConfig = {
host: 'gerrit.com',
baseUrl: 'https://gerrit.com/gerrit',
gitilesBaseUrl: 'https://dedicated-gitiles-server.com/gerrit/gitiles',
};
it('can create an archive url for a branch', () => {
+9 -4
View File
@@ -157,10 +157,15 @@ export function getAuthenticationPrefix(
export function getGitilesAuthenticationUrl(
config: GerritIntegrationConfig,
): string {
if (config.gitilesBaseUrl!.startsWith(config.baseUrl!)) {
return config.gitilesBaseUrl!.replace(
config.baseUrl!.concat('/'),
config.baseUrl!.concat(getAuthenticationPrefix(config)),
if (!config.baseUrl || !config.gitilesBaseUrl) {
throw new Error(
'Unexpected Gerrit config values. baseUrl or gitilesBaseUrl not set.',
);
}
if (config.gitilesBaseUrl.startsWith(config.baseUrl)) {
return config.gitilesBaseUrl.replace(
config.baseUrl.concat('/'),
config.baseUrl.concat(getAuthenticationPrefix(config)),
);
}
if (config.password) {