Skip to content

Commit 07c2e1c

Browse files
committedOct 18, 2024·
feat: add function to convert PR, issue, and changelog links to markdown format
resolves #32
1 parent f184bc5 commit 07c2e1c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
 

‎index.js

+31
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,36 @@ const reduceHeadings = (text) => text
4747
.replace(/^###\s+(.+)$/gm, '**__$1__**') // Convert H3 to bold + underline
4848
.replace(/^##\s+(.+)$/gm, '**$1**'); // Convert H2 to bold
4949

50+
/**
51+
* Converts PR links, issue links, and changelog links to markdown format.
52+
* - PR links: `https://github.com/OWNER/REPO/pull/1` -> `[PR #1](https://github.com/OWNER/REPO/pull/1)`
53+
* - Issue links: `https://github.com/OWNER/REPO/issues/1` -> `[Issue #30](https://github.com/OWNER/REPO/issues/1)`
54+
* - 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)`
55+
* @param {string} text The input text.
56+
* @returns {string} The text with links converted to markdown format.
57+
*/
58+
const convertLinksToMarkdown = (text) => {
59+
// Convert PR links
60+
text = text.replace(
61+
/https:\/\/github\.com\/([\w-]+)\/([\w-]+)\/pull\/(\d+)/g,
62+
(match, owner, repo, prNumber) => `[PR #${prNumber}](${match})`
63+
);
64+
65+
// Convert issue links
66+
text = text.replace(
67+
/https:\/\/github\.com\/([\w-]+)\/([\w-]+)\/issues\/(\d+)/g,
68+
(match, owner, repo, issueNumber) => `[Issue #${issueNumber}](${match})`
69+
);
70+
71+
// Convert changelog comparison links
72+
text = text.replace(
73+
/https:\/\/github\.com\/([\w-]+)\/([\w-]+)\/compare\/([v\w.-]+)\.\.\.([v\w.-]+)/g,
74+
(match, owner, repo, fromVersion, toVersion) => `[${fromVersion}...${toVersion}](${match})`
75+
);
76+
77+
return text;
78+
};
79+
5080
/**
5181
* Stylizes a markdown body into an appropriate embed message style.
5282
* @param {string} description The description to format.
@@ -57,6 +87,7 @@ const formatDescription = (description) => {
5787
edit = removeHTMLComments(edit);
5888
edit = reduceNewlines(edit);
5989
edit = convertMentionsToLinks(edit);
90+
edit = convertLinksToMarkdown(edit);
6091
edit = edit.trim();
6192

6293
if (core.getBooleanInput('reduce_headings')) {

0 commit comments

Comments
 (0)
Please sign in to comment.