forked from siderolabs/conform
-
Notifications
You must be signed in to change notification settings - Fork 0
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
b330410
commit e66888a
Showing
4 changed files
with
126 additions
and
24 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 |
---|---|---|
@@ -1,25 +1,26 @@ | ||
policies: | ||
- type: commit | ||
spec: | ||
headerLength: 89 | ||
dco: true | ||
gpg: false | ||
imperative: true | ||
conventional: | ||
types: | ||
- chore | ||
- docs | ||
- perf | ||
- refactor | ||
- style | ||
- test | ||
scopes: | ||
- policy | ||
- type: license | ||
spec: | ||
includeSuffixes: | ||
- .go | ||
header: | | ||
/* 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/. */ | ||
- type: commit | ||
spec: | ||
headerLength: 89 | ||
dco: true | ||
gpg: false | ||
imperative: true | ||
maximumOfOneCommit: true | ||
conventional: | ||
types: | ||
- chore | ||
- docs | ||
- perf | ||
- refactor | ||
- style | ||
- test | ||
scopes: | ||
- policy | ||
- type: license | ||
spec: | ||
includeSuffixes: | ||
- .go | ||
header: | | ||
/* 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/. */ |
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
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,57 @@ | ||
/* 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 ( | ||
"fmt" | ||
|
||
"github.com/autonomy/conform/internal/git" | ||
"github.com/autonomy/conform/internal/policy" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// NumberOfCommits enforces a maximum number of charcters on the commit | ||
// header. | ||
type NumberOfCommits struct { | ||
ref string | ||
ahead int | ||
errors []error | ||
} | ||
|
||
// Name returns the name of the check. | ||
func (h NumberOfCommits) Name() string { | ||
return "Number of Commits" | ||
} | ||
|
||
// Message returns to check message. | ||
func (h NumberOfCommits) Message() string { | ||
return fmt.Sprintf("HEAD is %d commit(s) ahead of %s", h.ahead, h.ref) | ||
} | ||
|
||
// Errors returns any violations of the check. | ||
func (h NumberOfCommits) Errors() []error { | ||
return h.errors | ||
} | ||
|
||
// ValidateNumberOfCommits checks the header length. | ||
func (c Commit) ValidateNumberOfCommits(g *git.Git, ref string) policy.Check { | ||
check := &NumberOfCommits{ | ||
ref: ref, | ||
} | ||
|
||
var err error | ||
check.ahead, _, err = g.AheadBehind(ref) | ||
if err != nil { | ||
check.errors = append(check.errors, err) | ||
return check | ||
} | ||
|
||
if check.ahead > 1 { | ||
check.errors = append(check.errors, errors.Errorf("HEAD is %d commit(s) ahead of %s", check.ahead, ref)) | ||
return check | ||
} | ||
|
||
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