-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.go
44 lines (36 loc) · 1.24 KB
/
release.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package rule
import (
"fmt"
"github.com/chavacava/changelog-lint/linting"
"github.com/chavacava/changelog-lint/model"
)
type Release struct{}
func (r Release) Apply(changes model.Changelog, failures chan linting.Failure, args linting.RuleArgs) {
if len(changes.Versions) < 1 {
msg := "at least one version required in release mode"
failures <- linting.Failure{RuleName: r.Name(), Message: msg, Position: 0}
return
}
wantVersion, ok := args.(string)
if !ok {
msg := fmt.Sprintf("expected release version argument to be a string, got %T instead", args)
failures <- linting.Failure{RuleName: r.Name(), Message: msg, Position: 0}
return
}
headVersion := changes.Versions[0]
gotVersion := headVersion.Version
if gotVersion != wantVersion {
msg := fmt.Sprintf("expected release version to be %s, got %s instead", wantVersion, gotVersion)
failures <- linting.Failure{RuleName: r.Name(), Message: msg, Position: headVersion.Position}
}
for _, version := range changes.Versions {
if version.Version == "Unreleased" {
msg := "version Unreleased forbidden in release mode"
failures <- linting.Failure{RuleName: r.Name(), Message: msg, Position: version.Position}
break
}
}
}
func (Release) Name() string {
return "release"
}