From ba7e672a462cf712924136f749bdfbfc7ee763b0 Mon Sep 17 00:00:00 2001 From: Alex Verkhovsky Date: Fri, 12 Dec 2025 21:23:05 -0700 Subject: [PATCH] chore(discord): suppress link embeds and handle truncated URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add wrap_urls() to wrap URLs in <> to suppress Discord embeds - Add strip_trailing_url() to remove partial URLs from truncated text - Update all 6 workflow jobs with body text to use the new helpers - Partial URLs (from truncation) are removed since they are unusable - Complete URLs are wrapped to prevent large embed previews 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .github/scripts/discord-helpers.sh | 6 +++++ .github/workflows/discord.yaml | 36 +++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/.github/scripts/discord-helpers.sh b/.github/scripts/discord-helpers.sh index 191b9037..b0ad015d 100644 --- a/.github/scripts/discord-helpers.sh +++ b/.github/scripts/discord-helpers.sh @@ -13,3 +13,9 @@ trunc() { [ "$spaces" -lt 3 ] && [ ${#txt} -gt 80 ] && txt=$(printf '%s' "$txt" | cut -c1-80) printf '%s' "$txt" } + +# Remove partial URL at end of truncated text (partial URLs are useless) +strip_trailing_url() { sed -E 's~ to suppress Discord embeds (keeps links clickable) +wrap_urls() { sed -E 's~https?://[^[:space:]<>]+~<&>~g'; } diff --git a/.github/workflows/discord.yaml b/.github/workflows/discord.yaml index 109bbb16..fdab1d70 100644 --- a/.github/workflows/discord.yaml +++ b/.github/workflows/discord.yaml @@ -53,7 +53,11 @@ jobs: TITLE=$(printf '%s' "$PR_TITLE" | trunc $MAX_TITLE | esc) [ ${#PR_TITLE} -gt $MAX_TITLE ] && TITLE="${TITLE}..." - BODY=$(printf '%s' "$PR_BODY" | trunc $MAX_BODY | esc) + BODY=$(printf '%s' "$PR_BODY" | trunc $MAX_BODY) + if [ -n "$PR_BODY" ] && [ ${#PR_BODY} -gt $MAX_BODY ]; then + BODY=$(printf '%s' "$BODY" | strip_trailing_url) + fi + BODY=$(printf '%s' "$BODY" | esc | wrap_urls) [ -n "$PR_BODY" ] && [ ${#PR_BODY} -gt $MAX_BODY ] && BODY="${BODY}..." [ -n "$BODY" ] && BODY=" · $BODY" USER=$(printf '%s' "$PR_USER" | esc) @@ -91,7 +95,11 @@ jobs: TITLE=$(printf '%s' "$ISSUE_TITLE" | trunc $MAX_TITLE | esc) [ ${#ISSUE_TITLE} -gt $MAX_TITLE ] && TITLE="${TITLE}..." - BODY=$(printf '%s' "$ISSUE_BODY" | trunc $MAX_BODY | esc) + BODY=$(printf '%s' "$ISSUE_BODY" | trunc $MAX_BODY) + if [ -n "$ISSUE_BODY" ] && [ ${#ISSUE_BODY} -gt $MAX_BODY ]; then + BODY=$(printf '%s' "$BODY" | strip_trailing_url) + fi + BODY=$(printf '%s' "$BODY" | esc | wrap_urls) [ -n "$ISSUE_BODY" ] && [ ${#ISSUE_BODY} -gt $MAX_BODY ] && BODY="${BODY}..." [ -n "$BODY" ] && BODY=" · $BODY" USER=$(printf '%s' "$USER" | esc) @@ -126,7 +134,11 @@ jobs: TITLE=$(printf '%s' "$ISSUE_TITLE" | trunc $MAX_TITLE | esc) [ ${#ISSUE_TITLE} -gt $MAX_TITLE ] && TITLE="${TITLE}..." - BODY=$(printf '%s' "$COMMENT_BODY" | trunc $MAX_BODY | esc) + BODY=$(printf '%s' "$COMMENT_BODY" | trunc $MAX_BODY) + if [ ${#COMMENT_BODY} -gt $MAX_BODY ]; then + BODY=$(printf '%s' "$BODY" | strip_trailing_url) + fi + BODY=$(printf '%s' "$BODY" | esc | wrap_urls) [ ${#COMMENT_BODY} -gt $MAX_BODY ] && BODY="${BODY}..." USER=$(printf '%s' "$COMMENT_USER" | esc) @@ -162,7 +174,11 @@ jobs: TITLE=$(printf '%s' "$PR_TITLE" | trunc $MAX_TITLE | esc) [ ${#PR_TITLE} -gt $MAX_TITLE ] && TITLE="${TITLE}..." - BODY=$(printf '%s' "$REVIEW_BODY" | trunc $MAX_BODY | esc) + BODY=$(printf '%s' "$REVIEW_BODY" | trunc $MAX_BODY) + if [ -n "$REVIEW_BODY" ] && [ ${#REVIEW_BODY} -gt $MAX_BODY ]; then + BODY=$(printf '%s' "$BODY" | strip_trailing_url) + fi + BODY=$(printf '%s' "$BODY" | esc | wrap_urls) [ -n "$REVIEW_BODY" ] && [ ${#REVIEW_BODY} -gt $MAX_BODY ] && BODY="${BODY}..." [ -n "$BODY" ] && BODY=": $BODY" USER=$(printf '%s' "$REVIEW_USER" | esc) @@ -194,7 +210,11 @@ jobs: TITLE=$(printf '%s' "$PR_TITLE" | trunc $MAX_TITLE | esc) [ ${#PR_TITLE} -gt $MAX_TITLE ] && TITLE="${TITLE}..." - BODY=$(printf '%s' "$COMMENT_BODY" | trunc $MAX_BODY | esc) + BODY=$(printf '%s' "$COMMENT_BODY" | trunc $MAX_BODY) + if [ ${#COMMENT_BODY} -gt $MAX_BODY ]; then + BODY=$(printf '%s' "$BODY" | strip_trailing_url) + fi + BODY=$(printf '%s' "$BODY" | esc | wrap_urls) [ ${#COMMENT_BODY} -gt $MAX_BODY ] && BODY="${BODY}..." USER=$(printf '%s' "$COMMENT_USER" | esc) @@ -224,7 +244,11 @@ jobs: REL_NAME=$(printf '%s' "$NAME" | trunc $MAX_TITLE | esc) [ ${#NAME} -gt $MAX_TITLE ] && REL_NAME="${REL_NAME}..." - BODY=$(printf '%s' "$RELEASE_BODY" | trunc $MAX_BODY | esc) + BODY=$(printf '%s' "$RELEASE_BODY" | trunc $MAX_BODY) + if [ -n "$RELEASE_BODY" ] && [ ${#RELEASE_BODY} -gt $MAX_BODY ]; then + BODY=$(printf '%s' "$BODY" | strip_trailing_url) + fi + BODY=$(printf '%s' "$BODY" | esc | wrap_urls) [ -n "$RELEASE_BODY" ] && [ ${#RELEASE_BODY} -gt $MAX_BODY ] && BODY="${BODY}..." [ -n "$BODY" ] && BODY=" · $BODY" TAG_ESC=$(printf '%s' "$TAG" | esc)