diff --git a/examples/nullify.yaml b/examples/nullify.yaml index d19f134..e0ec009 100644 --- a/examples/nullify.yaml +++ b/examples/nullify.yaml @@ -1,4 +1,6 @@ -fail_builds: true +enable_fail_builds: true +enable_pull_request_reviews: true +enable_issue_dashboards: true severity_threshold: medium ignore_dirs: - dir1 diff --git a/pkg/merger/merger.go b/pkg/merger/merger.go index 6d65f39..363b996 100644 --- a/pkg/merger/merger.go +++ b/pkg/merger/merger.go @@ -22,14 +22,30 @@ func MergeConfigFiles( continue } - if extraConfig.FailBuilds != nil { - config.FailBuilds = extraConfig.FailBuilds + // feature flags + + if extraConfig.EnableFailBuilds != nil { + config.EnableFailBuilds = extraConfig.EnableFailBuilds + } + + if extraConfig.EnablePullRequestReviews != nil { + config.EnablePullRequestReviews = extraConfig.EnablePullRequestReviews + } + + if extraConfig.EnableIssueDashboards != nil { + config.EnableIssueDashboards = extraConfig.EnableIssueDashboards } + // thresholds + if extraConfig.SeverityThreshold != "" && validator.ValidateSeverityThreshold(extraConfig) { config.SeverityThreshold = extraConfig.SeverityThreshold } + if extraConfig.PriorityThreshold != "" && validator.ValidateSeverityThreshold(extraConfig) { + config.PriorityThreshold = extraConfig.PriorityThreshold + } + if extraConfig.Integrations.Jira != nil { if config.Integrations.Jira == nil { config.Integrations.Jira = extraConfig.Integrations.Jira diff --git a/pkg/merger/merger_test.go b/pkg/merger/merger_test.go index 645bad4..084875d 100644 --- a/pkg/merger/merger_test.go +++ b/pkg/merger/merger_test.go @@ -20,7 +20,10 @@ func TestMergeConfigFiles(t *testing.T) { globalConfig: nil, repoConfig: nil, expected: &models.Configuration{ - SeverityThreshold: parser.DefaultSeverityThreshold, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: parser.DefaultSeverityThreshold, + PriorityThreshold: parser.DefaultPriorityThreshold, }, }, { @@ -81,9 +84,12 @@ func TestMergeConfigFiles(t *testing.T) { }, }, expected: &models.Configuration{ - SeverityThreshold: models.SeverityHigh, - IgnoreDirs: []string{"dir1", "dir2"}, - IgnorePaths: []string{"path1", "path2"}, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: models.SeverityHigh, + PriorityThreshold: models.PriorityMedium, + IgnoreDirs: []string{"dir1", "dir2"}, + IgnorePaths: []string{"path1", "path2"}, Code: models.Code{ AutoFix: &models.AutoFix{ Enabled: true, @@ -199,9 +205,12 @@ func TestMergeConfigFiles(t *testing.T) { }, repoConfig: nil, expected: &models.Configuration{ - SeverityThreshold: models.SeverityHigh, - IgnoreDirs: []string{"dir1", "dir2"}, - IgnorePaths: []string{"path1", "path2"}, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: models.SeverityHigh, + PriorityThreshold: models.PriorityMedium, + IgnoreDirs: []string{"dir1", "dir2"}, + IgnorePaths: []string{"path1", "path2"}, Code: models.Code{ AutoFix: &models.AutoFix{ Enabled: true, @@ -264,43 +273,61 @@ func TestMergeConfigFiles(t *testing.T) { globalConfig: nil, repoConfig: &models.Configuration{ SeverityThreshold: "", + PriorityThreshold: "", }, expected: &models.Configuration{ - SeverityThreshold: parser.DefaultSeverityThreshold, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: parser.DefaultSeverityThreshold, + PriorityThreshold: parser.DefaultPriorityThreshold, }, }, { name: "global config without severity threshold", globalConfig: &models.Configuration{ SeverityThreshold: "", + PriorityThreshold: "", }, repoConfig: nil, expected: &models.Configuration{ - SeverityThreshold: parser.DefaultSeverityThreshold, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: parser.DefaultSeverityThreshold, + PriorityThreshold: parser.DefaultPriorityThreshold, }, }, { name: "global and repo config without severity threshold", globalConfig: &models.Configuration{ SeverityThreshold: "", + PriorityThreshold: "", }, repoConfig: &models.Configuration{ SeverityThreshold: "", + PriorityThreshold: "", }, expected: &models.Configuration{ - SeverityThreshold: parser.DefaultSeverityThreshold, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: parser.DefaultSeverityThreshold, + PriorityThreshold: parser.DefaultPriorityThreshold, }, }, { name: "global and repo config without severity threshold", globalConfig: &models.Configuration{ SeverityThreshold: models.SeverityCritical, + PriorityThreshold: models.PriorityUrgent, }, repoConfig: &models.Configuration{ SeverityThreshold: models.SeverityHigh, + PriorityThreshold: models.PriorityImportant, }, expected: &models.Configuration{ - SeverityThreshold: models.SeverityHigh, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: models.SeverityHigh, + PriorityThreshold: models.PriorityImportant, }, }, } { @@ -327,7 +354,10 @@ func TestMergeJira(t *testing.T) { }, repoConfig: nil, expected: &models.Configuration{ - SeverityThreshold: parser.DefaultSeverityThreshold, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: parser.DefaultSeverityThreshold, + PriorityThreshold: parser.DefaultPriorityThreshold, Integrations: models.Integrations{ Jira: &models.Jira{ ProjectKey: "", @@ -356,7 +386,10 @@ func TestMergeJira(t *testing.T) { }, repoConfig: nil, expected: &models.Configuration{ - SeverityThreshold: parser.DefaultSeverityThreshold, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: parser.DefaultSeverityThreshold, + PriorityThreshold: parser.DefaultPriorityThreshold, Integrations: models.Integrations{ Jira: &models.Jira{ ProjectKey: "", @@ -395,7 +428,10 @@ func TestMergeJira(t *testing.T) { }, }, expected: &models.Configuration{ - SeverityThreshold: parser.DefaultSeverityThreshold, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: parser.DefaultSeverityThreshold, + PriorityThreshold: parser.DefaultPriorityThreshold, Integrations: models.Integrations{ Jira: &models.Jira{ ProjectKey: "", @@ -445,7 +481,10 @@ func TestMergeJira(t *testing.T) { }, }, expected: &models.Configuration{ - SeverityThreshold: parser.DefaultSeverityThreshold, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: parser.DefaultSeverityThreshold, + PriorityThreshold: parser.DefaultPriorityThreshold, Integrations: models.Integrations{ Jira: &models.Jira{ ProjectKey: "", @@ -473,7 +512,10 @@ func TestMergeJira(t *testing.T) { }, }, expected: &models.Configuration{ - SeverityThreshold: parser.DefaultSeverityThreshold, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: parser.DefaultSeverityThreshold, + PriorityThreshold: parser.DefaultPriorityThreshold, Integrations: models.Integrations{ Jira: &models.Jira{ ProjectKey: "", @@ -495,7 +537,10 @@ func TestMergeJira(t *testing.T) { }, repoConfig: nil, expected: &models.Configuration{ - SeverityThreshold: parser.DefaultSeverityThreshold, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: parser.DefaultSeverityThreshold, + PriorityThreshold: parser.DefaultPriorityThreshold, Secrets: models.Secrets{ CustomPatterns: map[string]models.SecretsCustomPattern{ "custom1": { @@ -518,7 +563,10 @@ func TestMergeJira(t *testing.T) { }, }, expected: &models.Configuration{ - SeverityThreshold: parser.DefaultSeverityThreshold, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: parser.DefaultSeverityThreshold, + PriorityThreshold: parser.DefaultPriorityThreshold, Secrets: models.Secrets{ CustomPatterns: map[string]models.SecretsCustomPattern{ "custom1": { @@ -555,7 +603,10 @@ func TestMergeJira(t *testing.T) { }, }, expected: &models.Configuration{ - SeverityThreshold: parser.DefaultSeverityThreshold, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: parser.DefaultSeverityThreshold, + PriorityThreshold: parser.DefaultPriorityThreshold, Secrets: models.Secrets{ CustomPatterns: map[string]models.SecretsCustomPattern{ "custom1": { @@ -593,7 +644,10 @@ func TestMergeJira(t *testing.T) { }, }, expected: &models.Configuration{ - SeverityThreshold: parser.DefaultSeverityThreshold, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: parser.DefaultSeverityThreshold, + PriorityThreshold: parser.DefaultPriorityThreshold, Secrets: models.Secrets{ CustomPatternsOverrideGlobal: true, CustomPatterns: map[string]models.SecretsCustomPattern{ diff --git a/pkg/models/code.go b/pkg/models/code.go index 3897fb9..4b568f6 100644 --- a/pkg/models/code.go +++ b/pkg/models/code.go @@ -1,9 +1,9 @@ package models type Code struct { - FailBuilds *bool `yaml:"fail_builds,omitempty"` - AutoFix *AutoFix `yaml:"auto_fix,omitempty"` - Ignore []CodeIgnore `yaml:"ignore,omitempty"` + EnableFailBuilds *bool `yaml:"enable_fail_builds,omitempty"` + AutoFix *AutoFix `yaml:"auto_fix,omitempty"` + Ignore []CodeIgnore `yaml:"ignore,omitempty"` } type CodeIgnore struct { diff --git a/pkg/models/dependencies.go b/pkg/models/dependencies.go index 6f07d17..f024f0e 100644 --- a/pkg/models/dependencies.go +++ b/pkg/models/dependencies.go @@ -1,9 +1,9 @@ package models type Dependencies struct { - FailBuilds *bool `yaml:"fail_builds,omitempty"` - AutoFix *AutoFix `yaml:"auto_fix,omitempty"` - Ignore []DependenciesIgnore `yaml:"ignore,omitempty"` + EnableFailBuilds *bool `yaml:"enable_fail_builds,omitempty"` + AutoFix *AutoFix `yaml:"auto_fix,omitempty"` + Ignore []DependenciesIgnore `yaml:"ignore,omitempty"` } type DependenciesIgnore struct { diff --git a/pkg/models/models.go b/pkg/models/models.go index 9bcbfed..58ce965 100644 --- a/pkg/models/models.go +++ b/pkg/models/models.go @@ -1,11 +1,17 @@ package models type Configuration struct { - FailBuilds *bool `yaml:"fail_builds,omitempty"` - SeverityThreshold string `yaml:"severity_threshold,omitempty"` - IgnoreDirs []string `yaml:"ignore_dirs,omitempty"` - IgnorePaths []string `yaml:"ignore_paths,omitempty"` - AutoFix *AutoFix `yaml:"auto_fix,omitempty"` + // git platform options + EnableFailBuilds *bool `yaml:"enable_fail_builds,omitempty"` + EnablePullRequestReviews *bool `yaml:"enable_pull_request_reviews,omitempty"` + EnableIssueDashboards *bool `yaml:"enable_issue_dashboards,omitempty"` + + SeverityThreshold string `yaml:"severity_threshold,omitempty"` + PriorityThreshold string `yaml:"priority_threshold,omitempty"` + + IgnoreDirs []string `yaml:"ignore_dirs,omitempty"` + IgnorePaths []string `yaml:"ignore_paths,omitempty"` + AutoFix *AutoFix `yaml:"auto_fix,omitempty"` Notifications map[string]Notification `yaml:"notifications,omitempty"` ScheduledNotifications map[string]ScheduledNotification `yaml:"scheduled_notifications,omitempty"` @@ -20,12 +26,28 @@ type Configuration struct { SecretsWhitelist []string `yaml:"secrets_whitelist,omitempty"` } -func (c *Configuration) GetFailBuilds() bool { - if c.FailBuilds == nil { +func (c *Configuration) GetEnableFailBuilds() bool { + if c.EnableFailBuilds == nil { + return false + } + + return *c.EnableFailBuilds +} + +func (c *Configuration) GetEnablePullRequestReviews() bool { + if c.EnablePullRequestReviews == nil { + return false + } + + return *c.EnablePullRequestReviews +} + +func (c *Configuration) GetEnableIssueDashboards() bool { + if c.EnableIssueDashboards == nil { return false } - return *c.FailBuilds + return *c.EnableIssueDashboards } func Bool(b bool) *bool { diff --git a/pkg/models/secrets.go b/pkg/models/secrets.go index d56d783..1a9075e 100644 --- a/pkg/models/secrets.go +++ b/pkg/models/secrets.go @@ -1,7 +1,7 @@ package models type Secrets struct { - FailBuilds *bool `yaml:"fail_builds,omitempty"` + EnableFailBuilds *bool `yaml:"enable_fail_builds,omitempty"` Ignore []SecretsIgnore `yaml:"ignore,omitempty"` CustomPatterns map[string]SecretsCustomPattern `yaml:"custom_patterns,omitempty"` CustomPatternsOverrideGlobal bool `yaml:"custom_patterns_override_global,omitempty"` diff --git a/pkg/parser/defaults.go b/pkg/parser/defaults.go index 43265e5..eb243b1 100644 --- a/pkg/parser/defaults.go +++ b/pkg/parser/defaults.go @@ -3,13 +3,17 @@ package parser import "github.com/nullify-platform/config-file-parser/pkg/models" const DefaultSeverityThreshold = models.SeverityMedium +const DefaultPriorityThreshold = models.PriorityMedium func NewDefaultConfig() *models.Configuration { return &models.Configuration{ - FailBuilds: nil, - SeverityThreshold: DefaultSeverityThreshold, - IgnoreDirs: nil, - IgnorePaths: nil, + EnableFailBuilds: nil, + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: DefaultSeverityThreshold, + PriorityThreshold: DefaultPriorityThreshold, + IgnoreDirs: nil, + IgnorePaths: nil, Code: models.Code{ Ignore: nil, }, diff --git a/pkg/validator/severity.go b/pkg/validator/severity.go index f420eee..06ab168 100644 --- a/pkg/validator/severity.go +++ b/pkg/validator/severity.go @@ -22,3 +22,23 @@ var validSeveritites = []string{ func ValidateSeverityThreshold(config *models.Configuration) bool { return slices.Contains(validSeveritites, config.SeverityThreshold) } + +var validPriorities = []string{ + models.PriorityUrgent, + models.PriorityImportant, + models.PriorityMedium, + models.PriorityLow, + models.PriorityNegligible, +} + +// ValidatePriorityThreshold returns true if the priority_threshold +// option is one of the valid values: +// - "" +// - NEGLIGIBLE / negligible +// - LOW / low +// - MEDIUM / medium +// - IMPORTANT / important +// - URGENT / urgent +func ValidatePriorityThreshold(config *models.Configuration) bool { + return slices.Contains(validPriorities, config.PriorityThreshold) +} diff --git a/tests/integration_test.go b/tests/integration_test.go index de592ad..c1ff47f 100644 --- a/tests/integration_test.go +++ b/tests/integration_test.go @@ -10,12 +10,13 @@ import ( ) func TestIntegration(t *testing.T) { - fail := true expectedConfig := &models.Configuration{ - FailBuilds: &fail, - SeverityThreshold: models.SeverityMedium, - IgnoreDirs: []string{"dir1"}, - IgnorePaths: []string{"data/**/*"}, + EnableFailBuilds: models.Bool(true), + EnablePullRequestReviews: models.Bool(true), + EnableIssueDashboards: models.Bool(true), + SeverityThreshold: models.SeverityMedium, + IgnoreDirs: []string{"dir1"}, + IgnorePaths: []string{"data/**/*"}, Secrets: models.Secrets{ Ignore: []models.SecretsIgnore{ { @@ -162,7 +163,7 @@ func TestIntegration(t *testing.T) { func TestEmptyFailsBuildField(t *testing.T) { expectedConfig := &models.Configuration{ - FailBuilds: nil, + EnableFailBuilds: nil, SeverityThreshold: models.SeverityMedium, IgnoreDirs: []string{"dir1"}, IgnorePaths: []string{"data/**/*"}, diff --git a/tests/nullify.yaml b/tests/nullify.yaml index 15a12ea..085482a 100644 --- a/tests/nullify.yaml +++ b/tests/nullify.yaml @@ -1,4 +1,6 @@ -fail_builds: true +enable_fail_builds: true +enable_pull_request_reviews: true +enable_issue_dashboards: true severity_threshold: medium ignore_dirs: - dir1