Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(merge-confidence): ensure URL path has trailing slashes #27536

Merged
merged 4 commits into from Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/util/merge-confidence/index.spec.ts
Expand Up @@ -347,6 +347,23 @@ describe('util/merge-confidence/index', () => {
);
});

it('uses a custom base url containing path', async () => {
const renovateApi = 'https://domain.com/proxy/renovate-api';
process.env.RENOVATE_X_MERGE_CONFIDENCE_API_BASE_URL = renovateApi;
httpMock.scope(renovateApi).get(`/api/mc/availability`).reply(200);

await expect(initMergeConfidence()).toResolve();

expect(logger.trace).toHaveBeenCalledWith(
expect.anything(),
'using merge confidence API base found in environment variables',
);
expect(logger.debug).toHaveBeenCalledWith(
expect.anything(),
'merge confidence API - successfully authenticated',
);
});

it('resolves if no token', async () => {
hostRules.clear();

Expand Down
14 changes: 11 additions & 3 deletions lib/util/merge-confidence/index.ts
Expand Up @@ -7,6 +7,7 @@ import * as packageCache from '../cache/package';
import { parseJson } from '../common';
import * as hostRules from '../host-rules';
import { Http } from '../http';
import { ensureTrailingSlash, joinUrlParts } from '../url';
import { MERGE_CONFIDENCE } from './common';
import type { MergeConfidence } from './types';

Expand Down Expand Up @@ -164,7 +165,14 @@ async function queryApi(
}

const escapedPackageName = packageName.replace('/', '%2f');
const url = `${apiBaseUrl}api/mc/json/${datasource}/${escapedPackageName}/${currentVersion}/${newVersion}`;
const url = joinUrlParts(
apiBaseUrl,
'api/mc/json',
datasource,
escapedPackageName,
currentVersion,
newVersion,
);
const cacheKey = `${token}:${url}`;
const cachedResult = await packageCache.get(hostType, cacheKey);

Expand Down Expand Up @@ -217,7 +225,7 @@ export async function initMergeConfidence(): Promise<void> {
return;
}

const url = `${apiBaseUrl}api/mc/availability`;
const url = joinUrlParts(apiBaseUrl, 'api/mc/availability');
try {
await http.get(url);
} catch (err) {
Expand Down Expand Up @@ -246,7 +254,7 @@ function getApiBaseUrl(): string {
{ baseUrl: parsedBaseUrl },
'using merge confidence API base found in environment variables',
);
return parsedBaseUrl;
return ensureTrailingSlash(parsedBaseUrl);
} catch (err) {
logger.warn(
{ err, baseFromEnv },
Expand Down