@@ -437,12 +437,17 @@ func LoadHeartbeatParams(ctx context.Context, v *viper.Viper) (Heartbeat, error)
437
437
timeSecs = float64 (time .Now ().UnixNano ()) / 1000000000
438
438
}
439
439
440
+ filterParams , err := loadFilterParams (ctx , v )
441
+ if err != nil {
442
+ return Heartbeat {}, fmt .Errorf ("failed to load filter params: %s" , err )
443
+ }
444
+
440
445
projectParams , err := loadProjectParams (ctx , v )
441
446
if err != nil {
442
447
return Heartbeat {}, fmt .Errorf ("failed to parse project params: %s" , err )
443
448
}
444
449
445
- sanitizeParams , err := loadSanitizeParams (v )
450
+ sanitizeParams , err := loadSanitizeParams (ctx , v )
446
451
if err != nil {
447
452
return Heartbeat {}, fmt .Errorf ("failed to load sanitize params: %s" , err )
448
453
}
@@ -469,34 +474,30 @@ func LoadHeartbeatParams(ctx context.Context, v *viper.Viper) (Heartbeat, error)
469
474
LinesInFile : linesInFile ,
470
475
LocalFile : vipertools .GetString (v , "local-file" ),
471
476
Time : timeSecs ,
472
- Filter : loadFilterParams ( ctx , v ) ,
477
+ Filter : filterParams ,
473
478
Project : projectParams ,
474
479
Sanitize : sanitizeParams ,
475
480
}, nil
476
481
}
477
482
478
- func loadFilterParams (ctx context.Context , v * viper.Viper ) FilterParams {
483
+ func loadFilterParams (ctx context.Context , v * viper.Viper ) ( FilterParams , error ) {
479
484
exclude := v .GetStringSlice ("exclude" )
480
485
exclude = append (exclude , v .GetStringSlice ("settings.exclude" )... )
481
486
exclude = append (exclude , v .GetStringSlice ("settings.ignore" )... )
482
487
483
- logger := log .Extract (ctx )
484
-
485
488
var excludePatterns []regex.Regex
486
489
487
490
for _ , s := range exclude {
488
- // make all regex case insensitive
489
- if ! strings .HasPrefix (s , "(?i)" ) {
490
- s = "(?i)" + s
491
- }
492
-
493
- compiled , err := regex .Compile (s )
491
+ patterns , err := parseBoolOrRegexList (ctx , s )
494
492
if err != nil {
495
- logger .Warnf ("failed to compile exclude regex pattern %q" , s )
496
- continue
493
+ return FilterParams {}, fmt .Errorf (
494
+ "failed to parse regex exclude param %q: %s" ,
495
+ s ,
496
+ err ,
497
+ )
497
498
}
498
499
499
- excludePatterns = append (excludePatterns , compiled )
500
+ excludePatterns = append (excludePatterns , patterns ... )
500
501
}
501
502
502
503
include := v .GetStringSlice ("include" )
@@ -505,18 +506,16 @@ func loadFilterParams(ctx context.Context, v *viper.Viper) FilterParams {
505
506
var includePatterns []regex.Regex
506
507
507
508
for _ , s := range include {
508
- // make all regex case insensitive
509
- if ! strings .HasPrefix (s , "(?i)" ) {
510
- s = "(?i)" + s
511
- }
512
-
513
- compiled , err := regex .Compile (s )
509
+ patterns , err := parseBoolOrRegexList (ctx , s )
514
510
if err != nil {
515
- logger .Warnf ("failed to compile include regex pattern %q" , s )
516
- continue
511
+ return FilterParams {}, fmt .Errorf (
512
+ "failed to parse regex include param %q: %s" ,
513
+ s ,
514
+ err ,
515
+ )
517
516
}
518
517
519
- includePatterns = append (includePatterns , compiled )
518
+ includePatterns = append (includePatterns , patterns ... )
520
519
}
521
520
522
521
return FilterParams {
@@ -532,10 +531,10 @@ func loadFilterParams(ctx context.Context, v *viper.Viper) FilterParams {
532
531
"include-only-with-project-file" ,
533
532
"settings.include_only_with_project_file" ,
534
533
),
535
- }
534
+ }, nil
536
535
}
537
536
538
- func loadSanitizeParams (v * viper.Viper ) (SanitizeParams , error ) {
537
+ func loadSanitizeParams (ctx context. Context , v * viper.Viper ) (SanitizeParams , error ) {
539
538
// hide branch names
540
539
hideBranchNamesStr := vipertools .FirstNonEmptyString (
541
540
v ,
@@ -545,7 +544,7 @@ func loadSanitizeParams(v *viper.Viper) (SanitizeParams, error) {
545
544
"settings.hidebranchnames" ,
546
545
)
547
546
548
- hideBranchNamesPatterns , err := parseBoolOrRegexList (hideBranchNamesStr )
547
+ hideBranchNamesPatterns , err := parseBoolOrRegexList (ctx , hideBranchNamesStr )
549
548
if err != nil {
550
549
return SanitizeParams {}, fmt .Errorf (
551
550
"failed to parse regex hide branch names param %q: %s" ,
@@ -563,7 +562,7 @@ func loadSanitizeParams(v *viper.Viper) (SanitizeParams, error) {
563
562
"settings.hideprojectnames" ,
564
563
)
565
564
566
- hideProjectNamesPatterns , err := parseBoolOrRegexList (hideProjectNamesStr )
565
+ hideProjectNamesPatterns , err := parseBoolOrRegexList (ctx , hideProjectNamesStr )
567
566
if err != nil {
568
567
return SanitizeParams {}, fmt .Errorf (
569
568
"failed to parse regex hide project names param %q: %s" ,
@@ -583,7 +582,7 @@ func loadSanitizeParams(v *viper.Viper) (SanitizeParams, error) {
583
582
"settings.hidefilenames" ,
584
583
)
585
584
586
- hideFileNamesPatterns , err := parseBoolOrRegexList (hideFileNamesStr )
585
+ hideFileNamesPatterns , err := parseBoolOrRegexList (ctx , hideFileNamesStr )
587
586
if err != nil {
588
587
return SanitizeParams {}, fmt .Errorf (
589
588
"failed to parse regex hide file names param %q: %s" ,
@@ -602,7 +601,7 @@ func loadSanitizeParams(v *viper.Viper) (SanitizeParams, error) {
602
601
}
603
602
604
603
func loadProjectParams (ctx context.Context , v * viper.Viper ) (ProjectParams , error ) {
605
- submodulesDisabled , err := parseBoolOrRegexList (vipertools .GetString (v , "git.submodules_disabled" ))
604
+ submodulesDisabled , err := parseBoolOrRegexList (ctx , vipertools .GetString (v , "git.submodules_disabled" ))
606
605
if err != nil {
607
606
return ProjectParams {}, fmt .Errorf (
608
607
"failed to parse regex submodules disabled param: %s" ,
@@ -1154,9 +1153,11 @@ func (p StatusBar) String() string {
1154
1153
)
1155
1154
}
1156
1155
1157
- func parseBoolOrRegexList (s string ) ([]regex.Regex , error ) {
1156
+ func parseBoolOrRegexList (ctx context. Context , s string ) ([]regex.Regex , error ) {
1158
1157
var patterns []regex.Regex
1159
1158
1159
+ logger := log .Extract (ctx )
1160
+
1160
1161
s = strings .ReplaceAll (s , "\r " , "\n " )
1161
1162
s = strings .Trim (s , "\n \t " )
1162
1163
@@ -1174,9 +1175,15 @@ func parseBoolOrRegexList(s string) ([]regex.Regex, error) {
1174
1175
continue
1175
1176
}
1176
1177
1178
+ // make all regex case insensitive
1179
+ if ! strings .HasPrefix (s , "(?i)" ) {
1180
+ s = "(?i)" + s
1181
+ }
1182
+
1177
1183
compiled , err := regex .Compile (s )
1178
1184
if err != nil {
1179
- return nil , fmt .Errorf ("failed to compile regex %q: %s" , s , err )
1185
+ logger .Warnf ("failed to compile regex pattern %q, it will be ignored" , s )
1186
+ continue
1180
1187
}
1181
1188
1182
1189
patterns = append (patterns , compiled )
0 commit comments