Skip to content
Snippets Groups Projects
Unverified Commit f19eb5b8 authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

fix(github): Don't append `/api/v3/` to the endpoint twice (#16097)

* fix(github): Don't attach `/api/v3/` to the endpoint twice

* Add test

* More correct replacing
parent 26a4d482
Branches
No related tags found
No related merge requests found
......@@ -181,7 +181,7 @@ export abstract class AbstractGithubDatasourceCache<
// so that soft update mechanics is immediately starting.
let cacheUpdatedAt = now.minus(this.updateDuration).toISO();
const baseUrl = getApiBaseUrl(registryUrl).replace('/v3/', '/'); // Replace for GHE
const baseUrl = getApiBaseUrl(registryUrl).replace(/\/v3\/$/, '/'); // Replace for GHE
const [owner, name] = packageName.split('/');
if (owner && name) {
......
......@@ -20,8 +20,12 @@ describe('modules/datasource/github-releases/common', () => {
});
it('supports local github installations', () => {
const apiUrl = getApiBaseUrl('https://gh.my-company.com/');
expect(apiUrl).toBe('https://gh.my-company.com/api/v3/');
expect(getApiBaseUrl('https://gh.my-company.com/')).toBe(
'https://gh.my-company.com/api/v3/'
);
expect(getApiBaseUrl('https://gh.my-company.com/api/v3/')).toBe(
'https://gh.my-company.com/api/v3/'
);
});
});
});
......@@ -10,9 +10,19 @@ export function getSourceUrlBase(registryUrl: string | undefined): string {
export function getApiBaseUrl(registryUrl: string | undefined): string {
const sourceUrlBase = getSourceUrlBase(registryUrl);
return [defaultSourceUrlBase, defaultApiBaseUrl].includes(sourceUrlBase)
? defaultApiBaseUrl
: `${sourceUrlBase}api/v3/`;
if (
sourceUrlBase === defaultSourceUrlBase ||
sourceUrlBase === defaultApiBaseUrl
) {
return defaultApiBaseUrl;
}
if (sourceUrlBase.endsWith('/api/v3/')) {
return sourceUrlBase;
}
return `${sourceUrlBase}api/v3/`;
}
export function getSourceUrl(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment