Skip to content

Commit

Permalink
fix: trim commit messages to first line only.
Browse files Browse the repository at this point in the history
  • Loading branch information
outofcoffee committed Apr 30, 2023
1 parent 03cb951 commit 35ff3ce
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
13 changes: 12 additions & 1 deletion vcs/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,22 @@ func fetchCommitsAfter(repoPath string, tag string) ([]string, error) {
if c.Hash == afterTagCommit.Hash {
return storer.ErrStop
}
commitMessages = append(commitMessages, strings.TrimSpace(c.Message))
message := getShortMessage(c.Message)
commitMessages = append(commitMessages, message)
return nil
})
if err != nil {
return nil, err
}
return commitMessages, nil
}

func getShortMessage(message string) string {
var short string
if strings.Contains(message, "\n") {
short = strings.Split(message, "\n")[0]
} else {
short = message
}
return strings.TrimSpace(short)
}
36 changes: 36 additions & 0 deletions vcs/operations_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package vcs

import "testing"

func Test_getShortMessage(t *testing.T) {
type args struct {
message string
}
tests := []struct {
name string
args args
want string
}{
{
name: "short message",
args: args{
message: "long message\nwith multiple lines",
},
want: "long message",
},
{
name: "remove trailing newlines",
args: args{
message: "commit message\n\n",
},
want: "commit message",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getShortMessage(tt.args.message); got != tt.want {
t.Errorf("getShortMessage() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 35ff3ce

Please sign in to comment.