diff --git a/config.example.yaml b/config.example.yaml index b1aa505..ab1a4da 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -24,7 +24,6 @@ interval: 10 providers: # Static list of projects to check - static: static: - name: "standards-insights" url: https://github.com/qonto/standards-insights.git @@ -68,12 +67,14 @@ checks: rules: - go-version-latest - name: go-main + operator: and labels: category: misc severity: minor owner: backend rules: - go-main + - go-version-latest - name: grep-test labels: category: misc @@ -90,7 +91,7 @@ rules: - name: go-version-latest files: - path: "go.mod" - contains: "go 1.20" + contains: "go 1.21" - name: go-main files: - path: "main.go" diff --git a/config/config.go b/config/config.go index 47d48d2..1e5853a 100644 --- a/config/config.go +++ b/config/config.go @@ -53,9 +53,14 @@ type GrepRule struct { } type Check struct { - Name string `validate:"required"` - Labels map[string]string - Rules []string `validate:"required,min=1"` + Name string `validate:"required"` + Labels map[string]string + Operator string `validate:"oneof=and or"` + Rules []string `validate:"required,min=1"` +} + +func (c Check) IsAND() bool { + return c.Operator == "" || c.Operator == "and" } type Group struct { diff --git a/pkg/checker/check.go b/pkg/checker/check.go index a5282e7..6148798 100644 --- a/pkg/checker/check.go +++ b/pkg/checker/check.go @@ -12,12 +12,21 @@ import ( ) func (c *Checker) executeCheck(ctx context.Context, check config.Check, project project.Project) aggregates.CheckResult { + if check.IsAND() { + return c.executeANDCheck(ctx, check, project) + } else { + return c.executeORCheck(ctx, check, project) + } +} + +func (c *Checker) executeANDCheck(ctx context.Context, check config.Check, project project.Project) aggregates.CheckResult { success := true checkResult := aggregates.CheckResult{ Name: check.Name, Labels: check.Labels, Results: []ruleraggregates.RuleResult{}, } + for _, rule := range check.Rules { ruleResult := c.ruler.Execute(ctx, rule, project) if !ruleResult.Success { @@ -31,3 +40,25 @@ func (c *Checker) executeCheck(ctx context.Context, check config.Check, project checkResult.Success = success return checkResult } + +func (c *Checker) executeORCheck(ctx context.Context, check config.Check, project project.Project) aggregates.CheckResult { + success := false + checkResult := aggregates.CheckResult{ + Name: check.Name, + Labels: check.Labels, + Results: []ruleraggregates.RuleResult{}, + } + + for _, rule := range check.Rules { + ruleResult := c.ruler.Execute(ctx, rule, project) + if ruleResult.Success { + success = true + c.logger.Debug(fmt.Sprintf("rule %s successful on project %s for check %s", rule, project.Name, check.Name)) + } else { + c.logger.Debug(fmt.Sprintf("rule %s failed on project %s for check %s", rule, project.Name, check.Name)) + } + checkResult.Results = append(checkResult.Results, ruleResult) + } + checkResult.Success = success + return checkResult +}