Skip to content

Commit

Permalink
refactor(release-notes): use util/url to validate url (#23128)
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy committed Jul 4, 2023
1 parent 81eb17a commit 3bae715
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions lib/workers/repository/update/pr/changelog/release-notes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO #7154
import URL from 'node:url';
import is from '@sindresorhus/is';
import { DateTime } from 'luxon';
import MarkdownIt from 'markdown-it';
Expand All @@ -9,6 +7,7 @@ import * as packageCache from '../../../../../util/cache/package';
import { detectPlatform } from '../../../../../util/common';
import { linkify } from '../../../../../util/markdown';
import { newlineRegex, regEx } from '../../../../../util/regex';
import { validateUrl } from '../../../../../util/url';
import type { BranchUpgradeConfig } from '../../../../types';
import * as bitbucket from './bitbucket';
import * as github from './github';
Expand Down Expand Up @@ -233,17 +232,6 @@ function sectionize(text: string, level: number): string[] {
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(
project: ChangeLogProject
): Promise<ChangeLogFile | null> {
Expand Down Expand Up @@ -345,12 +333,12 @@ export async function getReleaseNotesMd(
.filter(Boolean);
let body = section.replace(regEx(/.*?\n(-{3,}\n)?/), '').trim();
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);
// TODO: fix url
const notesSourceUrl = `${baseUrl}${repository}/blob/HEAD/${changelogFile}`;
const mdHeadingLink = title
.filter((word) => !isUrl(word))
.filter((word) => !validateUrl(word))
.join('-')
.replace(regEx(/[^A-Za-z0-9-]/g), '');
const url = `${notesSourceUrl}#${mdHeadingLink}`;
Expand Down

0 comments on commit 3bae715

Please sign in to comment.