mirror of
https://github.com/SethCohen/github-releases-to-discord
synced 2026-09-14 20:13:23 +00:00
feat: add function to convert PR, issue, and changelog links to markdown format
resolves #32
This commit is contained in:
@@ -47,6 +47,36 @@ const reduceHeadings = (text) => text
|
||||
.replace(/^###\s+(.+)$/gm, '**__$1__**') // Convert H3 to bold + underline
|
||||
.replace(/^##\s+(.+)$/gm, '**$1**'); // Convert H2 to bold
|
||||
|
||||
/**
|
||||
* Converts PR links, issue links, and changelog links to markdown format.
|
||||
* - PR links: `https://github.com/OWNER/REPO/pull/1` -> `[PR #1](https://github.com/OWNER/REPO/pull/1)`
|
||||
* - Issue links: `https://github.com/OWNER/REPO/issues/1` -> `[Issue #30](https://github.com/OWNER/REPO/issues/1)`
|
||||
* - Changelog links: `https://github.com/OWNER/REPO/compare/v1.0.0...v1.1.0` -> `[v1.0.0...v1.1.0](https://github.com/OWNER/REPO/compare/v1.0.0...v1.1.0)`
|
||||
* @param {string} text The input text.
|
||||
* @returns {string} The text with links converted to markdown format.
|
||||
*/
|
||||
const convertLinksToMarkdown = (text) => {
|
||||
// Convert PR links
|
||||
text = text.replace(
|
||||
/https:\/\/github\.com\/([\w-]+)\/([\w-]+)\/pull\/(\d+)/g,
|
||||
(match, owner, repo, prNumber) => `[PR #${prNumber}](${match})`
|
||||
);
|
||||
|
||||
// Convert issue links
|
||||
text = text.replace(
|
||||
/https:\/\/github\.com\/([\w-]+)\/([\w-]+)\/issues\/(\d+)/g,
|
||||
(match, owner, repo, issueNumber) => `[Issue #${issueNumber}](${match})`
|
||||
);
|
||||
|
||||
// Convert changelog comparison links
|
||||
text = text.replace(
|
||||
/https:\/\/github\.com\/([\w-]+)\/([\w-]+)\/compare\/([v\w.-]+)\.\.\.([v\w.-]+)/g,
|
||||
(match, owner, repo, fromVersion, toVersion) => `[${fromVersion}...${toVersion}](${match})`
|
||||
);
|
||||
|
||||
return text;
|
||||
};
|
||||
|
||||
/**
|
||||
* Stylizes a markdown body into an appropriate embed message style.
|
||||
* @param {string} description The description to format.
|
||||
@@ -57,6 +87,7 @@ const formatDescription = (description) => {
|
||||
edit = removeHTMLComments(edit);
|
||||
edit = reduceNewlines(edit);
|
||||
edit = convertMentionsToLinks(edit);
|
||||
edit = convertLinksToMarkdown(edit);
|
||||
edit = edit.trim();
|
||||
|
||||
if (core.getBooleanInput('reduce_headings')) {
|
||||
|
||||
Reference in New Issue
Block a user