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

refactor(release-notes): use util/url to validate url (#23128)

parent 81eb17aa
Branches
No related tags found
No related merge requests found
// TODO #7154
import URL from 'node:url';
import is from '@sindresorhus/is'; import is from '@sindresorhus/is';
import { DateTime } from 'luxon'; import { DateTime } from 'luxon';
import MarkdownIt from 'markdown-it'; import MarkdownIt from 'markdown-it';
...@@ -9,6 +7,7 @@ import * as packageCache from '../../../../../util/cache/package'; ...@@ -9,6 +7,7 @@ import * as packageCache from '../../../../../util/cache/package';
import { detectPlatform } from '../../../../../util/common'; import { detectPlatform } from '../../../../../util/common';
import { linkify } from '../../../../../util/markdown'; import { linkify } from '../../../../../util/markdown';
import { newlineRegex, regEx } from '../../../../../util/regex'; import { newlineRegex, regEx } from '../../../../../util/regex';
import { validateUrl } from '../../../../../util/url';
import type { BranchUpgradeConfig } from '../../../../types'; import type { BranchUpgradeConfig } from '../../../../types';
import * as bitbucket from './bitbucket'; import * as bitbucket from './bitbucket';
import * as github from './github'; import * as github from './github';
...@@ -233,17 +232,6 @@ function sectionize(text: string, level: number): string[] { ...@@ -233,17 +232,6 @@ function sectionize(text: string, level: number): string[] {
return result; return result;
} }
function isUrl(url: string): boolean {
try {
return !!URL.parse(url).hostname;
} catch (err) {
// istanbul ignore next
logger.debug({ err }, `Error parsing ${url} in URL.parse`);
}
// istanbul ignore next
return false;
}
export async function getReleaseNotesMdFileInner( export async function getReleaseNotesMdFileInner(
project: ChangeLogProject project: ChangeLogProject
): Promise<ChangeLogFile | null> { ): Promise<ChangeLogFile | null> {
...@@ -345,12 +333,12 @@ export async function getReleaseNotesMd( ...@@ -345,12 +333,12 @@ export async function getReleaseNotesMd(
.filter(Boolean); .filter(Boolean);
let body = section.replace(regEx(/.*?\n(-{3,}\n)?/), '').trim(); let body = section.replace(regEx(/.*?\n(-{3,}\n)?/), '').trim();
for (const word of title) { for (const word of title) {
if (word.includes(version) && !isUrl(word)) { if (word.includes(version) && !validateUrl(word)) {
logger.trace({ body }, 'Found release notes for v' + version); logger.trace({ body }, 'Found release notes for v' + version);
// TODO: fix url // TODO: fix url
const notesSourceUrl = `${baseUrl}${repository}/blob/HEAD/${changelogFile}`; const notesSourceUrl = `${baseUrl}${repository}/blob/HEAD/${changelogFile}`;
const mdHeadingLink = title const mdHeadingLink = title
.filter((word) => !isUrl(word)) .filter((word) => !validateUrl(word))
.join('-') .join('-')
.replace(regEx(/[^A-Za-z0-9-]/g), ''); .replace(regEx(/[^A-Za-z0-9-]/g), '');
const url = `${notesSourceUrl}#${mdHeadingLink}`; const url = `${notesSourceUrl}#${mdHeadingLink}`;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment