Skip to content

Commit 97b3fee

Browse files
committed
improves formatting
1 parent ccf58f7 commit 97b3fee

2 files changed

Lines changed: 8 additions & 14 deletions

File tree

pkg/api/models/botkube.libsonnet

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ local kind = if std.objectHas(data, "Kind") then data.Kind else "Resource";
77
local name = if std.objectHas(data, "Name") then data.Name else "unknown";
88
local level = if std.objectHas(data, "Level") then data.Level else "info";
99
local type = if std.objectHas(data, "Type") then data.Type else "event";
10-
local timestamp = if std.objectHas(data, "TimeStamp") then data.TimeStamp else "";
1110

1211
// Helper functions
1312
local formatLevel(level) =
@@ -41,20 +40,17 @@ local warningsSection = if hasWarnings then
4140
"\n\n⚠️ Warnings:\n" + std.join("\n", ["• " + warn for warn in data.Warnings])
4241
else "";
4342

44-
// Resource info
45-
local resourceInfo = "📦 " + kind + "/" + name + " in " + namespace + "@" + cluster;
43+
// Resource info - highlight the most important parts
44+
local resourceInfo = "📦 **" + kind + "/" + name + "** in **" + namespace + "**@" + cluster;
4645

4746
// Plain text format
4847
local plainTitle = formatLevel(level) + " Kubernetes " + formatType(type);
49-
local plainBody = resourceInfo +
50-
(if timestamp != "" then "\n🕐 " + timestamp else "") +
51-
messagesSection + recommendationsSection + warningsSection;
48+
local plainBody = resourceInfo + messagesSection + recommendationsSection + warningsSection;
5249

5350
// HTML format
5451
local htmlTitle = "<b>" + formatLevel(level) + " Kubernetes " + formatType(type) + "</b>";
55-
local htmlResourceInfo = "<code>" + kind + "/" + name + "</code> in <code>" + namespace + "@" + cluster + "</code>";
52+
local htmlResourceInfo = "📦 <b>" + kind + "/" + name + "</b> in <b>" + namespace + "</b>@<code>" + cluster + "</code>";
5653
local htmlBody = htmlResourceInfo +
57-
(if timestamp != "" then "<br/>🕐 <i>" + timestamp + "</i>" else "") +
5854
(if hasMessages then "<br/><br/><b>📋 Messages:</b><ul>" +
5955
std.join("", ["<li>" + msg + "</li>" for msg in data.Messages]) + "</ul>" else "") +
6056
(if hasRecommendations then "<br/><b>💡 Recommendations:</b><ul>" +

pkg/api/transformer_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,12 @@ func TestBotKubeWebHookMessage(t *testing.T) {
5454

5555
// Expected message with the improved schema
5656
expectedPlain := `✅ SUCCESS Kubernetes Created
57-
📦 Pod/nginx in default@David-Test
58-
🕐 2025-07-11T07:24:02Z
57+
📦 **Pod/nginx** in **default**@David-Test
5958
6059
💡 Recommendations:
6160
• The 'latest' tag used in 'nginx' image of Pod 'default/nginx' container 'nginx' should be avoided.`
6261

63-
expectedHtml := `<b>✅ SUCCESS Kubernetes Created</b><br/><code>Pod/nginx</code> in <code>default@David-Test</code><br/>🕐 <i>2025-07-11T07:24:02Z</i><br/><b>💡 Recommendations:</b><ul><li>The 'latest' tag used in 'nginx' image of Pod 'default/nginx' container 'nginx' should be avoided.</li></ul>`
62+
expectedHtml := `<b>✅ SUCCESS Kubernetes Created</b><br/>📦 <b>Pod/nginx</b> in <b>default</b>@<code>David-Test</code><br/><b>💡 Recommendations:</b><ul><li>The 'latest' tag used in 'nginx' image of Pod 'default/nginx' container 'nginx' should be avoided.</li></ul>`
6463

6564
assert.Equal(t, &MatrixMessage{
6665
Plain: expectedPlain,
@@ -75,13 +74,12 @@ func TestBotKubeErrorWebHookMessage(t *testing.T) {
7574

7675
// Expected message with the improved schema for error events
7776
expectedPlain := `🔴 ERROR Kubernetes Error
78-
📦 Pod/error-pod in default@development
79-
🕐 2025-07-26T18:40:25Z
77+
📦 **Pod/error-pod** in **default**@development
8078
8179
📋 Messages:
8280
• Failed to pull image "nonexistentimage:latest": failed to pull and unpack image "docker.io/library/nonexistentimage:latest": failed to resolve reference "docker.io/library/nonexistentimage:latest": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed`
8381

84-
expectedHtml := `<b>🔴 ERROR Kubernetes Error</b><br/><code>Pod/error-pod</code> in <code>default@development</code><br/>🕐 <i>2025-07-26T18:40:25Z</i><br/><br/><b>📋 Messages:</b><ul><li>Failed to pull image "nonexistentimage:latest": failed to pull and unpack image "docker.io/library/nonexistentimage:latest": failed to resolve reference "docker.io/library/nonexistentimage:latest": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed</li></ul>`
82+
expectedHtml := `<b>🔴 ERROR Kubernetes Error</b><br/>📦 <b>Pod/error-pod</b> in <b>default</b>@<code>development</code><br/><br/><b>📋 Messages:</b><ul><li>Failed to pull image "nonexistentimage:latest": failed to pull and unpack image "docker.io/library/nonexistentimage:latest": failed to resolve reference "docker.io/library/nonexistentimage:latest": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed</li></ul>`
8583

8684
assert.Equal(t, &MatrixMessage{
8785
Plain: expectedPlain,

0 commit comments

Comments
 (0)