-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render plain text for messages sent in attachments and remove the header #773
Merged
Merged
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
50bfe80
Slack bot now uploads a long msg as a plaintext file with a related d…
ezodude bad1598
Added interactive message to plaintext tests.
ezodude 0063ebb
Long SocketSlack interactive messages now sent as message and file up…
ezodude 0fbca32
Clean up.
ezodude d24cb59
Discore and MatterMost long messages now uploaded with a message and …
ezodude 861ae64
MatterMost message response field no longer used.
ezodude bf561f3
MS Teams long messages now uploaded as a plaintext file.
ezodude f88fc01
Added E2E test to verify large output is received as plaintext file w…
ezodude 8907fef
Fixed unit tests.
ezodude 2fcbd98
For MS Teams we may need to force markdown regardless of outgoing mes…
ezodude ffe6e18
Merge branch 'main' into render-plain
huseyinbabal a6eda16
Merge branch 'main' into render-plain
ezodude fa751ad
Remove description messages and attach cmd description to actual uplo…
ezodude ef7d01c
Factor out max message size to consts.
ezodude 819f545
Merge branch 'main' into render-plain
ezodude 3c0cfb7
Fix incorrect spacing in helm services template.
ezodude acddc90
Generalised Markdown formatting to be used for plaintext formatting.
ezodude ee3c269
Linter fixes.
ezodude 7c9419d
Merge branch 'main' into render-plain
ezodude 5b16bbc
Update test golden text to match the latest from main.
ezodude f7691d3
Remove dead code.
ezodude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package interactive | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// NewlineFormatter adds new line formatting. | ||
func NewlineFormatter(msg string) string { | ||
return fmt.Sprintf("%s\n", msg) | ||
} | ||
|
||
// MdHeaderFormatter adds Markdown header formatting. | ||
func MdHeaderFormatter(msg string) string { | ||
return fmt.Sprintf("**%s**", msg) | ||
} | ||
|
||
// NoFormatting does not apply any formatting. | ||
func NoFormatting(msg string) string { | ||
return msg | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package interactive | ||
|
||
// MessageToPlaintext returns interactive message as a plaintext. | ||
func MessageToPlaintext(msg Message, newlineFormatter func(in string) string) string { | ||
mszostok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
msg.Description = "" | ||
|
||
fmt := MDFormatter{ | ||
newlineFormatter: newlineFormatter, | ||
headerFormatter: NoFormatting, | ||
codeBlockFormatter: NoFormatting, | ||
adaptiveCodeBlockFormatter: NoFormatting, | ||
} | ||
return RenderMessage(fmt, msg) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package interactive | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"gotest.tools/v3/assert" | ||
"gotest.tools/v3/golden" | ||
) | ||
|
||
// go test -run=TestInteractiveMessageToMarkdownMultiSelect ./pkg/bot/interactive/... -test.update-golden | ||
func TestInteractiveMessageToPlaintextMultiSelect(t *testing.T) { | ||
// given | ||
message := Message{ | ||
Base: Base{ | ||
Header: "Adjust notifications", | ||
Description: "Adjust notifications description", | ||
}, | ||
|
||
Sections: []Section{ | ||
{ | ||
MultiSelect: MultiSelect{ | ||
Name: "Adjust notifications", | ||
Description: Body{ | ||
Plaintext: "Select notification sources", | ||
}, | ||
Command: "@BotKube edit SourceBindings", | ||
Options: []OptionItem{ | ||
{ | ||
Name: "K8s all events", | ||
Value: "k8s-all-events", | ||
}, | ||
{ | ||
Name: "K8s recommendations", | ||
Value: "k8s-recommendations", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
// when | ||
out := MessageToPlaintext(message, NewlineFormatter) | ||
|
||
// then | ||
golden.Assert(t, out, fmt.Sprintf("%s.golden.txt", t.Name())) | ||
} | ||
|
||
// go test -run=TestInteractiveMessageToMarkdown ./pkg/bot/interactive/... -test.update-golden | ||
func TestInteractiveMessageToPlaintext(t *testing.T) { | ||
customNewlineFormatter := func(msg string) string { | ||
return fmt.Sprintf("%s\r\n", msg) | ||
} | ||
|
||
// given | ||
help := Help("platform", "testing", "@BotKube") | ||
|
||
// when | ||
out := MessageToPlaintext(help, customNewlineFormatter) | ||
|
||
// then | ||
assert.Assert(t, golden.String(out, fmt.Sprintf("%s.golden.txt", t.Name()))) | ||
} |
39 changes: 39 additions & 0 deletions
39
pkg/bot/interactive/testdata/TestInteractiveMessageToPlaintext.golden.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
Using multiple instances | ||
If you are running multiple BotKube instances in the same channel to interact with testing, make sure to specify the cluster name when typing commands. | ||
--cluster-name="testing" | ||
|
||
|
||
Manage incoming notifications | ||
@BotKube notifier [start|stop|status] | ||
|
||
- @BotKube notifier start | ||
- @BotKube notifier stop | ||
- @BotKube notifier status | ||
|
||
Notification settings for this channel | ||
By default, BotKube will notify only about cluster errors and recommendations. | ||
- @BotKube edit SourceBindings | ||
|
||
Ping your cluster | ||
Check the status of connected Kubernetes cluster(s). | ||
- @BotKube ping | ||
|
||
Run kubectl commands (if enabled) | ||
You can run kubectl commands directly from Platform! | ||
- @BotKube get services | ||
- @BotKube get pods | ||
- @BotKube get deployments | ||
|
||
To list all supported kubectl commands | ||
- @BotKube commands list | ||
|
||
Filters (advanced) | ||
You can extend BotKube functionality by writing additional filters that can check resource specs, validate some checks and add messages to the Event struct. Learn more at https://botkube.io/filters | ||
|
||
Angry? Amazed? | ||
Give feedback: https://feedback.botkube.io | ||
|
||
Read our docs: https://botkube.io/docs | ||
Join our Slack: https://join.botkube.io | ||
Follow us on Twitter: https://twitter.com/botkube_io |
7 changes: 7 additions & 0 deletions
7
pkg/bot/interactive/testdata/TestInteractiveMessageToPlaintextMultiSelect.golden.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Adjust notifications | ||
|
||
Select notification sources | ||
|
||
Available options: | ||
- k8s-all-events | ||
- k8s-recommendations |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove it :)