diff --git a/go/pkg/yolopb/types.go b/go/pkg/yolopb/types.go index 89ae1669..290f83c1 100644 --- a/go/pkg/yolopb/types.go +++ b/go/pkg/yolopb/types.go @@ -2,16 +2,10 @@ package yolopb import ( "net/url" - "regexp" - "strings" "github.com/stretchr/signature" ) -var ( - signedOffByLine = regexp.MustCompile(`Signed-off-by: (.*)`) -) - // PrepareOutput adds new fields containing URLs with a signature and filters sensitive/useless data func (b *Build) PrepareOutput(salt string) error { for _, artifact := range b.HasArtifacts { @@ -20,9 +14,10 @@ func (b *Build) PrepareOutput(salt string) error { } } + // cleanup messages + b.Message = cleanupCommitMessage(b.Message) if b.HasMergerequest != nil { - b.HasMergerequest.Message = signedOffByLine.ReplaceAllString(b.HasMergerequest.Message, "") - b.HasMergerequest.Message = strings.TrimRight(b.HasMergerequest.Message, "\n") + b.HasMergerequest.Message = cleanupCommitMessage(b.HasMergerequest.Message) } return nil diff --git a/go/pkg/yolopb/types_test.go b/go/pkg/yolopb/types_test.go index 37b976e1..06a54868 100644 --- a/go/pkg/yolopb/types_test.go +++ b/go/pkg/yolopb/types_test.go @@ -21,6 +21,7 @@ func TestBuildPrepareOutput(t *testing.T) { for _, tt := range tests { t.Run(tt.msg, func(t *testing.T) { build := Build{ + Message: tt.msg, HasMergerequest: &MergeRequest{ Message: tt.msg, }, @@ -28,6 +29,7 @@ func TestBuildPrepareOutput(t *testing.T) { err := build.PrepareOutput("") require.NoError(t, err) assert.Equal(t, tt.expected, build.HasMergerequest.Message) + assert.Equal(t, tt.expected, build.Message) }) } } diff --git a/go/pkg/yolopb/util.go b/go/pkg/yolopb/util.go new file mode 100644 index 00000000..6cccb4dc --- /dev/null +++ b/go/pkg/yolopb/util.go @@ -0,0 +1,19 @@ +package yolopb + +import ( + "regexp" + "strings" +) + +var ( + signedOffByLine = regexp.MustCompile(`Signed-off-by: (.*)`) +) + +func cleanupCommitMessage(msg string) string { + if msg == "" { + return "" + } + msg = signedOffByLine.ReplaceAllString(msg, "") + msg = strings.TrimRight(msg, "\n") + return msg +}