Skip to content

Commit b38da23

Browse files
[SWAT-595] Add support for multiline Field values (#85)
* Support multiline fields with escaped newlines * Added e2e test for multiline field * Update input description * Added unit test Co-authored-by: Laszlo Pusok <[email protected]>
1 parent 29c0977 commit b38da23

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

bitrise.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,22 @@ workflows:
7272
#!/bin/bash
7373
set -ex
7474
75-
multi_line_msg="Multi\nline\n\ntext"
75+
multi_line_msg="Multiline, with a link: https://www.bitrise.io, \n _some_ *highlight*, \n and linkify @slackbot #random"
7676
envman add --key SLACK_MESSAGE_FROM_SCRIPT --value "$multi_line_msg"
7777
- path::./:
78-
title: Should escape backslash+n as newline char
78+
title: Should escape backslash+n as newline char + custom multiline release notes field
7979
is_skippable: false
8080
inputs:
8181
- webhook_url: $SLACK_WEBHOOK_URL
8282
- api_token: $SLACK_API_TOKEN
8383
- channel: $SLACK_CHANNEL
8484
- from_username: step-dev-test
8585
- message: $SLACK_MESSAGE_FROM_SCRIPT
86+
- fields: |
87+
Release notes|${SLACK_MESSAGE_FROM_SCRIPT}
88+
App|${BITRISE_APP_TITLE}
89+
Branch|${BITRISE_GIT_BRANCH}
90+
Workflow|${BITRISE_TRIGGERED_WORKFLOW_ID}
8691
fail-message-test:
8792
steps:
8893
- script:

message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (f Field) MarshalJSON() ([]byte, error) {
130130

131131
func parseFields(s string) (fs []Field) {
132132
for _, p := range pairs(s) {
133-
fs = append(fs, Field{Title: p[0], Value: p[1]})
133+
fs = append(fs, Field{Title: p[0], Value: ensureNewlines(p[1])})
134134
}
135135
return
136136
}

message_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func Test_parseFields(t *testing.T) {
9+
tests := []struct {
10+
name string
11+
s string
12+
wantFs []Field
13+
}{
14+
{
15+
name: "Newline in release notes",
16+
s: "Release notes|line1\\nline2",
17+
wantFs: []Field{{Title: "Release notes", Value: "line1\nline2"}},
18+
},
19+
}
20+
for _, tt := range tests {
21+
t.Run(tt.name, func(t *testing.T) {
22+
if gotFs := parseFields(tt.s); !reflect.DeepEqual(gotFs, tt.wantFs) {
23+
t.Errorf("parseFields() = %v, want %v", gotFs, tt.wantFs)
24+
}
25+
})
26+
}
27+
}

step.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,13 @@ inputs:
332332
description: |
333333
Fields separated by newlines and each field contains a `title` and a `value`.
334334
The `title` and the `value` fields are separated by a pipe `|` character.
335-
Empty lines and lines without a separator are omitted.
336335
337336
The *title* shown as a bold heading above the `value` text.
338337
The *value* is the text value of the field.
338+
339+
Supports multiline text with escaped newlines. Example: `Release notes| - Line1 \n -Line2`.
340+
341+
Empty lines and lines without a separator are omitted.
339342
- buttons: |
340343
View App|${BITRISE_APP_URL}
341344
View Build|${BITRISE_BUILD_URL}

0 commit comments

Comments
 (0)