diff --git a/bitrise.yml b/bitrise.yml index a5125e6..c252909 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -72,10 +72,10 @@ workflows: #!/bin/bash set -ex - multi_line_msg="Multi\nline\n\ntext" + multi_line_msg="Multiline, with a link: https://www.bitrise.io, \n _some_ *highlight*, \n and linkify @slackbot #random" envman add --key SLACK_MESSAGE_FROM_SCRIPT --value "$multi_line_msg" - path::./: - title: Should escape backslash+n as newline char + title: Should escape backslash+n as newline char + custom multiline release notes field is_skippable: false inputs: - webhook_url: $SLACK_WEBHOOK_URL @@ -83,6 +83,11 @@ workflows: - channel: $SLACK_CHANNEL - from_username: step-dev-test - message: $SLACK_MESSAGE_FROM_SCRIPT + - fields: | + Release notes|${SLACK_MESSAGE_FROM_SCRIPT} + App|${BITRISE_APP_TITLE} + Branch|${BITRISE_GIT_BRANCH} + Workflow|${BITRISE_TRIGGERED_WORKFLOW_ID} fail-message-test: steps: - script: diff --git a/message.go b/message.go index 5440cc8..f43f37a 100644 --- a/message.go +++ b/message.go @@ -130,7 +130,7 @@ func (f Field) MarshalJSON() ([]byte, error) { func parseFields(s string) (fs []Field) { for _, p := range pairs(s) { - fs = append(fs, Field{Title: p[0], Value: p[1]}) + fs = append(fs, Field{Title: p[0], Value: ensureNewlines(p[1])}) } return } diff --git a/message_test.go b/message_test.go new file mode 100644 index 0000000..46b08b0 --- /dev/null +++ b/message_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "reflect" + "testing" +) + +func Test_parseFields(t *testing.T) { + tests := []struct { + name string + s string + wantFs []Field + }{ + { + name: "Newline in release notes", + s: "Release notes|line1\\nline2", + wantFs: []Field{{Title: "Release notes", Value: "line1\nline2"}}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if gotFs := parseFields(tt.s); !reflect.DeepEqual(gotFs, tt.wantFs) { + t.Errorf("parseFields() = %v, want %v", gotFs, tt.wantFs) + } + }) + } +} diff --git a/step.yml b/step.yml index d117210..00a7caf 100644 --- a/step.yml +++ b/step.yml @@ -332,10 +332,13 @@ inputs: description: | Fields separated by newlines and each field contains a `title` and a `value`. The `title` and the `value` fields are separated by a pipe `|` character. - Empty lines and lines without a separator are omitted. The *title* shown as a bold heading above the `value` text. The *value* is the text value of the field. + + Supports multiline text with escaped newlines. Example: `Release notes| - Line1 \n -Line2`. + + Empty lines and lines without a separator are omitted. - buttons: | View App|${BITRISE_APP_URL} View Build|${BITRISE_BUILD_URL}