fix(drift): fix SplitCodeBlocks line duplication and handle plain text messages#2634
Open
raman1236 wants to merge 1 commit intodiggerhq:developfrom
Open
fix(drift): fix SplitCodeBlocks line duplication and handle plain text messages#2634raman1236 wants to merge 1 commit intodiggerhq:developfrom
raman1236 wants to merge 1 commit intodiggerhq:developfrom
Conversation
…t messages SplitCodeBlocks had two bugs: 1. When a line caused the message to exceed Slack's 4000-char limit, the line was appended to both the closing chunk and the opening of the next chunk, causing content duplication in the notification. 2. Messages without code block markers (```) that exceeded 4000 chars were returned unsplit, causing the Slack API to reject them. Also fix SendErrorNotificationForProject to split long error messages through SplitCodeBlocks instead of sending them directly, matching the existing behavior of SendNotificationForProject. Fixes diggerhq#745
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #745 - Drift alerts in Slack > 4000 characters break formatting
Bugs Fixed
1. Line duplication in
SplitCodeBlocksWhen a line caused the accumulated message to exceed Slack's 4000-character limit, the splitting logic appended the triggering line to both the current chunk and the start of the next chunk:
This caused every line at a split boundary to appear twice in the Slack notification.
Fix: Close the current chunk cleanly without the triggering line, then start the new chunk with it:
2. Messages without code blocks skipped splitting
The function returned messages with fewer than 2
```markers unsplit, even when they exceeded 4000 characters. This caused the Slack API to reject them.Fix: Remove the early return and add a plain-text splitting path.
3.
SendErrorNotificationForProjectdidn't split messagesUnlike
SendNotificationForProject, the error notification method sent messages directly viaSendSlackMessagewithout going throughSplitCodeBlocks. Long error stack traces would be rejected by Slack.Fix: Use the same split-and-loop pattern.
Testing
Added 2 new unit tests:
TestSplitCodeBlocksNoLineDuplication— verifies no line appears in multiple parts after splittingTestSplitCodeBlocksPlainTextOver4000— verifies plain text messages > 4000 chars are splitAll existing tests continue to pass: