Skip to content
Snippets Groups Projects
Unverified Commit 74ad0338 authored by Adam Setch's avatar Adam Setch Committed by GitHub
Browse files

refactor(changelog): use util/url instead of deprecated URL (#23113)

parent bd3cf102
No related branches found
No related tags found
No related merge requests found
import { partial } from '../../../../../../test/util';
import type { BranchConfig } from '../../../../types';
import { GitHubChangeLogSource } from './github/source';
const changelogSource = new GitHubChangeLogSource();
const upgrade = partial<BranchConfig>({
endpoint: 'https://api.github.com/',
packageName: 'renovate',
sourceUrl: 'https://github.com/renovatebot/renovate',
});
describe('workers/repository/update/pr/changelog/source', () => {
describe('getBaseUrl', () => {
it('handles unsupported sourceUrl', () => {
expect(
changelogSource.getBaseUrl({
...upgrade,
sourceUrl: undefined,
})
).toBeEmptyString();
});
it('handles sourceUrl', () => {
expect(changelogSource.getBaseUrl(upgrade)).toBe('https://github.com/');
});
});
describe('getRepositoryFromUrl', () => {
it('handles unsupported sourceUrl', () => {
expect(
changelogSource.getRepositoryFromUrl({
...upgrade,
sourceUrl: undefined,
})
).toBeEmptyString();
});
it('handles sourceUrl', () => {
expect(changelogSource.getRepositoryFromUrl(upgrade)).toBe(
'renovatebot/renovate'
);
});
});
});
import URL from 'node:url';
import is from '@sindresorhus/is';
import { logger } from '../../../../../logger';
import { getPkgReleases } from '../../../../../modules/datasource';
......@@ -6,7 +5,7 @@ import type { Release } from '../../../../../modules/datasource/types';
import * as allVersioning from '../../../../../modules/versioning';
import * as packageCache from '../../../../../util/cache/package';
import { regEx } from '../../../../../util/regex';
import { trimSlashes } from '../../../../../util/url';
import { parseUrl, trimSlashes } from '../../../../../util/url';
import type { BranchUpgradeConfig } from '../../../../types';
import { slugifyUrl } from './common';
import { addReleaseNotes } from './release-notes';
......@@ -238,16 +237,22 @@ export abstract class ChangeLogSource {
return `${slugifyUrl(sourceUrl)}:${packageName}:${prev}:${next}`;
}
protected getBaseUrl(config: BranchUpgradeConfig): string {
const parsedUrl = URL.parse(config.sourceUrl!);
const protocol = parsedUrl.protocol!;
const host = parsedUrl.host!;
getBaseUrl(config: BranchUpgradeConfig): string {
const parsedUrl = parseUrl(config.sourceUrl);
if (is.nullOrUndefined(parsedUrl)) {
return '';
}
const protocol = parsedUrl.protocol;
const host = parsedUrl.host;
return `${protocol}//${host}/`;
}
private getRepositoryFromUrl(config: BranchUpgradeConfig): string {
const parsedUrl = URL.parse(config.sourceUrl!);
const pathname = parsedUrl.pathname!;
getRepositoryFromUrl(config: BranchUpgradeConfig): string {
const parsedUrl = parseUrl(config.sourceUrl);
if (is.nullOrUndefined(parsedUrl)) {
return '';
}
const pathname = parsedUrl.pathname;
return trimSlashes(pathname).replace(regEx(/\.git$/), '');
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment