mirror of
https://github.com/SethCohen/github-releases-to-discord
synced 2026-09-14 20:13:23 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7de2fd1c2a | ||
|
|
97a481333d |
@@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## [1.15.0](https://github.com/SethCohen/github-releases-to-discord/compare/v1.14.0...v1.15.0) (2023-12-14)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* added clip description at last newline ([#25](https://github.com/SethCohen/github-releases-to-discord/issues/25)) ([97a4813](https://github.com/SethCohen/github-releases-to-discord/commit/97a481333d0b902f599b12f03b47c4a6cbfa5e52))
|
||||
|
||||
## [1.14.0](https://github.com/SethCohen/github-releases-to-discord/compare/v1.13.1...v1.14.0) (2023-12-11)
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import fetch from 'node-fetch';
|
||||
|
||||
/**
|
||||
* Stylizes a markdown body into an appropriate embed message style.
|
||||
* Remove Carriage Return character to reduce size
|
||||
* Remove HTML comments (commonly added by 'Generate release notes' button)
|
||||
* Better URL linking for common Github links: PRs, Issues, Compare
|
||||
* Redundant whitespace and newlines removed, keeping at max 2 to provide space between paragraphs
|
||||
@@ -15,6 +16,7 @@ import fetch from 'node-fetch';
|
||||
*/
|
||||
const formatDescription = (description) => {
|
||||
let edit = description
|
||||
.replace(/\r/g, '')
|
||||
.replace(/<!--.*?-->/gs, '')
|
||||
.replace(
|
||||
new RegExp(
|
||||
@@ -94,21 +96,23 @@ function getContext () {
|
||||
*
|
||||
* @param {string} str
|
||||
* @param {number} maxLength
|
||||
* @param {string=} url
|
||||
* @param {string} [url]
|
||||
* @param {boolean} [clipAtLine=false]
|
||||
*/
|
||||
function limit(str, maxLength, url) {
|
||||
function limit(str, maxLength, url, clipAtLine) {
|
||||
clipAtLine ??= false
|
||||
if (str.length <= maxLength)
|
||||
return str
|
||||
let replacement = '…'
|
||||
let replacement = clipAtLine ? '\n…' : '…'
|
||||
if (url) {
|
||||
replacement = `([${replacement}](${url}))`
|
||||
replacement = `${clipAtLine ? '\n' : ''}([…](${url}))`
|
||||
}
|
||||
maxLength = maxLength - replacement.length
|
||||
str = str.substring(0, maxLength)
|
||||
|
||||
const lastWhitespace = str.search(/[^\s]*$/)
|
||||
if (lastWhitespace > -1) {
|
||||
str = str.substring(0, lastWhitespace)
|
||||
const lastNewline = str.search(new RegExp(`[^${clipAtLine ? '\n' : '\s'}]*$`))
|
||||
if (lastNewline > -1) {
|
||||
str = str.substring(0, lastNewline)
|
||||
}
|
||||
|
||||
return str + replacement
|
||||
@@ -147,7 +151,7 @@ async function run () {
|
||||
if (footerTimestamp == 'true') embedMsg.timestamp = new Date().toISOString();
|
||||
|
||||
let embedSize = embedMsg.title.length + (embedMsg.footer?.text?.length ?? 0)
|
||||
embedMsg.description = limit(embedMsg.description, Math.min(getMaxDescription(), 6000 - embedSize), embedMsg.url)
|
||||
embedMsg.description = limit(embedMsg.description, Math.min(getMaxDescription(), 6000 - embedSize), embedMsg.url, true)
|
||||
|
||||
let requestBody = {
|
||||
embeds: [embedMsg]
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "github-releases-to-discord",
|
||||
"version": "1.14.0",
|
||||
"version": "1.15.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "github-releases-to-discord",
|
||||
"version": "1.14.0",
|
||||
"version": "1.15.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "github-releases-to-discord",
|
||||
"version": "1.14.0",
|
||||
"version": "1.15.0",
|
||||
"description": "A GitHub Action that automatically sends a stylized Discord webhook of a GitHub Release description to a specified Discord channel.",
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
|
||||
Reference in New Issue
Block a user