Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Accept prerelease syntax in Create Channel API (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
itowlson authored Jul 14, 2021
1 parent 884fec2 commit f323a95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Hippo/Messages/CreateChannelRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel.DataAnnotations;
using Hippo.Logging;
using Hippo.Models;
using Hippo.Rules;

namespace Hippo.Messages
{
Expand Down Expand Up @@ -65,10 +66,11 @@ public IEnumerable<ValidationResult> Validate(ValidationContext validationContex
}


if (!SemVer.Range.TryParse(RevisionRange, out _))
var ruleError = RevisionRangeRule.Validate(RevisionRange);
if (ruleError != null)
{
yield return new ValidationResult(
$"Revision Range does not comply with Semantic Versioning version number range rules",
$"Revision range is not valid rule syntax: {ruleError.Message}",
new[] { nameof(RevisionRange) });
}

Expand Down
13 changes: 13 additions & 0 deletions Hippo/Rules/RevisionRangeRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ public static RevisionRangeRule Parse(string? rule)
return new NpmRevisionRangeRule(rule);
}

public static Exception? Validate(string? rule)
{
try
{
Parse(rule);
return null;
}
catch (Exception e)
{
return e;
}
}

public abstract Revision? Match(ICollection<Revision> candidates);

private class NpmRevisionRangeRule : RevisionRangeRule
Expand Down

0 comments on commit f323a95

Please sign in to comment.