mirror of
https://github.com/SethCohen/github-releases-to-discord
synced 2026-09-14 20:13:23 +00:00
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:
@@ -21,4 +21,4 @@ jobs:
|
|||||||
footer_timestamp: ${{ inputs.FOOTER_TIMESTAMP }}
|
footer_timestamp: ${{ inputs.FOOTER_TIMESTAMP }}
|
||||||
max_description: ${{ inputs.MAX_DESCRIPTION }}
|
max_description: ${{ inputs.MAX_DESCRIPTION }}
|
||||||
reduce_headings: ${{ inputs.REDUCE_HEADINGS }}
|
reduce_headings: ${{ inputs.REDUCE_HEADINGS }}
|
||||||
|
remove_github_reference_links: ${{ inputs.REMOVE_GITHUB_REFERENCE_LINKS }}
|
||||||
|
|||||||
@@ -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.
|
- **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.
|
- **Mention Conversion:** Converts GitHub mentions (e.g., `@username`) into clickable GitHub profile links for easy navigation.
|
||||||
- **Markdown Link Conversion:**
|
- **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)`).
|
- **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)`).
|
- **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)`).
|
- **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_icon_url | ❌ | | String url for the webhook footer picture. |
|
||||||
| footer_timestamp| ❌ | | Boolean to enable footer timestamp. |
|
| footer_timestamp| ❌ | | Boolean to enable footer timestamp. |
|
||||||
| max_description | ❌ | "4096" | Max length for the description. |
|
| 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. |
|
| reduce_headings | ❌ | false | Converts H3 to bold, h2 to bold & underline. |
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
@@ -71,6 +73,7 @@ jobs:
|
|||||||
footer_icon_url: "https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png"
|
footer_icon_url: "https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png"
|
||||||
footer_timestamp: true
|
footer_timestamp: true
|
||||||
max_description: '4096'
|
max_description: '4096'
|
||||||
|
remove_github_reference_links: true
|
||||||
reduce_headings: true
|
reduce_headings: true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ inputs:
|
|||||||
description: Max length for the description.
|
description: Max length for the description.
|
||||||
required: false
|
required: false
|
||||||
default: '4096'
|
default: '4096'
|
||||||
|
remove_github_reference_links:
|
||||||
|
description: Remove any PR, commit, and issue links from the description.
|
||||||
|
required: false
|
||||||
|
default: 'false'
|
||||||
reduce_headings:
|
reduce_headings:
|
||||||
description: Converts H3 to bold, h2 to bold & underline.
|
description: Converts H3 to bold, h2 to bold & underline.
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
@@ -37,6 +37,23 @@ const convertMentionsToLinks = (text) => text.replace(
|
|||||||
(match, name) => `[@${name}](https://github.com/${name})`
|
(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.
|
* Reduces headings to a smaller format if 'reduce_headings' is enabled.
|
||||||
* Converts H3 to bold+underline, H2 to bold.
|
* Converts H3 to bold+underline, H2 to bold.
|
||||||
@@ -82,6 +99,10 @@ const formatDescription = (description) => {
|
|||||||
let edit = removeCarriageReturn(description);
|
let edit = removeCarriageReturn(description);
|
||||||
edit = removeHTMLComments(edit);
|
edit = removeHTMLComments(edit);
|
||||||
edit = reduceNewlines(edit);
|
edit = reduceNewlines(edit);
|
||||||
|
|
||||||
|
if (core.getBooleanInput('remove_github_reference_links')) {
|
||||||
|
edit = removeGithubReferenceLinks(edit);
|
||||||
|
}
|
||||||
edit = convertMentionsToLinks(edit);
|
edit = convertMentionsToLinks(edit);
|
||||||
edit = convertLinksToMarkdown(edit);
|
edit = convertLinksToMarkdown(edit);
|
||||||
edit = edit.trim();
|
edit = edit.trim();
|
||||||
|
|||||||
Reference in New Issue
Block a user