diff --git a/pkg/message.go b/pkg/message.go index 08b28f94..c2b1d0ca 100644 --- a/pkg/message.go +++ b/pkg/message.go @@ -146,7 +146,7 @@ func buildComment(ctx context.Context, apps map[string]*AppResults) string { sb.WriteString("\n\n") sb.WriteString(fmt.Sprintf("## ArgoCD Application Checks: `%s` %s\n", appName, appState.Emoji())) sb.WriteString("\n\n") - sb.WriteString(strings.Join(checkStrings, "---\n")) + sb.WriteString(strings.Join(checkStrings, "\n\n---\n\n")) sb.WriteString("") } diff --git a/pkg/message_test.go b/pkg/message_test.go index af7d2de5..3d6fa9eb 100644 --- a/pkg/message_test.go +++ b/pkg/message_test.go @@ -2,6 +2,7 @@ package pkg import ( "context" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -92,3 +93,61 @@ func TestMessageIsSuccess(t *testing.T) { }) } } + +func TestMultipleItemsWithNewlines(t *testing.T) { + var ( + message = NewMessage("name", 1, 2) + ctx = context.Background() + ) + message.AddNewApp(ctx, "first-app") + message.AddToAppMessage(ctx, "first-app", CheckResult{ + State: StateSuccess, + Summary: "summary-1", + Details: "detail-1", + }) + message.AddToAppMessage(ctx, "first-app", CheckResult{ + State: StateSuccess, + Summary: "summary-2", + Details: "detail-2", + }) + message.AddNewApp(ctx, "second-app") + message.AddToAppMessage(ctx, "second-app", CheckResult{ + State: StateSuccess, + Summary: "summary-1", + Details: "detail-1", + }) + message.AddToAppMessage(ctx, "second-app", CheckResult{ + State: StateSuccess, + Summary: "summary-2", + Details: "detail-2", + }) + result := message.BuildComment(ctx) + + // header rows need double newlines before and after + index := 0 + newline := uint8('\n') + for { + index++ + foundAt := strings.Index(result[index:], "---") + if foundAt == -1 { + break // couldn't be found, we're done + } + index += foundAt + + if index < 2 { + continue // hyphens are at the beginning of the string, we're fine + } + + if result[index-1] == '-' || result[index+3] == '-' { + continue // not a triple-hyphen, but a more-than-triple-hyphen, move on + } + + // must be preceded by two newlines + assert.Equal(t, newline, result[index-1]) + assert.Equal(t, newline, result[index-2]) + + // must be followed by two newlines + assert.Equal(t, newline, result[index+3]) + assert.Equal(t, newline, result[index+4]) + } +}