dependabot-nuget 0.304.0 → 0.305.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/Directory.Packages.props +5 -5
  3. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/AnalyzeCommand.cs +1 -1
  4. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/CloneCommand.cs +1 -1
  5. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/DiscoverCommand.cs +2 -2
  6. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/RunCommand.cs +1 -1
  7. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/UpdateCommand.cs +1 -1
  8. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/AnalyzeWorker.cs +1 -1
  9. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DiscoveryWorker.cs +1 -1
  10. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/ProjectBuildFile.cs +3 -1
  11. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/NuGetUpdater.Core.csproj +4 -0
  12. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/JobErrorBase.cs +1 -0
  13. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestTextGenerator.cs +13 -12
  14. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +52 -21
  15. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs +13 -2
  16. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdateOperationBase.cs +3 -3
  17. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +1 -1
  18. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +33 -12
  19. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/OpenTelemetryLogger.cs +54 -0
  20. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.cs +77 -0
  21. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestMessageTests.cs +45 -2
  22. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestTextTests.cs +63 -44
  23. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs +56 -8
  24. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdatePermittedAndMessageTests.cs +90 -23
  25. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestBase.cs +1 -1
  26. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackageReferenceUpdaterTests.cs +60 -0
  27. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/LoggerTests.cs +61 -0
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +44 -0
  29. metadata +7 -5
@@ -1324,6 +1324,83 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
1324
1324
  );
1325
1325
  }
1326
1326
 
1327
+ [Fact]
1328
+ public async Task ReportsPrivateSourceBadResponseFailureOnServiceUnavailable()
1329
+ {
1330
+ static (int, string) TestHttpHandler(string uriString)
1331
+ {
1332
+ var uri = new Uri(uriString, UriKind.Absolute);
1333
+ var baseUrl = $"{uri.Scheme}://{uri.Host}:{uri.Port}";
1334
+ return uri.PathAndQuery switch
1335
+ {
1336
+ // initial request is good
1337
+ "/index.json" => (200, $$"""
1338
+ {
1339
+ "version": "3.0.0",
1340
+ "resources": [
1341
+ {
1342
+ "@id": "{{baseUrl}}/download",
1343
+ "@type": "PackageBaseAddress/3.0.0"
1344
+ },
1345
+ {
1346
+ "@id": "{{baseUrl}}/query",
1347
+ "@type": "SearchQueryService"
1348
+ },
1349
+ {
1350
+ "@id": "{{baseUrl}}/registrations",
1351
+ "@type": "RegistrationsBaseUrl"
1352
+ }
1353
+ ]
1354
+ }
1355
+ """),
1356
+ // all other requests are unauthorized
1357
+ _ => (503, "{}"),
1358
+ };
1359
+ }
1360
+ // override various nuget locations
1361
+ using var tempDir = new TemporaryDirectory();
1362
+ using var _ = new TemporaryEnvironment(
1363
+ [
1364
+ ("NUGET_PACKAGES", Path.Combine(tempDir.DirectoryPath, "NUGET_PACKAGES")),
1365
+ ("NUGET_HTTP_CACHE_PATH", Path.Combine(tempDir.DirectoryPath, "NUGET_HTTP_CACHE_PATH")),
1366
+ ("NUGET_SCRATCH", Path.Combine(tempDir.DirectoryPath, "NUGET_SCRATCH")),
1367
+ ("NUGET_PLUGINS_CACHE_PATH", Path.Combine(tempDir.DirectoryPath, "NUGET_PLUGINS_CACHE_PATH")),
1368
+ ]);
1369
+ using var http = TestHttpServer.CreateTestStringServer(TestHttpHandler);
1370
+ var experimentsManager = new ExperimentsManager() { UseDirectDiscovery = true };
1371
+ await TestDiscoveryAsync(
1372
+ experimentsManager: experimentsManager,
1373
+ workspacePath: "",
1374
+ files:
1375
+ [
1376
+ ("project.csproj", """
1377
+ <Project Sdk="Microsoft.NET.Sdk">
1378
+ <PropertyGroup>
1379
+ <TargetFramework>net8.0</TargetFramework>
1380
+ </PropertyGroup>
1381
+ <ItemGroup>
1382
+ <PackageReference Include="Some.Package" Version="1.2.3" />
1383
+ </ItemGroup>
1384
+ </Project>
1385
+ """),
1386
+ ("NuGet.Config", $"""
1387
+ <configuration>
1388
+ <packageSources>
1389
+ <clear />
1390
+ <add key="private_feed" value="{http.BaseUrl.TrimEnd('/')}/index.json" allowInsecureConnections="true" />
1391
+ </packageSources>
1392
+ </configuration>
1393
+ """),
1394
+ ],
1395
+ expectedResult: new()
1396
+ {
1397
+ Error = new PrivateSourceBadResponse([$"{http.BaseUrl.TrimEnd('/')}/index.json"]),
1398
+ Path = "",
1399
+ Projects = [],
1400
+ }
1401
+ );
1402
+ }
1403
+
1327
1404
  [LinuxOnlyFact]
1328
1405
  public async Task DiscoverySucceedsWhenNoWindowsAppRefPackageCanBeFound()
1329
1406
  {
@@ -2,6 +2,7 @@ using NuGet.Versioning;
2
2
 
3
3
  using NuGetUpdater.Core.Run;
4
4
  using NuGetUpdater.Core.Run.ApiModel;
5
+ using NuGetUpdater.Core.Updater;
5
6
 
6
7
  using Xunit;
7
8
 
@@ -11,9 +12,9 @@ public class PullRequestMessageTests
11
12
  {
12
13
  [Theory]
13
14
  [MemberData(nameof(GetPullRequestApiMessageData))]
14
- public void GetPullRequestApiMessage(Job job, DependencyFile[] updatedFiles, ReportedDependency[] updatedDependencies, MessageBase expectedMessage)
15
+ public void GetPullRequestApiMessage(Job job, DependencyFile[] updatedFiles, ReportedDependency[] updatedDependencies, UpdateOperationBase[] updateOperationsPerformed, MessageBase expectedMessage)
15
16
  {
16
- var actualMessage = RunWorker.GetPullRequestApiMessage(job, updatedFiles, updatedDependencies, "TEST-COMMIT-SHA");
17
+ var actualMessage = RunWorker.GetPullRequestApiMessage(job, updatedFiles, updatedDependencies, [.. updateOperationsPerformed], "TEST-COMMIT-SHA");
17
18
  Assert.NotNull(actualMessage);
18
19
  actualMessage = actualMessage switch
19
20
  {
@@ -62,6 +63,16 @@ public class PullRequestMessageTests
62
63
  Requirements = [],
63
64
  }
64
65
  },
66
+ // updateOperationsPerformed
67
+ new UpdateOperationBase[]
68
+ {
69
+ new DirectUpdate()
70
+ {
71
+ DependencyName = "Some.Dependency",
72
+ NewVersion = NuGetVersion.Parse("1.0.1"),
73
+ UpdatedFiles = ["/src/project.csproj"]
74
+ }
75
+ },
65
76
  // expectedMessage
66
77
  new CreatePullRequest()
67
78
  {
@@ -106,6 +117,16 @@ public class PullRequestMessageTests
106
117
  Requirements = [], // not used
107
118
  }
108
119
  },
120
+ // updateOperationsPerformed
121
+ new UpdateOperationBase[]
122
+ {
123
+ new DirectUpdate()
124
+ {
125
+ DependencyName = "Some.Dependency",
126
+ NewVersion = NuGetVersion.Parse("1.0.1"),
127
+ UpdatedFiles = ["/src/project.csproj"]
128
+ }
129
+ },
109
130
  // expectedMessage
110
131
  new ClosePullRequest() { DependencyNames = ["Some.Dependency"], Reason = "up_to_date" },
111
132
  ];
@@ -140,6 +161,8 @@ public class PullRequestMessageTests
140
161
  Array.Empty<DependencyFile>(),
141
162
  // updatedDependencies
142
163
  Array.Empty<ReportedDependency>(),
164
+ // updateOperationsPerformed
165
+ new UpdateOperationBase[] { },
143
166
  // expectedMessage
144
167
  new ClosePullRequest() { DependencyNames = ["Some.Dependency"], Reason = "dependency_removed" },
145
168
  ];
@@ -183,6 +206,16 @@ public class PullRequestMessageTests
183
206
  Requirements = [],
184
207
  }
185
208
  },
209
+ // updateOperationsPerformed
210
+ new UpdateOperationBase[]
211
+ {
212
+ new DirectUpdate()
213
+ {
214
+ DependencyName = "Some.Dependency",
215
+ NewVersion = NuGetVersion.Parse("1.0.1"),
216
+ UpdatedFiles = ["/src/project.csproj"]
217
+ }
218
+ },
186
219
  // expectedMessage
187
220
  new UpdatePullRequest()
188
221
  {
@@ -236,6 +269,16 @@ public class PullRequestMessageTests
236
269
  Requirements = [],
237
270
  }
238
271
  },
272
+ // updateOperationsPerformed
273
+ new UpdateOperationBase[]
274
+ {
275
+ new DirectUpdate()
276
+ {
277
+ DependencyName = "Some.Dependency",
278
+ NewVersion = NuGetVersion.Parse("1.0.1"),
279
+ UpdatedFiles = ["/src/project.csproj"]
280
+ }
281
+ },
239
282
  // expectedMessage
240
283
  new UpdatePullRequest()
241
284
  {
@@ -1,5 +1,10 @@
1
+ using System.Collections.Immutable;
2
+
3
+ using NuGet.Versioning;
4
+
1
5
  using NuGetUpdater.Core.Run;
2
6
  using NuGetUpdater.Core.Run.ApiModel;
7
+ using NuGetUpdater.Core.Updater;
3
8
 
4
9
  using Xunit;
5
10
 
@@ -9,14 +14,22 @@ public class PullRequestTextTests
9
14
  {
10
15
  [Theory]
11
16
  [MemberData(nameof(GetPullRequestTextTestData))]
12
- public void PullRequestText(Job job, ReportedDependency[] updatedDependencies, DependencyFile[] updatedFiles, string? dependencyGroupName, string expectedTitle, string expectedCommitMessage, string expectedBody)
17
+ public void PullRequestText(
18
+ Job job,
19
+ UpdateOperationBase[] updateOperationsPerformed,
20
+ string? dependencyGroupName,
21
+ string expectedTitle,
22
+ string expectedCommitMessage,
23
+ string expectedBody
24
+ )
13
25
  {
14
- var actualTitle = PullRequestTextGenerator.GetPullRequestTitle(job, updatedDependencies, updatedFiles, dependencyGroupName);
15
- var actualCommitMessage = PullRequestTextGenerator.GetPullRequestCommitMessage(job, updatedDependencies, updatedFiles, dependencyGroupName);
16
- var actualBody = PullRequestTextGenerator.GetPullRequestBody(job, updatedDependencies, updatedFiles, dependencyGroupName);
26
+ var updateOperationsPerformedImmutable = updateOperationsPerformed.ToImmutableArray();
27
+ var actualTitle = PullRequestTextGenerator.GetPullRequestTitle(job, updateOperationsPerformedImmutable, dependencyGroupName);
28
+ var actualCommitMessage = PullRequestTextGenerator.GetPullRequestCommitMessage(job, updateOperationsPerformedImmutable, dependencyGroupName);
29
+ var actualBody = PullRequestTextGenerator.GetPullRequestBody(job, updateOperationsPerformedImmutable, dependencyGroupName);
17
30
  Assert.Equal(expectedTitle, actualTitle);
18
31
  Assert.Equal(expectedCommitMessage, actualCommitMessage);
19
- Assert.Equal(expectedBody, actualBody);
32
+ Assert.Equal(expectedBody.Replace("\r", ""), actualBody);
20
33
  }
21
34
 
22
35
  public static IEnumerable<object?[]> GetPullRequestTextTestData()
@@ -26,18 +39,16 @@ public class PullRequestTextTests
26
39
  [
27
40
  // job
28
41
  FromCommitOptions(null),
29
- // updatedDependencies
30
- new []
42
+ // updateOperationsPerformed
43
+ new UpdateOperationBase[]
31
44
  {
32
- new ReportedDependency()
45
+ new DirectUpdate()
33
46
  {
34
- Name = "Some.Package",
35
- Version = "1.2.3",
36
- Requirements = []
47
+ DependencyName = "Some.Package",
48
+ NewVersion = NuGetVersion.Parse("1.2.3"),
49
+ UpdatedFiles = ["a.txt"]
37
50
  }
38
51
  },
39
- // updatedFiles
40
- Array.Empty<DependencyFile>(),
41
52
  // dependencyGroupName
42
53
  null,
43
54
  // expectedTitle
@@ -45,7 +56,10 @@ public class PullRequestTextTests
45
56
  // expectedCommitMessage
46
57
  "Update Some.Package to 1.2.3",
47
58
  // expectedBody
48
- "Update Some.Package to 1.2.3"
59
+ """
60
+ Performed the following updates:
61
+ - Updated Some.Package to 1.2.3 in a.txt
62
+ """
49
63
  ];
50
64
 
51
65
  // single dependency, prefix given
@@ -53,18 +67,16 @@ public class PullRequestTextTests
53
67
  [
54
68
  // job
55
69
  FromCommitOptions(new(){ Prefix = "[SECURITY] " }),
56
- // updatedDependencies
57
- new []
70
+ // updateOperationsPerformed
71
+ new UpdateOperationBase[]
58
72
  {
59
- new ReportedDependency()
73
+ new DirectUpdate()
60
74
  {
61
- Name = "Some.Package",
62
- Version = "1.2.3",
63
- Requirements = []
75
+ DependencyName = "Some.Package",
76
+ NewVersion = NuGetVersion.Parse("1.2.3"),
77
+ UpdatedFiles = ["a.txt"]
64
78
  }
65
79
  },
66
- // updatedFiles
67
- Array.Empty<DependencyFile>(),
68
80
  // dependencyGroupName
69
81
  null,
70
82
  // expectedTitle
@@ -72,7 +84,10 @@ public class PullRequestTextTests
72
84
  // expectedCommitMessage
73
85
  "[SECURITY] Update Some.Package to 1.2.3",
74
86
  // expectedBody
75
- "[SECURITY] Update Some.Package to 1.2.3"
87
+ """
88
+ Performed the following updates:
89
+ - Updated Some.Package to 1.2.3 in a.txt
90
+ """
76
91
  ];
77
92
 
78
93
  // multiple dependencies, multiple versions
@@ -80,36 +95,34 @@ public class PullRequestTextTests
80
95
  [
81
96
  // job
82
97
  FromCommitOptions(null),
83
- // updatedDependencies
84
- new[]
98
+ // updateOperationsPerformed
99
+ new UpdateOperationBase[]
85
100
  {
86
- new ReportedDependency()
101
+ new DirectUpdate()
87
102
  {
88
- Name = "Package.A",
89
- Version = "1.0.0",
90
- Requirements = []
103
+ DependencyName = "Package.A",
104
+ NewVersion = NuGetVersion.Parse("1.0.0"),
105
+ UpdatedFiles = ["a1.txt"]
91
106
  },
92
- new ReportedDependency()
107
+ new DirectUpdate()
93
108
  {
94
- Name = "Package.A",
95
- Version = "2.0.0",
96
- Requirements = []
109
+ DependencyName = "Package.A",
110
+ NewVersion = NuGetVersion.Parse("2.0.0"),
111
+ UpdatedFiles = ["a2.txt"]
97
112
  },
98
- new ReportedDependency()
113
+ new DirectUpdate()
99
114
  {
100
- Name = "Package.B",
101
- Version = "3.0.0",
102
- Requirements = []
115
+ DependencyName = "Package.B",
116
+ NewVersion = NuGetVersion.Parse("3.0.0"),
117
+ UpdatedFiles = ["b1.txt"]
103
118
  },
104
- new ReportedDependency()
119
+ new DirectUpdate()
105
120
  {
106
- Name = "Package.B",
107
- Version = "4.0.0",
108
- Requirements = []
121
+ DependencyName = "Package.B",
122
+ NewVersion = NuGetVersion.Parse("4.0.0"),
123
+ UpdatedFiles = ["b2.txt"]
109
124
  },
110
125
  },
111
- // updatedFiles
112
- Array.Empty<DependencyFile>(),
113
126
  // dependencyGroupName
114
127
  null,
115
128
  // expectedTitle
@@ -117,7 +130,13 @@ public class PullRequestTextTests
117
130
  // expectedCommitMessage
118
131
  "Update Package.A to 1.0.0, 2.0.0; Package.B to 3.0.0, 4.0.0",
119
132
  // expectedBody
120
- "Update Package.A to 1.0.0, 2.0.0; Package.B to 3.0.0, 4.0.0"
133
+ """
134
+ Performed the following updates:
135
+ - Updated Package.A to 1.0.0 in a1.txt
136
+ - Updated Package.A to 2.0.0 in a2.txt
137
+ - Updated Package.B to 3.0.0 in b1.txt
138
+ - Updated Package.B to 4.0.0 in b2.txt
139
+ """
121
140
  ];
122
141
  }
123
142
 
@@ -86,7 +86,7 @@ public class RunWorkerTests
86
86
  CanUpdate = true,
87
87
  UpdatedDependencies =
88
88
  [
89
- new("Some.Package", "1.0.2", DependencyType.Unknown, TargetFrameworks: ["net8.0"], InfoUrl: "https://nuget.example.com/some-package"),
89
+ new("Some.Package", "1.0.1", DependencyType.Unknown, TargetFrameworks: ["net8.0"], InfoUrl: "https://nuget.example.com/some-package"),
90
90
  ]
91
91
  });
92
92
  }),
@@ -108,7 +108,14 @@ public class RunWorkerTests
108
108
  """.SetEOL(EOL));
109
109
  return new UpdateOperationResult()
110
110
  {
111
- UpdateOperations = [],
111
+ UpdateOperations = [
112
+ new DirectUpdate()
113
+ {
114
+ DependencyName = "Some.Package",
115
+ NewVersion = NuGetVersion.Parse("1.0.1"),
116
+ UpdatedFiles = ["/some-dir/project.csproj"]
117
+ }
118
+ ],
112
119
  };
113
120
  }),
114
121
  expectedResult: new RunResult()
@@ -319,7 +326,20 @@ public class RunWorkerTests
319
326
  """.SetEOL(EOL));
320
327
  return new UpdateOperationResult()
321
328
  {
322
- UpdateOperations = [],
329
+ UpdateOperations = [
330
+ new DirectUpdate()
331
+ {
332
+ DependencyName = "Some.Package",
333
+ NewVersion = NuGetVersion.Parse("1.0.1"),
334
+ UpdatedFiles = ["/some-dir/project.csproj"]
335
+ },
336
+ new DirectUpdate()
337
+ {
338
+ DependencyName = "Some.Package2",
339
+ NewVersion = NuGetVersion.Parse("1.0.1"),
340
+ UpdatedFiles = ["/some-dir/project.csproj"]
341
+ }
342
+ ],
323
343
  };
324
344
  }),
325
345
  expectedResult: new RunResult()
@@ -689,7 +709,14 @@ public class RunWorkerTests
689
709
 
690
710
  return new UpdateOperationResult()
691
711
  {
692
- UpdateOperations = [],
712
+ UpdateOperations = [
713
+ new DirectUpdate()
714
+ {
715
+ DependencyName = packageName,
716
+ NewVersion = NuGetVersion.Parse(newVersion),
717
+ UpdatedFiles = [filePath]
718
+ }
719
+ ],
693
720
  };
694
721
  }),
695
722
  expectedResult: new RunResult()
@@ -1102,7 +1129,14 @@ public class RunWorkerTests
1102
1129
 
1103
1130
  return new UpdateOperationResult()
1104
1131
  {
1105
- UpdateOperations = [],
1132
+ UpdateOperations = [
1133
+ new DirectUpdate()
1134
+ {
1135
+ DependencyName = packageName,
1136
+ NewVersion = NuGetVersion.Parse(newVersion),
1137
+ UpdatedFiles = [filePath]
1138
+ }
1139
+ ],
1106
1140
  };
1107
1141
  }),
1108
1142
  expectedResult: new RunResult()
@@ -1567,7 +1601,14 @@ public class RunWorkerTests
1567
1601
  """.SetEOL(EOL));
1568
1602
  return new UpdateOperationResult()
1569
1603
  {
1570
- UpdateOperations = [],
1604
+ UpdateOperations = [
1605
+ new DirectUpdate()
1606
+ {
1607
+ DependencyName = packageName,
1608
+ NewVersion = NuGetVersion.Parse(newVersion),
1609
+ UpdatedFiles = [filePath]
1610
+ }
1611
+ ],
1571
1612
  };
1572
1613
  }),
1573
1614
  expectedResult: new RunResult()
@@ -2322,7 +2363,7 @@ public class RunWorkerTests
2322
2363
  }),
2323
2364
  updaterWorker: new TestUpdaterWorker(async input =>
2324
2365
  {
2325
- var (repoRoot, filePath, dependencyName, _previousVersion, _newVersion, _isTransitive) = input;
2366
+ var (repoRoot, filePath, dependencyName, _previousVersion, newVersion, _isTransitive) = input;
2326
2367
  var dependencyFilePath = Path.Join(repoRoot, filePath);
2327
2368
  var updatedContent = dependencyName switch
2328
2369
  {
@@ -2333,7 +2374,14 @@ public class RunWorkerTests
2333
2374
  await File.WriteAllTextAsync(dependencyFilePath, updatedContent);
2334
2375
  return new UpdateOperationResult()
2335
2376
  {
2336
- UpdateOperations = [],
2377
+ UpdateOperations = [
2378
+ new DirectUpdate()
2379
+ {
2380
+ DependencyName = dependencyName,
2381
+ NewVersion = NuGetVersion.Parse(newVersion),
2382
+ UpdatedFiles = [filePath]
2383
+ }
2384
+ ],
2337
2385
  };
2338
2386
  }),
2339
2387
  expectedResult: new()