@@ -136,11 +136,12 @@ def has_white_space(self, version):
136
136
"""
137
137
return VersionType .HAS_WHITE_SPACE in version
138
138
139
- def compare_user_version_with_target_version (self , index ):
139
+ def compare_user_version_with_target_version (self , target_version , user_version ):
140
140
""" Method to compare user version with target version.
141
141
142
142
Args:
143
- index: Index of the condition to be evaluated.
143
+ target_version: String representing condition value
144
+ user_version: String representing user value
144
145
145
146
Returns:
146
147
Int:
@@ -149,23 +150,8 @@ def compare_user_version_with_target_version(self, index):
149
150
- -1 if user version is less than target version or, in case of exact string match, doesn't match the target
150
151
version.
151
152
None:
152
- - if the user version value is not string type or is null .
153
+ - if the user version value format is not a valid semantic version .
153
154
"""
154
- condition_name = self .condition_data [index ][0 ]
155
- target_version = self .condition_data [index ][1 ]
156
- user_version = self .attributes .get (condition_name )
157
-
158
- if not isinstance (target_version , string_types ):
159
- self .logger .warning (audience_logs .UNKNOWN_CONDITION_VALUE .format (self ._get_condition_json (index ), ))
160
- return None
161
-
162
- if not isinstance (user_version , string_types ):
163
- self .logger .warning (
164
- audience_logs .UNEXPECTED_TYPE .format (
165
- self ._get_condition_json (index ), type (user_version ), condition_name
166
- )
167
- )
168
- return None
169
155
170
156
target_version_parts = self .split_version (target_version )
171
157
if target_version_parts is None :
@@ -426,7 +412,24 @@ def semver_equal_evaluator(self, index):
426
412
None:
427
413
- if the user version value is not string type or is null.
428
414
"""
429
- result = self .compare_user_version_with_target_version (index )
415
+
416
+ condition_name = self .condition_data [index ][0 ]
417
+ target_version = self .condition_data [index ][1 ]
418
+ user_version = self .attributes .get (condition_name )
419
+
420
+ if not isinstance (target_version , string_types ):
421
+ self .logger .warning (audience_logs .UNKNOWN_CONDITION_VALUE .format (self ._get_condition_json (index ), ))
422
+ return None
423
+
424
+ if not isinstance (user_version , string_types ):
425
+ self .logger .warning (
426
+ audience_logs .UNEXPECTED_TYPE .format (
427
+ self ._get_condition_json (index ), type (user_version ), condition_name
428
+ )
429
+ )
430
+ return None
431
+
432
+ result = self .compare_user_version_with_target_version (target_version , user_version )
430
433
if result is None :
431
434
return None
432
435
@@ -445,7 +448,23 @@ def semver_greater_than_evaluator(self, index):
445
448
None:
446
449
- if the user version value is not string type or is null.
447
450
"""
448
- result = self .compare_user_version_with_target_version (index )
451
+ condition_name = self .condition_data [index ][0 ]
452
+ target_version = self .condition_data [index ][1 ]
453
+ user_version = self .attributes .get (condition_name )
454
+
455
+ if not isinstance (target_version , string_types ):
456
+ self .logger .warning (audience_logs .UNKNOWN_CONDITION_VALUE .format (self ._get_condition_json (index ), ))
457
+ return None
458
+
459
+ if not isinstance (user_version , string_types ):
460
+ self .logger .warning (
461
+ audience_logs .UNEXPECTED_TYPE .format (
462
+ self ._get_condition_json (index ), type (user_version ), condition_name
463
+ )
464
+ )
465
+ return None
466
+
467
+ result = self .compare_user_version_with_target_version (target_version , user_version )
449
468
if result is None :
450
469
return None
451
470
@@ -464,7 +483,23 @@ def semver_less_than_evaluator(self, index):
464
483
None:
465
484
- if the user version value is not string type or is null.
466
485
"""
467
- result = self .compare_user_version_with_target_version (index )
486
+ condition_name = self .condition_data [index ][0 ]
487
+ target_version = self .condition_data [index ][1 ]
488
+ user_version = self .attributes .get (condition_name )
489
+
490
+ if not isinstance (target_version , string_types ):
491
+ self .logger .warning (audience_logs .UNKNOWN_CONDITION_VALUE .format (self ._get_condition_json (index ), ))
492
+ return None
493
+
494
+ if not isinstance (user_version , string_types ):
495
+ self .logger .warning (
496
+ audience_logs .UNEXPECTED_TYPE .format (
497
+ self ._get_condition_json (index ), type (user_version ), condition_name
498
+ )
499
+ )
500
+ return None
501
+
502
+ result = self .compare_user_version_with_target_version (target_version , user_version )
468
503
if result is None :
469
504
return None
470
505
@@ -483,7 +518,23 @@ def semver_less_than_or_equal_evaluator(self, index):
483
518
None:
484
519
- if the user version value is not string type or is null.
485
520
"""
486
- result = self .compare_user_version_with_target_version (index )
521
+ condition_name = self .condition_data [index ][0 ]
522
+ target_version = self .condition_data [index ][1 ]
523
+ user_version = self .attributes .get (condition_name )
524
+
525
+ if not isinstance (target_version , string_types ):
526
+ self .logger .warning (audience_logs .UNKNOWN_CONDITION_VALUE .format (self ._get_condition_json (index ), ))
527
+ return None
528
+
529
+ if not isinstance (user_version , string_types ):
530
+ self .logger .warning (
531
+ audience_logs .UNEXPECTED_TYPE .format (
532
+ self ._get_condition_json (index ), type (user_version ), condition_name
533
+ )
534
+ )
535
+ return None
536
+
537
+ result = self .compare_user_version_with_target_version (target_version , user_version )
487
538
if result is None :
488
539
return None
489
540
@@ -502,7 +553,23 @@ def semver_greater_than_or_equal_evaluator(self, index):
502
553
None:
503
554
- if the user version value is not string type or is null.
504
555
"""
505
- result = self .compare_user_version_with_target_version (index )
556
+ condition_name = self .condition_data [index ][0 ]
557
+ target_version = self .condition_data [index ][1 ]
558
+ user_version = self .attributes .get (condition_name )
559
+
560
+ if not isinstance (target_version , string_types ):
561
+ self .logger .warning (audience_logs .UNKNOWN_CONDITION_VALUE .format (self ._get_condition_json (index ), ))
562
+ return None
563
+
564
+ if not isinstance (user_version , string_types ):
565
+ self .logger .warning (
566
+ audience_logs .UNEXPECTED_TYPE .format (
567
+ self ._get_condition_json (index ), type (user_version ), condition_name
568
+ )
569
+ )
570
+ return None
571
+
572
+ result = self .compare_user_version_with_target_version (target_version , user_version )
506
573
if result is None :
507
574
return None
508
575
@@ -523,35 +590,35 @@ def semver_greater_than_or_equal_evaluator(self, index):
523
590
ConditionMatchTypes .SUBSTRING : substring_evaluator
524
591
}
525
592
526
- def split_version (self , target ):
593
+ def split_version (self , version ):
527
594
""" Method to split the given version.
528
595
529
596
Args:
530
- target : Given version.
597
+ version : Given version.
531
598
532
599
Returns:
533
600
List:
534
601
- The array of version split into smaller parts i.e major, minor, patch etc
535
602
None:
536
603
- if the given version is invalid in format
537
604
"""
538
- target_prefix = target
605
+ target_prefix = version
539
606
target_suffix = ""
540
607
target_parts = []
541
608
542
- # check that target shouldn't have white space
543
- if self .has_white_space (target ):
609
+ # check that version shouldn't have white space
610
+ if self .has_white_space (version ):
544
611
self .logger .warning (Errors .INVALID_ATTRIBUTE_FORMAT )
545
612
return None
546
613
547
614
# check for pre release e.g. 1.0.0-alpha where 'alpha' is a pre release
548
615
# otherwise check for build e.g. 1.0.0+001 where 001 is a build metadata
549
- if self .is_pre_release (target ):
550
- target_parts = target .split (VersionType .IS_PRE_RELEASE )
551
- elif self .is_build (target ):
552
- target_parts = target .split (VersionType .IS_BUILD )
616
+ if self .is_pre_release (version ):
617
+ target_parts = version .split (VersionType .IS_PRE_RELEASE )
618
+ elif self .is_build (version ):
619
+ target_parts = version .split (VersionType .IS_BUILD )
553
620
554
- # split target version into prefix and suffix
621
+ # split version into prefix and suffix
555
622
if target_parts :
556
623
if len (target_parts ) < 1 :
557
624
self .logger .warning (Errors .INVALID_ATTRIBUTE_FORMAT )
0 commit comments