fix(schedules): corrected serialization of pathRegex
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

This commit is contained in:
D. Moonfire 2023-01-18 22:32:54 -06:00
parent 2e93ebdb7c
commit 185980b5c4
2 changed files with 16 additions and 6 deletions

View file

@ -21,7 +21,7 @@ public partial class NumericalPathSchedule : ISchedule
{
public NumericalPathSchedule()
{
this.PathRegex = new Regex(@"^.*(\d+)");
this.PathRegex = @"^.*(\d+)";
this.GetPath = entity => entity.Get<UPath>().ToString();
this.CaptureGroup = 1;
this.CaptureOffset = -1;
@ -47,7 +47,7 @@ public partial class NumericalPathSchedule : ISchedule
/// <summary>
/// Gets or sets the regular expression to identify a matching path.
/// </summary>
public Regex? PathRegex { get; set; }
public string? PathRegex { get; set; }
/// <summary>
/// Gets or sets the period between each matching entity. The period is
@ -83,7 +83,8 @@ public partial class NumericalPathSchedule : ISchedule
{
// Get the path and match it.
string? path = this.GetPath(entity);
Match? match = this.PathRegex?.Match(path)
Regex? regex = this.GetRegex();
Match? match = regex?.Match(path)
?? throw new NullReferenceException(
"PathRegex was not configured for the "
+ this.GetType().Name
@ -116,12 +117,20 @@ public partial class NumericalPathSchedule : ISchedule
/// <inheritdoc />
public virtual bool CanApply(Entity entity)
{
string? path = this.GetPath(entity);
bool match = this.PathRegex?.IsMatch(path) ?? false;
string path = this.GetPath(entity);
Regex? regex = this.GetRegex();
bool match = regex?.IsMatch(path) ?? false;
return match;
}
public Regex? GetRegex()
{
return this.PathRegex == null
? null
: new Regex(this.PathRegex);
}
protected virtual Entity Apply(
Entity entity,
int number,

View file

@ -47,7 +47,8 @@ public class NumericalPathScheduleTests : TemporalSchedulesTestBase
"---",
"access: custom",
"schedules:",
" - scheduleStart: 2023-01-01",
" - pathRegex: chapter-(\\d+)",
" scheduleStart: 2023-01-01",
" access: public",
""));
List<TestSchedule>? schedules = model.Schedules!;