Skip to content

Commit

Permalink
fix: trim whitespace while validating DCO (#126)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira authored and andrewrynhard committed Jun 28, 2019
1 parent 57c9dbd commit 0af31f8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/policy/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func ValidateHeaderLength(report *policy.Report, msg string) {
// ValidateDCO checks the commit message for a Developer Certificate of Origin.
func ValidateDCO(report *policy.Report, msg string) {
for _, line := range strings.Split(msg, "\n") {
if DCORegex.MatchString(line) {
if DCORegex.MatchString(strings.TrimSpace(line)) {
return
}
}
Expand Down
42 changes: 42 additions & 0 deletions internal/policy/commit/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,48 @@ func TestConventionalCommitPolicy(t *testing.T) {
}
}

func TestValidateDCO(t *testing.T) {
type testDesc struct {
Name string
CommitMessage string
ExpectValid bool
}

for _, test := range []testDesc{
{
Name: "Valid DCO",
CommitMessage: "something nice\n\nSigned-off-by: Foo Bar <[email protected]>\n\n",
ExpectValid: true,
},
{
Name: "Valid DCO with CRLF",
CommitMessage: "something nice\r\n\r\nSigned-off-by: Foo Bar <[email protected]>\r\n\r\n",
ExpectValid: true,
},
{
Name: "No DCO",
CommitMessage: "something nice\n\nnot signed\n",
ExpectValid: false,
},
} {
t.Run(test.Name, func(tt *testing.T) {
var report policy.Report

ValidateDCO(&report, test.CommitMessage)

if test.ExpectValid {
if !report.Valid() {
tt.Error("Report is invalid with valid DCP")
}
} else {
if report.Valid() {
tt.Error("Report is valid with invalid DCO")
}
}
})
}
}

func runCompliance() *policy.Report {
c := &Commit{
Conventional: &Conventional{
Expand Down

0 comments on commit 0af31f8

Please sign in to comment.