Skip to content

Commit 21e39cb

Browse files
add feature flags (#134)
1 parent 1a21be9 commit 21e39cb

File tree

11 files changed

+170
-49
lines changed

11 files changed

+170
-49
lines changed

examples/nullify.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
fail_builds: true
1+
enable_fail_builds: true
2+
enable_pull_request_reviews: true
3+
enable_issue_dashboards: true
24
severity_threshold: medium
35
ignore_dirs:
46
- dir1

pkg/merger/merger.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,30 @@ func MergeConfigFiles(
2222
continue
2323
}
2424

25-
if extraConfig.FailBuilds != nil {
26-
config.FailBuilds = extraConfig.FailBuilds
25+
// feature flags
26+
27+
if extraConfig.EnableFailBuilds != nil {
28+
config.EnableFailBuilds = extraConfig.EnableFailBuilds
29+
}
30+
31+
if extraConfig.EnablePullRequestReviews != nil {
32+
config.EnablePullRequestReviews = extraConfig.EnablePullRequestReviews
33+
}
34+
35+
if extraConfig.EnableIssueDashboards != nil {
36+
config.EnableIssueDashboards = extraConfig.EnableIssueDashboards
2737
}
2838

39+
// thresholds
40+
2941
if extraConfig.SeverityThreshold != "" && validator.ValidateSeverityThreshold(extraConfig) {
3042
config.SeverityThreshold = extraConfig.SeverityThreshold
3143
}
3244

45+
if extraConfig.PriorityThreshold != "" && validator.ValidateSeverityThreshold(extraConfig) {
46+
config.PriorityThreshold = extraConfig.PriorityThreshold
47+
}
48+
3349
if extraConfig.Integrations.Jira != nil {
3450
if config.Integrations.Jira == nil {
3551
config.Integrations.Jira = extraConfig.Integrations.Jira

pkg/merger/merger_test.go

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ func TestMergeConfigFiles(t *testing.T) {
2020
globalConfig: nil,
2121
repoConfig: nil,
2222
expected: &models.Configuration{
23-
SeverityThreshold: parser.DefaultSeverityThreshold,
23+
EnablePullRequestReviews: models.Bool(true),
24+
EnableIssueDashboards: models.Bool(true),
25+
SeverityThreshold: parser.DefaultSeverityThreshold,
26+
PriorityThreshold: parser.DefaultPriorityThreshold,
2427
},
2528
},
2629
{
@@ -81,9 +84,12 @@ func TestMergeConfigFiles(t *testing.T) {
8184
},
8285
},
8386
expected: &models.Configuration{
84-
SeverityThreshold: models.SeverityHigh,
85-
IgnoreDirs: []string{"dir1", "dir2"},
86-
IgnorePaths: []string{"path1", "path2"},
87+
EnablePullRequestReviews: models.Bool(true),
88+
EnableIssueDashboards: models.Bool(true),
89+
SeverityThreshold: models.SeverityHigh,
90+
PriorityThreshold: models.PriorityMedium,
91+
IgnoreDirs: []string{"dir1", "dir2"},
92+
IgnorePaths: []string{"path1", "path2"},
8793
Code: models.Code{
8894
AutoFix: &models.AutoFix{
8995
Enabled: true,
@@ -199,9 +205,12 @@ func TestMergeConfigFiles(t *testing.T) {
199205
},
200206
repoConfig: nil,
201207
expected: &models.Configuration{
202-
SeverityThreshold: models.SeverityHigh,
203-
IgnoreDirs: []string{"dir1", "dir2"},
204-
IgnorePaths: []string{"path1", "path2"},
208+
EnablePullRequestReviews: models.Bool(true),
209+
EnableIssueDashboards: models.Bool(true),
210+
SeverityThreshold: models.SeverityHigh,
211+
PriorityThreshold: models.PriorityMedium,
212+
IgnoreDirs: []string{"dir1", "dir2"},
213+
IgnorePaths: []string{"path1", "path2"},
205214
Code: models.Code{
206215
AutoFix: &models.AutoFix{
207216
Enabled: true,
@@ -264,43 +273,61 @@ func TestMergeConfigFiles(t *testing.T) {
264273
globalConfig: nil,
265274
repoConfig: &models.Configuration{
266275
SeverityThreshold: "",
276+
PriorityThreshold: "",
267277
},
268278
expected: &models.Configuration{
269-
SeverityThreshold: parser.DefaultSeverityThreshold,
279+
EnablePullRequestReviews: models.Bool(true),
280+
EnableIssueDashboards: models.Bool(true),
281+
SeverityThreshold: parser.DefaultSeverityThreshold,
282+
PriorityThreshold: parser.DefaultPriorityThreshold,
270283
},
271284
},
272285
{
273286
name: "global config without severity threshold",
274287
globalConfig: &models.Configuration{
275288
SeverityThreshold: "",
289+
PriorityThreshold: "",
276290
},
277291
repoConfig: nil,
278292
expected: &models.Configuration{
279-
SeverityThreshold: parser.DefaultSeverityThreshold,
293+
EnablePullRequestReviews: models.Bool(true),
294+
EnableIssueDashboards: models.Bool(true),
295+
SeverityThreshold: parser.DefaultSeverityThreshold,
296+
PriorityThreshold: parser.DefaultPriorityThreshold,
280297
},
281298
},
282299
{
283300
name: "global and repo config without severity threshold",
284301
globalConfig: &models.Configuration{
285302
SeverityThreshold: "",
303+
PriorityThreshold: "",
286304
},
287305
repoConfig: &models.Configuration{
288306
SeverityThreshold: "",
307+
PriorityThreshold: "",
289308
},
290309
expected: &models.Configuration{
291-
SeverityThreshold: parser.DefaultSeverityThreshold,
310+
EnablePullRequestReviews: models.Bool(true),
311+
EnableIssueDashboards: models.Bool(true),
312+
SeverityThreshold: parser.DefaultSeverityThreshold,
313+
PriorityThreshold: parser.DefaultPriorityThreshold,
292314
},
293315
},
294316
{
295317
name: "global and repo config without severity threshold",
296318
globalConfig: &models.Configuration{
297319
SeverityThreshold: models.SeverityCritical,
320+
PriorityThreshold: models.PriorityUrgent,
298321
},
299322
repoConfig: &models.Configuration{
300323
SeverityThreshold: models.SeverityHigh,
324+
PriorityThreshold: models.PriorityImportant,
301325
},
302326
expected: &models.Configuration{
303-
SeverityThreshold: models.SeverityHigh,
327+
EnablePullRequestReviews: models.Bool(true),
328+
EnableIssueDashboards: models.Bool(true),
329+
SeverityThreshold: models.SeverityHigh,
330+
PriorityThreshold: models.PriorityImportant,
304331
},
305332
},
306333
} {
@@ -327,7 +354,10 @@ func TestMergeJira(t *testing.T) {
327354
},
328355
repoConfig: nil,
329356
expected: &models.Configuration{
330-
SeverityThreshold: parser.DefaultSeverityThreshold,
357+
EnablePullRequestReviews: models.Bool(true),
358+
EnableIssueDashboards: models.Bool(true),
359+
SeverityThreshold: parser.DefaultSeverityThreshold,
360+
PriorityThreshold: parser.DefaultPriorityThreshold,
331361
Integrations: models.Integrations{
332362
Jira: &models.Jira{
333363
ProjectKey: "",
@@ -356,7 +386,10 @@ func TestMergeJira(t *testing.T) {
356386
},
357387
repoConfig: nil,
358388
expected: &models.Configuration{
359-
SeverityThreshold: parser.DefaultSeverityThreshold,
389+
EnablePullRequestReviews: models.Bool(true),
390+
EnableIssueDashboards: models.Bool(true),
391+
SeverityThreshold: parser.DefaultSeverityThreshold,
392+
PriorityThreshold: parser.DefaultPriorityThreshold,
360393
Integrations: models.Integrations{
361394
Jira: &models.Jira{
362395
ProjectKey: "",
@@ -395,7 +428,10 @@ func TestMergeJira(t *testing.T) {
395428
},
396429
},
397430
expected: &models.Configuration{
398-
SeverityThreshold: parser.DefaultSeverityThreshold,
431+
EnablePullRequestReviews: models.Bool(true),
432+
EnableIssueDashboards: models.Bool(true),
433+
SeverityThreshold: parser.DefaultSeverityThreshold,
434+
PriorityThreshold: parser.DefaultPriorityThreshold,
399435
Integrations: models.Integrations{
400436
Jira: &models.Jira{
401437
ProjectKey: "",
@@ -445,7 +481,10 @@ func TestMergeJira(t *testing.T) {
445481
},
446482
},
447483
expected: &models.Configuration{
448-
SeverityThreshold: parser.DefaultSeverityThreshold,
484+
EnablePullRequestReviews: models.Bool(true),
485+
EnableIssueDashboards: models.Bool(true),
486+
SeverityThreshold: parser.DefaultSeverityThreshold,
487+
PriorityThreshold: parser.DefaultPriorityThreshold,
449488
Integrations: models.Integrations{
450489
Jira: &models.Jira{
451490
ProjectKey: "",
@@ -473,7 +512,10 @@ func TestMergeJira(t *testing.T) {
473512
},
474513
},
475514
expected: &models.Configuration{
476-
SeverityThreshold: parser.DefaultSeverityThreshold,
515+
EnablePullRequestReviews: models.Bool(true),
516+
EnableIssueDashboards: models.Bool(true),
517+
SeverityThreshold: parser.DefaultSeverityThreshold,
518+
PriorityThreshold: parser.DefaultPriorityThreshold,
477519
Integrations: models.Integrations{
478520
Jira: &models.Jira{
479521
ProjectKey: "",
@@ -495,7 +537,10 @@ func TestMergeJira(t *testing.T) {
495537
},
496538
repoConfig: nil,
497539
expected: &models.Configuration{
498-
SeverityThreshold: parser.DefaultSeverityThreshold,
540+
EnablePullRequestReviews: models.Bool(true),
541+
EnableIssueDashboards: models.Bool(true),
542+
SeverityThreshold: parser.DefaultSeverityThreshold,
543+
PriorityThreshold: parser.DefaultPriorityThreshold,
499544
Secrets: models.Secrets{
500545
CustomPatterns: map[string]models.SecretsCustomPattern{
501546
"custom1": {
@@ -518,7 +563,10 @@ func TestMergeJira(t *testing.T) {
518563
},
519564
},
520565
expected: &models.Configuration{
521-
SeverityThreshold: parser.DefaultSeverityThreshold,
566+
EnablePullRequestReviews: models.Bool(true),
567+
EnableIssueDashboards: models.Bool(true),
568+
SeverityThreshold: parser.DefaultSeverityThreshold,
569+
PriorityThreshold: parser.DefaultPriorityThreshold,
522570
Secrets: models.Secrets{
523571
CustomPatterns: map[string]models.SecretsCustomPattern{
524572
"custom1": {
@@ -555,7 +603,10 @@ func TestMergeJira(t *testing.T) {
555603
},
556604
},
557605
expected: &models.Configuration{
558-
SeverityThreshold: parser.DefaultSeverityThreshold,
606+
EnablePullRequestReviews: models.Bool(true),
607+
EnableIssueDashboards: models.Bool(true),
608+
SeverityThreshold: parser.DefaultSeverityThreshold,
609+
PriorityThreshold: parser.DefaultPriorityThreshold,
559610
Secrets: models.Secrets{
560611
CustomPatterns: map[string]models.SecretsCustomPattern{
561612
"custom1": {
@@ -593,7 +644,10 @@ func TestMergeJira(t *testing.T) {
593644
},
594645
},
595646
expected: &models.Configuration{
596-
SeverityThreshold: parser.DefaultSeverityThreshold,
647+
EnablePullRequestReviews: models.Bool(true),
648+
EnableIssueDashboards: models.Bool(true),
649+
SeverityThreshold: parser.DefaultSeverityThreshold,
650+
PriorityThreshold: parser.DefaultPriorityThreshold,
597651
Secrets: models.Secrets{
598652
CustomPatternsOverrideGlobal: true,
599653
CustomPatterns: map[string]models.SecretsCustomPattern{

pkg/models/code.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package models
22

33
type Code struct {
4-
FailBuilds *bool `yaml:"fail_builds,omitempty"`
5-
AutoFix *AutoFix `yaml:"auto_fix,omitempty"`
6-
Ignore []CodeIgnore `yaml:"ignore,omitempty"`
4+
EnableFailBuilds *bool `yaml:"enable_fail_builds,omitempty"`
5+
AutoFix *AutoFix `yaml:"auto_fix,omitempty"`
6+
Ignore []CodeIgnore `yaml:"ignore,omitempty"`
77
}
88

99
type CodeIgnore struct {

pkg/models/dependencies.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package models
22

33
type Dependencies struct {
4-
FailBuilds *bool `yaml:"fail_builds,omitempty"`
5-
AutoFix *AutoFix `yaml:"auto_fix,omitempty"`
6-
Ignore []DependenciesIgnore `yaml:"ignore,omitempty"`
4+
EnableFailBuilds *bool `yaml:"enable_fail_builds,omitempty"`
5+
AutoFix *AutoFix `yaml:"auto_fix,omitempty"`
6+
Ignore []DependenciesIgnore `yaml:"ignore,omitempty"`
77
}
88

99
type DependenciesIgnore struct {

pkg/models/models.go

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package models
22

33
type Configuration struct {
4-
FailBuilds *bool `yaml:"fail_builds,omitempty"`
5-
SeverityThreshold string `yaml:"severity_threshold,omitempty"`
6-
IgnoreDirs []string `yaml:"ignore_dirs,omitempty"`
7-
IgnorePaths []string `yaml:"ignore_paths,omitempty"`
8-
AutoFix *AutoFix `yaml:"auto_fix,omitempty"`
4+
// git platform options
5+
EnableFailBuilds *bool `yaml:"enable_fail_builds,omitempty"`
6+
EnablePullRequestReviews *bool `yaml:"enable_pull_request_reviews,omitempty"`
7+
EnableIssueDashboards *bool `yaml:"enable_issue_dashboards,omitempty"`
8+
9+
SeverityThreshold string `yaml:"severity_threshold,omitempty"`
10+
PriorityThreshold string `yaml:"priority_threshold,omitempty"`
11+
12+
IgnoreDirs []string `yaml:"ignore_dirs,omitempty"`
13+
IgnorePaths []string `yaml:"ignore_paths,omitempty"`
14+
AutoFix *AutoFix `yaml:"auto_fix,omitempty"`
915

1016
Notifications map[string]Notification `yaml:"notifications,omitempty"`
1117
ScheduledNotifications map[string]ScheduledNotification `yaml:"scheduled_notifications,omitempty"`
@@ -20,12 +26,28 @@ type Configuration struct {
2026
SecretsWhitelist []string `yaml:"secrets_whitelist,omitempty"`
2127
}
2228

23-
func (c *Configuration) GetFailBuilds() bool {
24-
if c.FailBuilds == nil {
29+
func (c *Configuration) GetEnableFailBuilds() bool {
30+
if c.EnableFailBuilds == nil {
31+
return false
32+
}
33+
34+
return *c.EnableFailBuilds
35+
}
36+
37+
func (c *Configuration) GetEnablePullRequestReviews() bool {
38+
if c.EnablePullRequestReviews == nil {
39+
return false
40+
}
41+
42+
return *c.EnablePullRequestReviews
43+
}
44+
45+
func (c *Configuration) GetEnableIssueDashboards() bool {
46+
if c.EnableIssueDashboards == nil {
2547
return false
2648
}
2749

28-
return *c.FailBuilds
50+
return *c.EnableIssueDashboards
2951
}
3052

3153
func Bool(b bool) *bool {

pkg/models/secrets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package models
22

33
type Secrets struct {
4-
FailBuilds *bool `yaml:"fail_builds,omitempty"`
4+
EnableFailBuilds *bool `yaml:"enable_fail_builds,omitempty"`
55
Ignore []SecretsIgnore `yaml:"ignore,omitempty"`
66
CustomPatterns map[string]SecretsCustomPattern `yaml:"custom_patterns,omitempty"`
77
CustomPatternsOverrideGlobal bool `yaml:"custom_patterns_override_global,omitempty"`

pkg/parser/defaults.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ package parser
33
import "github.com/nullify-platform/config-file-parser/pkg/models"
44

55
const DefaultSeverityThreshold = models.SeverityMedium
6+
const DefaultPriorityThreshold = models.PriorityMedium
67

78
func NewDefaultConfig() *models.Configuration {
89
return &models.Configuration{
9-
FailBuilds: nil,
10-
SeverityThreshold: DefaultSeverityThreshold,
11-
IgnoreDirs: nil,
12-
IgnorePaths: nil,
10+
EnableFailBuilds: nil,
11+
EnablePullRequestReviews: models.Bool(true),
12+
EnableIssueDashboards: models.Bool(true),
13+
SeverityThreshold: DefaultSeverityThreshold,
14+
PriorityThreshold: DefaultPriorityThreshold,
15+
IgnoreDirs: nil,
16+
IgnorePaths: nil,
1317
Code: models.Code{
1418
Ignore: nil,
1519
},

pkg/validator/severity.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,23 @@ var validSeveritites = []string{
2222
func ValidateSeverityThreshold(config *models.Configuration) bool {
2323
return slices.Contains(validSeveritites, config.SeverityThreshold)
2424
}
25+
26+
var validPriorities = []string{
27+
models.PriorityUrgent,
28+
models.PriorityImportant,
29+
models.PriorityMedium,
30+
models.PriorityLow,
31+
models.PriorityNegligible,
32+
}
33+
34+
// ValidatePriorityThreshold returns true if the priority_threshold
35+
// option is one of the valid values:
36+
// - ""
37+
// - NEGLIGIBLE / negligible
38+
// - LOW / low
39+
// - MEDIUM / medium
40+
// - IMPORTANT / important
41+
// - URGENT / urgent
42+
func ValidatePriorityThreshold(config *models.Configuration) bool {
43+
return slices.Contains(validPriorities, config.PriorityThreshold)
44+
}

0 commit comments

Comments
 (0)