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
+1 -1
View File
@@ -21,4 +21,4 @@ jobs:
footer_timestamp: ${{ inputs.FOOTER_TIMESTAMP }}
max_description: ${{ inputs.MAX_DESCRIPTION }}
reduce_headings: ${{ inputs.REDUCE_HEADINGS }}
remove_github_reference_links: ${{ inputs.REMOVE_GITHUB_REFERENCE_LINKS }}
+3
View File
@@ -10,6 +10,7 @@ A GitHub Action that sends a stylized Discord webhook containing the description
- **Whitespace Optimization:** Reduces redundant newlines and excess spaces while preserving proper paragraph spacing.
- **Mention Conversion:** Converts GitHub mentions (e.g., `@username`) into clickable GitHub profile links for easy navigation.
- **Markdown Link Conversion:**
- **Link Removal (Optional):** Remove PR and commit links from the changelog.
- **PR Links:** Converts pull request URLs into Markdown links (e.g., `[PR #1](https://github.com/OWNER/REPO/pull/1)`).
- **Issue Links:** Converts issue URLs into Markdown links (e.g., `[Issue #1](https://github.com/OWNER/REPO/issues/1)`).
- **Changelog Links:** Converts changelog comparison URLs into concise Markdown links (e.g., `[v1.0.0...v1.1.0](https://github.com/OWNER/REPO/compare/v1.0.0...v1.1.0)`).
@@ -42,6 +43,7 @@ A GitHub Action that sends a stylized Discord webhook containing the description
| footer_icon_url | ❌ | | String url for the webhook footer picture. |
| footer_timestamp| ❌ | | Boolean to enable footer timestamp. |
| max_description | ❌ | "4096" | Max length for the description. |
| remove_github_reference_links | ❌ | false | Remove any PR, commit, and issue links from the description. |
| reduce_headings | ❌ | false | Converts H3 to bold, h2 to bold & underline. |
## Example Usage
@@ -71,6 +73,7 @@ jobs:
footer_icon_url: "https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png"
footer_timestamp: true
max_description: '4096'
remove_github_reference_links: true
reduce_headings: true
```
+4
View File
@@ -31,6 +31,10 @@ inputs:
description: Max length for the description.
required: false
default: '4096'
remove_github_reference_links:
description: Remove any PR, commit, and issue links from the description.
required: false
default: 'false'
reduce_headings:
description: Converts H3 to bold, h2 to bold & underline.
required: false
+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();