Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/nullify.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 18 additions & 2 deletions pkg/merger/merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
94 changes: 74 additions & 20 deletions pkg/merger/merger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
},
} {
Expand All @@ -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: "",
Expand Down Expand Up @@ -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: "",
Expand Down Expand Up @@ -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: "",
Expand Down Expand Up @@ -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: "",
Expand Down Expand Up @@ -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: "",
Expand All @@ -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": {
Expand All @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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{
Expand Down
6 changes: 3 additions & 3 deletions pkg/models/code.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/models/dependencies.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
38 changes: 30 additions & 8 deletions pkg/models/models.go
Original file line number Diff line number Diff line change
@@ -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"`
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/secrets.go
Original file line number Diff line number Diff line change
@@ -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"`
Expand Down
12 changes: 8 additions & 4 deletions pkg/parser/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
20 changes: 20 additions & 0 deletions pkg/validator/severity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading