Skip to content

Commit

Permalink
Merge pull request #353 from berty/dev/moul/cleanup-commit-messages
Browse files Browse the repository at this point in the history
feat: cleanup commit messages
  • Loading branch information
moul authored Jun 19, 2020
2 parents 8b661ed + 063b4d1 commit 5236780
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
11 changes: 3 additions & 8 deletions go/pkg/yolopb/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go/pkg/yolopb/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ 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,
},
}
err := build.PrepareOutput("")
require.NoError(t, err)
assert.Equal(t, tt.expected, build.HasMergerequest.Message)
assert.Equal(t, tt.expected, build.Message)
})
}
}
19 changes: 19 additions & 0 deletions go/pkg/yolopb/util.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 5236780

Please sign in to comment.