-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11066 from dependabot/dev/brettfo/nuget-end-to-en…
…d-ignore parse and honor `ignore-conditions` from job file
- Loading branch information
Showing
6 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/MiscellaneousTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using NuGet.Versioning; | ||
|
||
using NuGetUpdater.Core.Analyze; | ||
using NuGetUpdater.Core.Run; | ||
using NuGetUpdater.Core.Run.ApiModel; | ||
|
||
using Xunit; | ||
|
||
namespace NuGetUpdater.Core.Test.Run; | ||
|
||
public class MiscellaneousTests | ||
{ | ||
[Theory] | ||
[MemberData(nameof(RequirementsFromIgnoredVersionsData))] | ||
public void RequirementsFromIgnoredVersions(string dependencyName, Condition[] ignoreConditions, Requirement[] expectedRequirements) | ||
{ | ||
var job = new Job() | ||
{ | ||
Source = new() | ||
{ | ||
Provider = "github", | ||
Repo = "some/repo" | ||
}, | ||
IgnoreConditions = ignoreConditions | ||
}; | ||
var actualRequirements = RunWorker.GetIgnoredRequirementsForDependency(job, dependencyName); | ||
var actualRequirementsStrings = string.Join("|", actualRequirements.Select(r => r.ToString())); | ||
var expectedRequirementsStrings = string.Join("|", expectedRequirements.Select(r => r.ToString())); | ||
Assert.Equal(expectedRequirementsStrings, actualRequirementsStrings); | ||
} | ||
|
||
public static IEnumerable<object?[]> RequirementsFromIgnoredVersionsData() | ||
{ | ||
yield return | ||
[ | ||
// dependencyName | ||
"Some.Package", | ||
// ignoredConditions | ||
new Condition[] | ||
{ | ||
new() | ||
{ | ||
DependencyName = "SOME.PACKAGE", | ||
VersionRequirement = Requirement.Parse("> 1.2.3") | ||
}, | ||
new() | ||
{ | ||
DependencyName = "some.package", | ||
VersionRequirement = Requirement.Parse("<= 2.0.0") | ||
}, | ||
new() | ||
{ | ||
DependencyName = "Unrelated.Package", | ||
VersionRequirement = Requirement.Parse("= 3.4.5") | ||
} | ||
}, | ||
// expectedRequirements | ||
new Requirement[] | ||
{ | ||
new IndividualRequirement(">", NuGetVersion.Parse("1.2.3")), | ||
new IndividualRequirement("<=", NuGetVersion.Parse("2.0.0")), | ||
} | ||
]; | ||
|
||
// version requirement is null => ignore all | ||
yield return | ||
[ | ||
// dependencyName | ||
"Some.Package", | ||
// ignoredConditions | ||
new Condition[] | ||
{ | ||
new() | ||
{ | ||
DependencyName = "Some.Package" | ||
} | ||
}, | ||
// expectedRequirements | ||
new Requirement[] | ||
{ | ||
new IndividualRequirement(">", NuGetVersion.Parse("0.0.0")) | ||
} | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/RequirementConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace NuGetUpdater.Core.Analyze; | ||
|
||
public class RequirementConverter : JsonConverter<Requirement> | ||
{ | ||
public override Requirement? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
return Requirement.Parse(reader.GetString()!); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, Requirement value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue(value.ToString()); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Condition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
using NuGetUpdater.Core.Analyze; | ||
|
||
namespace NuGetUpdater.Core.Run.ApiModel; | ||
|
||
public sealed record Condition | ||
{ | ||
[JsonPropertyName("dependency-name")] | ||
public required string DependencyName { get; init; } | ||
[JsonPropertyName("source")] | ||
public string? Source { get; init; } = null; | ||
[JsonPropertyName("update-types")] | ||
public string[] UpdateTypes { get; init; } = []; | ||
[JsonPropertyName("updated-at")] | ||
public DateTime? UpdatedAt { get; init; } = null; | ||
[JsonPropertyName("version-requirement")] | ||
public Requirement? VersionRequirement { get; init; } = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters