Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 87 additions & 45 deletions .github/workflows/pr-comment-slack-notify.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PR Comment Slack Notification
name: PR Slack Notification

on:
pull_request:
Expand Down Expand Up @@ -116,55 +116,97 @@ jobs:
# Comment event — try to find existing thread, then reply in it
THREAD_TS=$(find_thread_ts)

# Truncate comment body to 200 chars
if [ ${#COMMENT_BODY} -gt 200 ]; then
TRUNCATED_BODY="${COMMENT_BODY:0:200}..."
# Clean comment body:
# 1. Remove HTML comments (<!-- ... -->)
# 2. Remove GitHub admonitions (> [!TIP], > [!NOTE], etc. and their continuation lines)
# 3. Trim leading/trailing whitespace
CLEANED_BODY=$(echo "$COMMENT_BODY" | perl -0777 -pe '
s/<!--.*?-->//gs;
s/^>\s*\[!(TIP|NOTE|WARNING|CAUTION|IMPORTANT)\]\s*\n(^>.*\n)*//gm;
s/^\s+|\s+$//g;
')

# Truncate to 200 chars
if [ ${#CLEANED_BODY} -gt 200 ]; then
TRUNCATED_BODY="${CLEANED_BODY:0:200}..."
else
TRUNCATED_BODY="$COMMENT_BODY"
TRUNCATED_BODY="$CLEANED_BODY"
fi
Comment on lines +119 to 134
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Truncation exceeds the stated 200‑char limit.
The ellipsis makes the output 203 chars. Either adjust the slice or update the comment to match intent.

Suggested fix (cap at 200 including ellipsis)
-            # Truncate to 200 chars
-            if [ ${`#CLEANED_BODY`} -gt 200 ]; then
-              TRUNCATED_BODY="${CLEANED_BODY:0:200}..."
+            # Truncate to 200 chars including ellipsis
+            if [ ${`#CLEANED_BODY`} -gt 200 ]; then
+              TRUNCATED_BODY="${CLEANED_BODY:0:197}..."
             else
               TRUNCATED_BODY="$CLEANED_BODY"
             fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Clean comment body:
# 1. Remove HTML comments (<!-- ... -->)
# 2. Remove GitHub admonitions (> [!TIP], > [!NOTE], etc. and their continuation lines)
# 3. Trim leading/trailing whitespace
CLEANED_BODY=$(echo "$COMMENT_BODY" | perl -0777 -pe '
s/<!--.*?-->//gs;
s/^>\s*\[!(TIP|NOTE|WARNING|CAUTION|IMPORTANT)\]\s*\n(^>.*\n)*//gm;
s/^\s+|\s+$//g;
')
# Truncate to 200 chars
if [ ${#CLEANED_BODY} -gt 200 ]; then
TRUNCATED_BODY="${CLEANED_BODY:0:200}..."
else
TRUNCATED_BODY="$COMMENT_BODY"
TRUNCATED_BODY="$CLEANED_BODY"
fi
# Clean comment body:
# 1. Remove HTML comments (<!-- ... -->)
# 2. Remove GitHub admonitions (> [!TIP], > [!NOTE], etc. and their continuation lines)
# 3. Trim leading/trailing whitespace
CLEANED_BODY=$(echo "$COMMENT_BODY" | perl -0777 -pe '
s/<!--.*?-->//gs;
s/^>\s*\[!(TIP|NOTE|WARNING|CAUTION|IMPORTANT)\]\s*\n(^>.*\n)*//gm;
s/^\s+|\s+$//g;
')
# Truncate to 200 chars including ellipsis
if [ ${`#CLEANED_BODY`} -gt 200 ]; then
TRUNCATED_BODY="${CLEANED_BODY:0:197}..."
else
TRUNCATED_BODY="$CLEANED_BODY"
fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/pr-comment-slack-notify.yml around lines 119 - 134, The
truncation logic currently slices CLEANED_BODY to 200 then appends "..." so
TRUNCATED_BODY can be 203 chars; update the truncation to ensure the final
string is at most 200 chars by slicing to 197 before appending the ellipsis (or
alternatively slice to 200 and do not append ellipsis). Modify the block that
sets TRUNCATED_BODY (references CLEANED_BODY and TRUNCATED_BODY) so the
conditional uses ${`#CLEANED_BODY`} -gt 200 and then sets
TRUNCATED_BODY="${CLEANED_BODY:0:197}..." to guarantee a 200-char max, or
implement an equivalent approach (e.g., printf %.200s) that ensures the
ellipsis-inclusive output never exceeds 200 chars.


PAYLOAD=$(jq -n \
--arg channel "$SLACK_CHANNEL_ID" \
--arg repo_short "$REPO_SHORT" \
--arg pr_url "$PR_URL" \
--arg pr_number "$PR_NUMBER" \
--arg pr_title "$PR_TITLE" \
--arg commenter "$COMMENTER" \
--arg comment_body "$TRUNCATED_BODY" \
--arg comment_url "$COMMENT_URL" \
--arg avatar "$COMMENTER_AVATAR" \
--arg thread_ts "$THREAD_TS" \
'{
"channel": $channel,
"username": $commenter,
"icon_url": $avatar,
"text": ($commenter + " commented on [" + $repo_short + "#" + $pr_number + "] <" + $pr_url + "|" + $pr_title + ">"),
"unfurl_links": false,
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ($commenter + " commented on [" + $repo_short + "#" + $pr_number + "] <" + $pr_url + "|" + $pr_title + ">")
if [ -n "$THREAD_TS" ]; then
# Thread reply — just show the comment text, no header
PAYLOAD=$(jq -n \
--arg channel "$SLACK_CHANNEL_ID" \
--arg commenter "$COMMENTER" \
--arg comment_body "$TRUNCATED_BODY" \
--arg avatar "$COMMENTER_AVATAR" \
--arg thread_ts "$THREAD_TS" \
'{
"channel": $channel,
"username": $commenter,
"icon_url": $avatar,
"thread_ts": $thread_ts,
"text": $comment_body,
"unfurl_links": false,
"blocks": [
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_quote",
"elements": [
{
"type": "text",
"text": $comment_body
}
]
}
]
}
},
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_quote",
"elements": [
{
"type": "text",
"text": $comment_body
}
]
]
}')
else
# No thread found — post top-level with full context
PAYLOAD=$(jq -n \
--arg channel "$SLACK_CHANNEL_ID" \
--arg repo_short "$REPO_SHORT" \
--arg pr_url "$PR_URL" \
--arg pr_number "$PR_NUMBER" \
--arg pr_title "$PR_TITLE" \
--arg commenter "$COMMENTER" \
--arg comment_body "$TRUNCATED_BODY" \
--arg avatar "$COMMENTER_AVATAR" \
'{
"channel": $channel,
"username": $commenter,
"icon_url": $avatar,
"text": ($commenter + " commented on [" + $repo_short + "#" + $pr_number + "] <" + $pr_url + "|" + $pr_title + ">"),
"unfurl_links": false,
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ($commenter + " commented on [" + $repo_short + "#" + $pr_number + "] <" + $pr_url + "|" + $pr_title + ">")
}
]
}
]
}
| if $thread_ts != "" then .thread_ts = $thread_ts else . end')
},
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_quote",
"elements": [
{
"type": "text",
"text": $comment_body
}
]
}
]
}
]
}')
fi

curl -s -X POST "https://slack.com/api/chat.postMessage" \
-H "Authorization: Bearer $SLACK_BOT_TOKEN" \
Expand Down