Add option to strip PR and commit links (#48)

* feat: add option to remove PR and commit links

* feat(github-action): rename input from remove_pr_commit_links to remove_github_reference_links for clarity and expand functionality to include issue links
fix(github-action): update removeGithubReferenceLinks function to remove all GitHub PR, commit, and issue links from the text, including markdown links

resolves #41
This commit is contained in:
SethCohen
2025-06-17 00:10:47 -04:00
committed by GitHub
parent e1dc0826fe
commit 74ded4247d
4 changed files with 29 additions and 1 deletions
+21
View File
@@ -37,6 +37,23 @@ const convertMentionsToLinks = (text) => text.replace(
(match, name) => `[@${name}](https://github.com/${name})`
);
/**
* Removes any GitHub PR, commit, or issue links from the text, including markdown links.
* @param {string} text The input text.
* @returns {string} The text without GitHub PR and commit links.
*/
const removeGithubReferenceLinks = (text) => text
// Remove markdown links to PRs, commits, and issues
.replace(/\[[^\]]*\]\(https:\/\/github\.com\/[^(\s)]+\/pull\/\d+\)/g, '')
.replace(/\[[^\]]*\]\(https:\/\/github\.com\/[^(\s)]+\/commit\/\w+\)/g, '')
.replace(/\[[^\]]*\]\(https:\/\/github\.com\/[^(\s)]+\/issues\/\d+\)/g, '')
// Remove bare PR, commit, and issue URLs
.replace(/https:\/\/github\.com\/[^(\s)]+\/pull\/\d+/g, '')
.replace(/https:\/\/github\.com\/[^(\s)]+\/commit\/\w+/g, '')
.replace(/https:\/\/github\.com\/[^(\s)]+\/issues\/\d+/g, '')
// Remove empty parentheses left behind
.replace(/\(\s*\)/g, '');
/**
* Reduces headings to a smaller format if 'reduce_headings' is enabled.
* Converts H3 to bold+underline, H2 to bold.
@@ -82,6 +99,10 @@ const formatDescription = (description) => {
let edit = removeCarriageReturn(description);
edit = removeHTMLComments(edit);
edit = reduceNewlines(edit);
if (core.getBooleanInput('remove_github_reference_links')) {
edit = removeGithubReferenceLinks(edit);
}
edit = convertMentionsToLinks(edit);
edit = convertLinksToMarkdown(edit);
edit = edit.trim();