Skip to content

Commit 29562a1

Browse files
fix(merge-confidence): ensure URL path has trailing slashes (#27536)
1 parent 5ea25f7 commit 29562a1

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lib/util/merge-confidence/index.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,23 @@ describe('util/merge-confidence/index', () => {
347347
);
348348
});
349349

350+
it('uses a custom base url containing path', async () => {
351+
const renovateApi = 'https://domain.com/proxy/renovate-api';
352+
process.env.RENOVATE_X_MERGE_CONFIDENCE_API_BASE_URL = renovateApi;
353+
httpMock.scope(renovateApi).get(`/api/mc/availability`).reply(200);
354+
355+
await expect(initMergeConfidence()).toResolve();
356+
357+
expect(logger.trace).toHaveBeenCalledWith(
358+
expect.anything(),
359+
'using merge confidence API base found in environment variables',
360+
);
361+
expect(logger.debug).toHaveBeenCalledWith(
362+
expect.anything(),
363+
'merge confidence API - successfully authenticated',
364+
);
365+
});
366+
350367
it('resolves if no token', async () => {
351368
hostRules.clear();
352369

lib/util/merge-confidence/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as packageCache from '../cache/package';
77
import { parseJson } from '../common';
88
import * as hostRules from '../host-rules';
99
import { Http } from '../http';
10+
import { ensureTrailingSlash, joinUrlParts } from '../url';
1011
import { MERGE_CONFIDENCE } from './common';
1112
import type { MergeConfidence } from './types';
1213

@@ -164,7 +165,14 @@ async function queryApi(
164165
}
165166

166167
const escapedPackageName = packageName.replace('/', '%2f');
167-
const url = `${apiBaseUrl}api/mc/json/${datasource}/${escapedPackageName}/${currentVersion}/${newVersion}`;
168+
const url = joinUrlParts(
169+
apiBaseUrl,
170+
'api/mc/json',
171+
datasource,
172+
escapedPackageName,
173+
currentVersion,
174+
newVersion,
175+
);
168176
const cacheKey = `${token}:${url}`;
169177
const cachedResult = await packageCache.get(hostType, cacheKey);
170178

@@ -217,7 +225,7 @@ export async function initMergeConfidence(): Promise<void> {
217225
return;
218226
}
219227

220-
const url = `${apiBaseUrl}api/mc/availability`;
228+
const url = joinUrlParts(apiBaseUrl, 'api/mc/availability');
221229
try {
222230
await http.get(url);
223231
} catch (err) {
@@ -246,7 +254,7 @@ function getApiBaseUrl(): string {
246254
{ baseUrl: parsedBaseUrl },
247255
'using merge confidence API base found in environment variables',
248256
);
249-
return parsedBaseUrl;
257+
return ensureTrailingSlash(parsedBaseUrl);
250258
} catch (err) {
251259
logger.warn(
252260
{ err, baseFromEnv },

0 commit comments

Comments
 (0)