• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mindersec / minder / 24734181615

21 Apr 2026 04:31PM UTC coverage: 60.248%. First build
24734181615

Pull #6388

github

web-flow
Merge c80084f3f into fef41377a
Pull Request #6388: feat(engine): add commit-level evaluation primitives with ordered multi-commit support

49 of 51 new or added lines in 1 file covered. (96.08%)

20273 of 33649 relevant lines covered (60.25%)

35.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.08
/internal/engine/commit_evaluator.go
1
// SPDX-FileCopyrightText: Copyright 2026 The Minder Authors
2
// SPDX-License-Identifier: Apache-2.0
3

4
package engine
5

6
import "regexp"
7

8
const conventionalCommitTypePattern = `(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)`
9
const conventionalCommitScopePattern = `(\([A-Za-z0-9._/-]+\))?`
10

11
var conventionalCommitPattern = regexp.MustCompile(
12
        `^` + conventionalCommitTypePattern + conventionalCommitScopePattern + `!?: .+`,
13
)
14

15
// Commit contains commit-level data that can be evaluated by policies.
16
type Commit struct {
17
        SHA     string
18
        Message string
19
}
20

21
// CommitEvaluation captures the result of evaluating one policy.
22
type CommitEvaluation struct {
23
        Policy string
24
        Passed bool
25
        Reason string
26
}
27

28
// CommitResult captures all evaluations for a single commit.
29
type CommitResult struct {
30
        SHA         string
31
        Evaluations []CommitEvaluation
32
}
33

34
// CommitPolicy defines a single commit-level policy.
35
type CommitPolicy interface {
36
        Name() string
37
        Evaluate(commit Commit) CommitEvaluation
38
}
39

40
// CommitEvaluator evaluates commits against a list of commit-level policies.
41
type CommitEvaluator struct {
42
        policies []CommitPolicy
43
}
44

45
// NewCommitEvaluator creates a commit evaluator with the provided policies.
46
func NewCommitEvaluator(policies ...CommitPolicy) *CommitEvaluator {
5✔
47
        return &CommitEvaluator{policies: policies}
5✔
48
}
5✔
49

50
// Evaluate evaluates the commit against all configured policies.
51
func (e *CommitEvaluator) Evaluate(commit Commit) []CommitEvaluation {
5✔
52
        if len(e.policies) == 0 {
6✔
53
                return []CommitEvaluation{}
1✔
54
        }
1✔
55

56
        results := make([]CommitEvaluation, 0, len(e.policies))
4✔
57
        for _, policy := range e.policies {
9✔
58
                res := policy.Evaluate(commit)
5✔
59
                if res.Policy == "" {
5✔
NEW
60
                        res.Policy = policy.Name()
×
NEW
61
                }
×
62
                results = append(results, res)
5✔
63
        }
64

65
        return results
4✔
66
}
67

68
// EvaluateAll evaluates all commits in a PR, preserving commit order.
69
func (e *CommitEvaluator) EvaluateAll(commits []Commit) []CommitResult {
3✔
70
        results := make([]CommitResult, 0, len(commits))
3✔
71

3✔
72
        for _, commit := range commits {
6✔
73
                results = append(results, CommitResult{
3✔
74
                        SHA:         commit.SHA,
3✔
75
                        Evaluations: e.Evaluate(commit),
3✔
76
                })
3✔
77
        }
3✔
78

79
        return results
3✔
80
}
81

82
// HasPolicyFailures returns true if any policy evaluation fails.
83
func HasPolicyFailures(results []CommitResult) bool {
5✔
84
        for _, commitResult := range results {
14✔
85
                for _, eval := range commitResult.Evaluations {
19✔
86
                        if !eval.Passed {
13✔
87
                                return true
3✔
88
                        }
3✔
89
                }
90
        }
91

92
        return false
2✔
93
}
94

95
// HasFailures returns true if any policy evaluation fails.
96
// Deprecated: use HasPolicyFailures for clearer semantics.
97
func HasFailures(results []CommitResult) bool {
2✔
98
        return HasPolicyFailures(results)
2✔
99
}
2✔
100

101
// ConventionalCommitPolicy is an example commit policy that validates commit
102
// messages against a Conventional Commits-like format.
103
type ConventionalCommitPolicy struct{}
104

105
// Name returns the policy name.
106
func (ConventionalCommitPolicy) Name() string {
4✔
107
        return "conventional_commit"
4✔
108
}
4✔
109

110
// Evaluate validates commit message format.
111
func (p ConventionalCommitPolicy) Evaluate(commit Commit) CommitEvaluation {
4✔
112
        if conventionalCommitPattern.MatchString(commit.Message) {
7✔
113
                return CommitEvaluation{
3✔
114
                        Policy: p.Name(),
3✔
115
                        Passed: true,
3✔
116
                        Reason: "commit message matches conventional commit format",
3✔
117
                }
3✔
118
        }
3✔
119

120
        return CommitEvaluation{
1✔
121
                Policy: p.Name(),
1✔
122
                Passed: false,
1✔
123
                Reason: "commit message must follow <type>(optional-scope): <description>",
1✔
124
        }
1✔
125
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc