dependabot-nuget 0.316.0 → 0.318.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/DependencyInfo.cs +3 -0
  3. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/VersionFinder.cs +30 -1
  4. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/FrameworkCompatibilityService.cs +25 -1
  5. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Condition.cs +13 -1
  6. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/DependencyGroup.cs +29 -18
  7. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Job.cs +7 -9
  8. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestTextGenerator.cs +6 -1
  9. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +13 -1
  10. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/CreateSecurityUpdatePullRequestHandler.cs +18 -10
  11. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/GroupUpdateAllVersionsHandler.cs +11 -16
  12. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshGroupUpdatePullRequestHandler.cs +4 -2
  13. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandler.cs +29 -13
  14. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandler.cs +25 -7
  15. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs +15 -8
  16. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/SpecialImportsConditionPatcher.cs +15 -2
  17. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +11 -3
  18. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/VersionFinderTests.cs +39 -0
  19. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/FrameworkCompatibilityServiceFacts.cs +8 -11
  20. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/MiscellaneousTests.cs +108 -15
  21. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestTextTests.cs +39 -0
  22. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/SerializationTests.cs +2 -2
  23. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/GroupUpdateAllVersionsHandlerTests.cs +291 -0
  24. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshGroupUpdatePullRequestHandlerTests.cs +311 -6
  25. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandlerTests.cs +273 -0
  26. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandlerTests.cs +307 -0
  27. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackageReferenceUpdaterTests.cs +51 -1
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/SpecialFilePatcherTests.cs +25 -0
  29. metadata +4 -4
@@ -2,6 +2,8 @@ using System.Collections.Immutable;
2
2
 
3
3
  using Microsoft.Language.Xml;
4
4
 
5
+ using NuGetUpdater.Core.Utilities;
6
+
5
7
  namespace NuGetUpdater.Core.Updater
6
8
  {
7
9
  internal class SpecialImportsConditionPatcher : IDisposable
@@ -24,9 +26,20 @@ namespace NuGetUpdater.Core.Updater
24
26
 
25
27
  public SpecialImportsConditionPatcher(string projectFilePath)
26
28
  {
29
+ var hasBOM = false;
27
30
  _processor = new XmlFilePreAndPostProcessor(
28
- getContent: () => File.ReadAllText(projectFilePath),
29
- setContent: s => File.WriteAllText(projectFilePath, s),
31
+ getContent: () =>
32
+ {
33
+ var content = File.ReadAllText(projectFilePath);
34
+ var rawContent = File.ReadAllBytes(projectFilePath);
35
+ hasBOM = rawContent.HasBOM();
36
+ return content;
37
+ },
38
+ setContent: content =>
39
+ {
40
+ var rawContent = content.SetBOM(hasBOM);
41
+ File.WriteAllBytes(projectFilePath, rawContent);
42
+ },
30
43
  nodeFinder: doc => doc.Descendants()
31
44
  .Where(e => e.Name == "Import")
32
45
  .Where(e =>
@@ -478,7 +478,7 @@ internal static partial class MSBuildHelper
478
478
  // Return as array
479
479
  var candidatePackagesArray = candidatePackages.ToImmutableArray();
480
480
 
481
- var targetFrameworks = new NuGetFramework[] { NuGetFramework.Parse(targetFramework) };
481
+ var targetFrameworks = ImmutableArray.Create<NuGetFramework>(NuGetFramework.Parse(targetFramework));
482
482
 
483
483
  var resolveProjectPath = projectPath;
484
484
 
@@ -492,15 +492,23 @@ internal static partial class MSBuildHelper
492
492
  // Target framework compatibility check
493
493
  foreach (var package in candidatePackages)
494
494
  {
495
- if (!NuGetVersion.TryParse(package.Version, out var nuGetVersion))
495
+ if (package.Version is null ||
496
+ !VersionRange.TryParse(package.Version, out var nuGetVersionRange))
496
497
  {
497
498
  // If version is not valid, return original packages and revert
498
499
  return packages;
499
500
  }
500
501
 
502
+ if (nuGetVersionRange.IsFloating)
503
+ {
504
+ // If a wildcard version, the original project specified it this way and we can count on restore to do the appropriate thing
505
+ continue;
506
+ }
507
+
508
+ var nuGetVersion = nuGetVersionRange.MinVersion; // not a wildcard, so `MinVersion` is just the version itself
501
509
  var packageIdentity = new NuGet.Packaging.Core.PackageIdentity(package.Name, nuGetVersion);
502
510
 
503
- bool isNewPackageCompatible = await CompatibilityChecker.CheckAsync(packageIdentity, targetFrameworks.ToImmutableArray(), nugetContext, logger, CancellationToken.None);
511
+ bool isNewPackageCompatible = await CompatibilityChecker.CheckAsync(packageIdentity, targetFrameworks, nugetContext, logger, CancellationToken.None);
504
512
  if (!isNewPackageCompatible)
505
513
  {
506
514
  // If the package target framework is not compatible, return original packages and revert
@@ -296,4 +296,43 @@ public class VersionFinderTests : TestBase
296
296
  var actualJson = JsonSerializer.Serialize(error, RunWorker.SerializerOptions);
297
297
  Assert.Equal(expectedJson, actualJson);
298
298
  }
299
+
300
+ [Theory]
301
+ [InlineData(null, "1.0.1", "1.1.0", "2.0.0")]
302
+ [InlineData(ConditionUpdateType.SemVerMajor, "1.0.1", "1.1.0")]
303
+ [InlineData(ConditionUpdateType.SemVerMinor, "1.0.1")]
304
+ [InlineData(ConditionUpdateType.SemVerPatch)]
305
+ public async Task VersionFinder_IgnoredUpdateTypesIsHonored(ConditionUpdateType? ignoredUpdateType, params string[] expectedVersions)
306
+ {
307
+ // arrange
308
+ using var tempDir = new TemporaryDirectory();
309
+ await UpdateWorkerTestBase.MockNuGetPackagesInDirectory([
310
+ MockNuGetPackage.CreateSimplePackage("Some.Dependency", "1.0.1", "net9.0"),
311
+ MockNuGetPackage.CreateSimplePackage("Some.Dependency", "1.1.0", "net9.0"),
312
+ MockNuGetPackage.CreateSimplePackage("Some.Dependency", "2.0.0", "net9.0"),
313
+ ], tempDir.DirectoryPath);
314
+ var tfm = NuGetFramework.Parse("net9.0");
315
+ var ignoredUpdateTypes = ignoredUpdateType is not null
316
+ ? new ConditionUpdateType[] { ignoredUpdateType.Value }
317
+ : [];
318
+ var dependencyInfo = new DependencyInfo()
319
+ {
320
+ Name = "Some.Dependency",
321
+ Version = "1.0.0",
322
+ IsVulnerable = false,
323
+ IgnoredVersions = [],
324
+ Vulnerabilities = [],
325
+ IgnoredUpdateTypes = [.. ignoredUpdateTypes],
326
+ };
327
+ var logger = new TestLogger();
328
+ var nugetContext = new NuGetContext(tempDir.DirectoryPath);
329
+
330
+ // act
331
+ var versionResult = await VersionFinder.GetVersionsAsync([tfm], dependencyInfo, nugetContext, logger, CancellationToken.None);
332
+ var versions = versionResult.GetVersions();
333
+
334
+ // assert
335
+ var actualVersions = versions.Select(v => v.ToString()).OrderBy(v => v).ToArray();
336
+ AssertEx.Equal(expectedVersions, actualVersions);
337
+ }
299
338
  }
@@ -1,10 +1,6 @@
1
1
  // Copyright (c) .NET Foundation. All rights reserved.
2
2
  // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
 
4
- using System;
5
- using System.Collections.Generic;
6
- using System.Linq;
7
-
8
4
  using NuGet.Frameworks;
9
5
 
10
6
  using NuGetUpdater.Core.FrameworkChecker;
@@ -64,17 +60,18 @@ public class FrameworkCompatibilityServiceFacts
64
60
  }
65
61
 
66
62
  [Theory]
67
- [InlineData("portable-net45+sl4+win8+wp7")]
68
- [InlineData("portable-net40+sl4")]
69
- [InlineData("portable-net45+sl5+win8+wpa81+wp8")]
70
- public void PCLPackageFrameworksReturnsEmptySet(string pclFrameworkName)
63
+ [InlineData("portable-net45+win8+wpa81", "net48", true)] // profile 111, compatible
64
+ [InlineData("portable-net45+win8+wpa81", "net40", false)] // profile 111, incompatible
65
+ [InlineData("portable-net45+win8+wp8+wpa81", "net48", true)] // profile 259, compatible
66
+ public void PCLPackageFrameworksReportCompatibility(string pclFrameworkName, string projectFrameworkName, bool expectedCompatible)
71
67
  {
72
68
  var portableFramework = NuGetFramework.Parse(pclFrameworkName);
69
+ var projectFramework = NuGetFramework.Parse(projectFrameworkName);
73
70
 
74
- var result = _service.GetCompatibleFrameworks([portableFramework]);
71
+ var compatible = _service.GetCompatibleFrameworks([portableFramework]);
75
72
 
76
- Assert.True(portableFramework.IsPCL);
77
- Assert.Empty(result);
73
+ var actualCompatible = compatible.Contains(projectFramework);
74
+ Assert.Equal(expectedCompatible, actualCompatible);
78
75
  }
79
76
 
80
77
  [Theory]
@@ -16,8 +16,8 @@ namespace NuGetUpdater.Core.Test.Run;
16
16
  public class MiscellaneousTests
17
17
  {
18
18
  [Theory]
19
- [MemberData(nameof(IsDependencyIgnoredTestData))]
20
- public void IsDependencyIgnored(Condition[] ignoreConditions, string dependencyName, string dependencyVersion, bool expectedIgnored)
19
+ [MemberData(nameof(IsDependencyIgnoredByNameOnlyTestData))]
20
+ public void IsDependencyIgnoredByNameOnly(Condition[] ignoreConditions, string dependencyName, bool expectedIgnored)
21
21
  {
22
22
  // arrange
23
23
  var job = new Job()
@@ -31,14 +31,15 @@ public class MiscellaneousTests
31
31
  };
32
32
 
33
33
  // act
34
- var actualIsIgnored = job.IsDependencyIgnored(dependencyName, dependencyVersion);
34
+ var actualIsIgnored = job.IsDependencyIgnoredByNameOnly(dependencyName);
35
35
 
36
36
  // assert
37
37
  Assert.Equal(expectedIgnored, actualIsIgnored);
38
38
  }
39
39
 
40
- public static IEnumerable<object[]> IsDependencyIgnoredTestData()
40
+ public static IEnumerable<object[]> IsDependencyIgnoredByNameOnlyTestData()
41
41
  {
42
+ // non-matching name
42
43
  yield return
43
44
  [
44
45
  // ignoreConditions
@@ -51,12 +52,11 @@ public class MiscellaneousTests
51
52
  },
52
53
  // dependencyName
53
54
  "Some.Dependency",
54
- // dependencyVersion
55
- "1.2.3",
56
55
  // expectedIgnored
57
56
  false,
58
57
  ];
59
58
 
59
+ // matching name, but has version requirement
60
60
  yield return
61
61
  [
62
62
  // ignoreConditions
@@ -70,12 +70,11 @@ public class MiscellaneousTests
70
70
  },
71
71
  // dependencyName
72
72
  "Some.Dependency",
73
- // dependencyVersion
74
- "1.2.3",
75
73
  // expectedIgnored
76
74
  false,
77
75
  ];
78
76
 
77
+ // wildcard matching name
79
78
  yield return
80
79
  [
81
80
  // ignoreConditions
@@ -83,18 +82,34 @@ public class MiscellaneousTests
83
82
  {
84
83
  new Condition()
85
84
  {
86
- DependencyName = "Some.Dependency",
87
- VersionRequirement = Requirement.Parse("> 1.0.0"),
85
+ DependencyName = "Some.*",
88
86
  }
89
87
  },
90
88
  // dependencyName
91
89
  "Some.Dependency",
92
- // dependencyVersion
93
- "1.2.3",
94
90
  // expectedIgnored
95
91
  true,
96
92
  ];
97
93
 
94
+ // matching name, but has update type restrictions
95
+ yield return
96
+ [
97
+ // ignoreConditions
98
+ new[]
99
+ {
100
+ new Condition()
101
+ {
102
+ DependencyName = "Some.*",
103
+ UpdateTypes = [ConditionUpdateType.SemVerMajor],
104
+ }
105
+ },
106
+ // dependencyName
107
+ "Some.Dependency",
108
+ // expectedIgnored
109
+ false,
110
+ ];
111
+
112
+ // explicitly null update types
98
113
  yield return
99
114
  [
100
115
  // ignoreConditions
@@ -103,17 +118,56 @@ public class MiscellaneousTests
103
118
  new Condition()
104
119
  {
105
120
  DependencyName = "Some.*",
121
+ UpdateTypes = null,
106
122
  }
107
123
  },
108
124
  // dependencyName
109
125
  "Some.Dependency",
110
- // dependencyVersion
111
- "1.2.3",
112
126
  // expectedIgnored
113
127
  true,
114
128
  ];
115
129
  }
116
130
 
131
+ [Fact]
132
+ public void DeserializeDependencyGroup()
133
+ {
134
+ var json = """
135
+ {
136
+ "name": "test-group",
137
+ "rules": {
138
+ "patterns": ["Test.*"],
139
+ "exclude-patterns": ["Dependency.*"]
140
+ }
141
+ }
142
+ """;
143
+ var group = JsonSerializer.Deserialize<DependencyGroup>(json, RunWorker.SerializerOptions);
144
+ Assert.NotNull(group);
145
+ Assert.Equal("test-group", group.Name);
146
+ var matcher = group.GetGroupMatcher();
147
+ Assert.Equal(["Test.*"], matcher.Patterns);
148
+ Assert.Equal(["Dependency.*"], matcher.ExcludePatterns);
149
+ }
150
+
151
+ [Fact]
152
+ public void DeserializeDependencyGroup_UnexpectedShape()
153
+ {
154
+ var json = """
155
+ {
156
+ "name": "test-group",
157
+ "rules": {
158
+ "patterns": { "unexpected": 1 },
159
+ "exclude-patterns": { "unexpected": 2 }
160
+ }
161
+ }
162
+ """;
163
+ var group = JsonSerializer.Deserialize<DependencyGroup>(json, RunWorker.SerializerOptions);
164
+ Assert.NotNull(group);
165
+ Assert.Equal("test-group", group.Name);
166
+ var matcher = group.GetGroupMatcher();
167
+ Assert.Equal([], matcher.Patterns);
168
+ Assert.Equal([], matcher.ExcludePatterns);
169
+ }
170
+
117
171
  [Theory]
118
172
  [MemberData(nameof(DependencyGroup_IsMatchTestData))]
119
173
  public void DependencyGroup_IsMatch(string[]? patterns, string[]? excludePatterns, string dependencyName, bool expectedMatch)
@@ -625,6 +679,7 @@ public class MiscellaneousTests
625
679
 
626
680
  public static IEnumerable<object[]> DependencyInfoFromJobData()
627
681
  {
682
+ // with security advisory
628
683
  yield return
629
684
  [
630
685
  // job
@@ -667,7 +722,45 @@ public class MiscellaneousTests
667
722
  VulnerableVersions = [Requirement.Parse(">= 1.0.0, < 1.1.0")],
668
723
  SafeVersions = [Requirement.Parse("= 1.1.0"), Requirement.Parse("= 1.2.0")],
669
724
  }
670
- ]
725
+ ],
726
+ IgnoredUpdateTypes = [],
727
+ }
728
+ ];
729
+
730
+ yield return
731
+ [
732
+ // job
733
+ new Job()
734
+ {
735
+ Source = new()
736
+ {
737
+ Provider = "github",
738
+ Repo = "some/repo",
739
+ },
740
+ IgnoreConditions = [
741
+ new Condition()
742
+ {
743
+ DependencyName = "Some.*",
744
+ UpdateTypes = [ConditionUpdateType.SemVerMajor],
745
+ },
746
+ new Condition()
747
+ {
748
+ DependencyName = "Unrelated.*",
749
+ UpdateTypes = [ConditionUpdateType.SemVerMinor],
750
+ },
751
+ ],
752
+ },
753
+ // dependency
754
+ new Dependency("Some.Dependency", "1.0.0", DependencyType.PackageReference),
755
+ // expectedDependencyInfo
756
+ new DependencyInfo()
757
+ {
758
+ Name = "Some.Dependency",
759
+ Version = "1.0.0",
760
+ IsVulnerable = false,
761
+ IgnoredVersions = [],
762
+ Vulnerabilities = [],
763
+ IgnoredUpdateTypes = [ConditionUpdateType.SemVerMajor],
671
764
  }
672
765
  ];
673
766
  }
@@ -402,6 +402,45 @@ public class PullRequestTextTests
402
402
  - Updated Package.B from 4.0.0 to 4.5.6 in a.txt
403
403
  """
404
404
  ];
405
+
406
+ // multiple updates to the same dependency
407
+ yield return
408
+ [
409
+ // job
410
+ FromCommitOptions(null),
411
+ // updateOperationsPerformed
412
+ new UpdateOperationBase[]
413
+ {
414
+ new DirectUpdate()
415
+ {
416
+ DependencyName = "Some.Package",
417
+ OldVersion = NuGetVersion.Parse("1.0.0"),
418
+ NewVersion = NuGetVersion.Parse("1.2.3"),
419
+ UpdatedFiles = ["a.txt"]
420
+ },
421
+ new DirectUpdate()
422
+ {
423
+ DependencyName = "Some.Package",
424
+ OldVersion = NuGetVersion.Parse("1.0.0"),
425
+ NewVersion = NuGetVersion.Parse("1.2.3"),
426
+ UpdatedFiles = ["b.txt"]
427
+ }
428
+ },
429
+ // dependencyGroupName
430
+ null,
431
+ // expectedTitle
432
+ "Bump Some.Package to 1.2.3",
433
+ // expectedCommitMessage
434
+ """
435
+ Bump Some.Package to 1.2.3
436
+ """,
437
+ // expectedBody
438
+ """
439
+ Performed the following updates:
440
+ - Updated Some.Package from 1.0.0 to 1.2.3 in a.txt
441
+ - Updated Some.Package from 1.0.0 to 1.2.3 in b.txt
442
+ """
443
+ ];
405
444
  }
406
445
 
407
446
  private static Job FromCommitOptions(CommitOptions? commitOptions)
@@ -316,13 +316,13 @@ public class SerializationTests : TestBase
316
316
 
317
317
  Assert.Equal("Package.1", jobWrapper.Job.IgnoreConditions[0].DependencyName);
318
318
  Assert.Equal("some-file", jobWrapper.Job.IgnoreConditions[0].Source);
319
- Assert.Equal("version-update:semver-major", jobWrapper.Job.IgnoreConditions[0].UpdateTypes.Single());
319
+ Assert.Equal(ConditionUpdateType.SemVerMajor, jobWrapper.Job.IgnoreConditions[0].UpdateTypes!.Single());
320
320
  Assert.Null(jobWrapper.Job.IgnoreConditions[0].UpdatedAt);
321
321
  Assert.Equal("> 1.2.3", jobWrapper.Job.IgnoreConditions[0].VersionRequirement?.ToString());
322
322
 
323
323
  Assert.Equal("Package.2", jobWrapper.Job.IgnoreConditions[1].DependencyName);
324
324
  Assert.Null(jobWrapper.Job.IgnoreConditions[1].Source);
325
- Assert.Empty(jobWrapper.Job.IgnoreConditions[1].UpdateTypes);
325
+ Assert.Null(jobWrapper.Job.IgnoreConditions[1].UpdateTypes);
326
326
  Assert.Equal(new DateTime(2024, 12, 5, 15, 47, 12), jobWrapper.Job.IgnoreConditions[1].UpdatedAt);
327
327
  Assert.Null(jobWrapper.Job.IgnoreConditions[1].VersionRequirement);
328
328
  }