|
|
@ -116,6 +116,7 @@ public class QualityProfileConfigYamlValidator : AbstractValidator<QualityProfil
|
|
|
|
|
|
|
|
|
|
|
|
RuleFor(x => x.Qualities)
|
|
|
|
RuleFor(x => x.Qualities)
|
|
|
|
.Custom(ValidateHaveNoDuplicates!)
|
|
|
|
.Custom(ValidateHaveNoDuplicates!)
|
|
|
|
|
|
|
|
.Custom(ValidateGroupQualityCount!)
|
|
|
|
.Must(x => x!.Any(y => y.Enabled is true or null))
|
|
|
|
.Must(x => x!.Any(y => y.Enabled is true or null))
|
|
|
|
.WithMessage(x =>
|
|
|
|
.WithMessage(x =>
|
|
|
|
$"For profile {x.Name}, at least one explicitly listed quality under 'qualities' must be enabled.")
|
|
|
|
$"For profile {x.Name}, at least one explicitly listed quality under 'qualities' must be enabled.")
|
|
|
@ -137,6 +138,22 @@ public class QualityProfileConfigYamlValidator : AbstractValidator<QualityProfil
|
|
|
|
.When(x => x is {Upgrade.Allowed: not false, Qualities.Count: > 0});
|
|
|
|
.When(x => x is {Upgrade.Allowed: not false, Qualities.Count: > 0});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void ValidateGroupQualityCount(
|
|
|
|
|
|
|
|
IReadOnlyCollection<QualityProfileQualityConfigYaml> qualities,
|
|
|
|
|
|
|
|
ValidationContext<QualityProfileConfigYaml> context)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Find groups with less than 2 items
|
|
|
|
|
|
|
|
var invalidCount = qualities
|
|
|
|
|
|
|
|
.Count(x => x.Qualities?.Count < 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (invalidCount != 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var profile = context.InstanceToValidate;
|
|
|
|
|
|
|
|
context.AddFailure(
|
|
|
|
|
|
|
|
$"For profile {profile.Name}, 'qualities' contains {invalidCount} groups with less than 2 qualities");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void ValidateHaveNoDuplicates(
|
|
|
|
private static void ValidateHaveNoDuplicates(
|
|
|
|
IReadOnlyCollection<QualityProfileQualityConfigYaml> qualities,
|
|
|
|
IReadOnlyCollection<QualityProfileQualityConfigYaml> qualities,
|
|
|
|
ValidationContext<QualityProfileConfigYaml> context)
|
|
|
|
ValidationContext<QualityProfileConfigYaml> context)
|
|
|
|