Skip to content

Commit 62ef8e7

Browse files
Techn1xrarkins
andauthored
refactor: lift up properties for re-use in getReleaseNotesMd() (#36140)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
1 parent f6224a9 commit 62ef8e7

1 file changed

Lines changed: 31 additions & 23 deletions

File tree

lib/workers/repository/update/pr/changelog/release-notes.ts

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -366,33 +366,24 @@ export async function getReleaseNotesMd(
366366
.replace(regEx(/^\s*#*\s*/), '')
367367
.split(' ')
368368
.filter(Boolean);
369-
let body = section.replace(regEx(/.*?\n(-{3,}\n)?/), '').trim();
369+
const body = section.replace(regEx(/.*?\n(-{3,}\n)?/), '').trim();
370+
const notesSourceUrl = getNotesSourceUrl(
371+
baseUrl,
372+
repository,
373+
project,
374+
changelogFile,
375+
);
376+
const mdHeadingLink = title
377+
.filter((word) => !isHttpUrl(word))
378+
.join('-')
379+
.replace(regEx(/[^A-Za-z0-9-]/g), '');
380+
const url = `${notesSourceUrl}#${mdHeadingLink}`;
381+
// Look for version in title
370382
for (const word of title) {
371383
if (word.includes(version) && !isHttpUrl(word)) {
372384
logger.trace({ body }, 'Found release notes for v' + version);
373-
const notesSourceUrl = getNotesSourceUrl(
374-
baseUrl,
375-
repository,
376-
project,
377-
changelogFile,
378-
);
379-
const mdHeadingLink = title
380-
.filter((word) => !isHttpUrl(word))
381-
.join('-')
382-
.replace(regEx(/[^A-Za-z0-9-]/g), '');
383-
const url = `${notesSourceUrl}#${mdHeadingLink}`;
384-
body = massageBody(body, baseUrl);
385-
if (body?.length) {
386-
try {
387-
body = await linkify(body, {
388-
repository: `${baseUrl}${repository}`,
389-
});
390-
} catch (err) /* istanbul ignore next */ {
391-
logger.warn({ body, err }, 'linkify error');
392-
}
393-
}
394385
return {
395-
body,
386+
body: await linkifyBody(project, body),
396387
url,
397388
notesSourceUrl,
398389
};
@@ -524,3 +515,20 @@ function getNotesSourceUrl(
524515
changelogFile,
525516
);
526517
}
518+
519+
async function linkifyBody(
520+
{ baseUrl, repository }: ChangeLogProject,
521+
bodyStr: string,
522+
): Promise<string> {
523+
const body = massageBody(bodyStr, baseUrl);
524+
if (body?.length) {
525+
try {
526+
return await linkify(body, {
527+
repository: `${baseUrl}${repository}`,
528+
});
529+
} catch (err) /* istanbul ignore next */ {
530+
logger.warn({ body, err }, 'linkify error');
531+
}
532+
}
533+
return body;
534+
}

0 commit comments

Comments
 (0)