-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andrew Rynhard <andrew@andrewrynhard.com>
- Loading branch information
1 parent
e66888a
commit adce353
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package commit | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/autonomy/conform/internal/policy" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// RequiredBodyThreshold is the default minimum number of line changes required | ||
// to trigger the body check. | ||
var RequiredBodyThreshold = 10 | ||
|
||
// Body enforces a maximum number of charcters on the commit | ||
// header. | ||
type Body struct { | ||
errors []error | ||
} | ||
|
||
// Name returns the name of the check. | ||
func (h Body) Name() string { | ||
return "Commit Body" | ||
} | ||
|
||
// Message returns to check message. | ||
func (h Body) Message() string { | ||
return "Commit body is valid" | ||
} | ||
|
||
// Errors returns any violations of the check. | ||
func (h Body) Errors() []error { | ||
return h.errors | ||
} | ||
|
||
// ValidateBody checks the header length. | ||
func (c Commit) ValidateBody() policy.Check { | ||
check := &Body{} | ||
|
||
if c.HeaderLength != 0 { | ||
MaxNumberOfCommitCharacters = c.HeaderLength | ||
} | ||
|
||
lines := strings.Split(strings.TrimPrefix(c.msg, "\n"), "\n") | ||
valid := false | ||
for _, line := range lines[1:] { | ||
if DCORegex.MatchString(strings.TrimSpace(line)) { | ||
continue | ||
} | ||
if line != "" { | ||
valid = true | ||
break | ||
} | ||
} | ||
|
||
if !valid { | ||
check.errors = append(check.errors, errors.New("Commit body is empty")) | ||
} | ||
|
||
return check | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters