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
|
# 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)
|
## [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.
|
* 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)
|
* Remove HTML comments (commonly added by 'Generate release notes' button)
|
||||||
* Better URL linking for common Github links: PRs, Issues, Compare
|
* Better URL linking for common Github links: PRs, Issues, Compare
|
||||||
* Redundant whitespace and newlines removed, keeping at max 2 to provide space between paragraphs
|
* 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) => {
|
const formatDescription = (description) => {
|
||||||
let edit = description
|
let edit = description
|
||||||
|
.replace(/\r/g, '')
|
||||||
.replace(/<!--.*?-->/gs, '')
|
.replace(/<!--.*?-->/gs, '')
|
||||||
.replace(
|
.replace(
|
||||||
new RegExp(
|
new RegExp(
|
||||||
@@ -94,21 +96,23 @@ function getContext () {
|
|||||||
*
|
*
|
||||||
* @param {string} str
|
* @param {string} str
|
||||||
* @param {number} maxLength
|
* @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)
|
if (str.length <= maxLength)
|
||||||
return str
|
return str
|
||||||
let replacement = '…'
|
let replacement = clipAtLine ? '\n…' : '…'
|
||||||
if (url) {
|
if (url) {
|
||||||
replacement = `([${replacement}](${url}))`
|
replacement = `${clipAtLine ? '\n' : ''}([…](${url}))`
|
||||||
}
|
}
|
||||||
maxLength = maxLength - replacement.length
|
maxLength = maxLength - replacement.length
|
||||||
str = str.substring(0, maxLength)
|
str = str.substring(0, maxLength)
|
||||||
|
|
||||||
const lastWhitespace = str.search(/[^\s]*$/)
|
const lastNewline = str.search(new RegExp(`[^${clipAtLine ? '\n' : '\s'}]*$`))
|
||||||
if (lastWhitespace > -1) {
|
if (lastNewline > -1) {
|
||||||
str = str.substring(0, lastWhitespace)
|
str = str.substring(0, lastNewline)
|
||||||
}
|
}
|
||||||
|
|
||||||
return str + replacement
|
return str + replacement
|
||||||
@@ -147,7 +151,7 @@ async function run () {
|
|||||||
if (footerTimestamp == 'true') embedMsg.timestamp = new Date().toISOString();
|
if (footerTimestamp == 'true') embedMsg.timestamp = new Date().toISOString();
|
||||||
|
|
||||||
let embedSize = embedMsg.title.length + (embedMsg.footer?.text?.length ?? 0)
|
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 = {
|
let requestBody = {
|
||||||
embeds: [embedMsg]
|
embeds: [embedMsg]
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "github-releases-to-discord",
|
"name": "github-releases-to-discord",
|
||||||
"version": "1.14.0",
|
"version": "1.15.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "github-releases-to-discord",
|
"name": "github-releases-to-discord",
|
||||||
"version": "1.14.0",
|
"version": "1.15.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.10.1",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "github-releases-to-discord",
|
"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.",
|
"description": "A GitHub Action that automatically sends a stylized Discord webhook of a GitHub Release description to a specified Discord channel.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
|||||||
Reference in New Issue
Block a user