dependabot-nuget 0.316.0 → 0.317.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.
- checksums.yaml +4 -4
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Job.cs +1 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestTextGenerator.cs +6 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/GroupUpdateAllVersionsHandler.cs +7 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshGroupUpdatePullRequestHandler.cs +3 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandler.cs +28 -12
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandler.cs +24 -6
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/SpecialImportsConditionPatcher.cs +15 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestTextTests.cs +39 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/GroupUpdateAllVersionsHandlerTests.cs +162 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshGroupUpdatePullRequestHandlerTests.cs +311 -6
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandlerTests.cs +273 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandlerTests.cs +307 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/SpecialFilePatcherTests.cs +25 -0
- metadata +4 -4
@@ -1,3 +1,5 @@
|
|
1
|
+
using System.Collections.Immutable;
|
2
|
+
|
1
3
|
using NuGet.Versioning;
|
2
4
|
|
3
5
|
using NuGetUpdater.Core.Analyze;
|
@@ -12,12 +14,6 @@ namespace NuGetUpdater.Core.Test.Run.UpdateHandlers;
|
|
12
14
|
|
13
15
|
public class RefreshGroupUpdatePullRequestHandlerTests : UpdateHandlersTestsBase
|
14
16
|
{
|
15
|
-
// group name must match, existing pr must be found
|
16
|
-
// if updated_deps is empty, close(update_no_longer_possible)
|
17
|
-
// if updated_deps is different, close(dependencies_changed), create()
|
18
|
-
// else if perfect match, update()
|
19
|
-
// else create()
|
20
|
-
|
21
17
|
[Fact]
|
22
18
|
public async Task GeneratesUpdatePullRequest()
|
23
19
|
{
|
@@ -139,6 +135,315 @@ public class RefreshGroupUpdatePullRequestHandlerTests : UpdateHandlersTestsBase
|
|
139
135
|
);
|
140
136
|
}
|
141
137
|
|
138
|
+
[Fact]
|
139
|
+
public async Task GeneratesUpdatePullRequest_FirstUpdateDidNothingSecondUpdateSucceeded()
|
140
|
+
{
|
141
|
+
await TestAsync(
|
142
|
+
job: new Job()
|
143
|
+
{
|
144
|
+
Dependencies = ["Some.Dependency"],
|
145
|
+
DependencyGroups = [new() { Name = "test_group" }],
|
146
|
+
DependencyGroupToRefresh = "test_group",
|
147
|
+
ExistingPullRequests = [new() { Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("2.0.0") }] }],
|
148
|
+
Source = CreateJobSource("/src"),
|
149
|
+
UpdatingAPullRequest = true,
|
150
|
+
},
|
151
|
+
files: [
|
152
|
+
("src/project1.csproj", "initial contents"),
|
153
|
+
("src/project2.csproj", "initial contents"),
|
154
|
+
],
|
155
|
+
discoveryWorker: TestDiscoveryWorker.FromResults(
|
156
|
+
("/src", new WorkspaceDiscoveryResult()
|
157
|
+
{
|
158
|
+
Path = "/src",
|
159
|
+
Projects = [
|
160
|
+
new()
|
161
|
+
{
|
162
|
+
FilePath = "project1.csproj",
|
163
|
+
Dependencies = [
|
164
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
165
|
+
new("Unrelated.Dependency", "3.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
166
|
+
],
|
167
|
+
ImportedFiles = [],
|
168
|
+
AdditionalFiles = [],
|
169
|
+
},
|
170
|
+
new()
|
171
|
+
{
|
172
|
+
FilePath = "project2.csproj",
|
173
|
+
Dependencies = [
|
174
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
175
|
+
new("Unrelated.Dependency", "3.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
176
|
+
],
|
177
|
+
ImportedFiles = [],
|
178
|
+
AdditionalFiles = [],
|
179
|
+
},
|
180
|
+
],
|
181
|
+
})
|
182
|
+
),
|
183
|
+
analyzeWorker: new TestAnalyzeWorker(input =>
|
184
|
+
{
|
185
|
+
var repoRoot = input.Item1;
|
186
|
+
var discovery = input.Item2;
|
187
|
+
var dependencyInfo = input.Item3;
|
188
|
+
if (dependencyInfo.Name != "Some.Dependency")
|
189
|
+
{
|
190
|
+
throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}");
|
191
|
+
}
|
192
|
+
|
193
|
+
return Task.FromResult(new AnalysisResult()
|
194
|
+
{
|
195
|
+
CanUpdate = true,
|
196
|
+
UpdatedVersion = "2.0.0",
|
197
|
+
UpdatedDependencies = [],
|
198
|
+
});
|
199
|
+
}),
|
200
|
+
updaterWorker: new TestUpdaterWorker(async input =>
|
201
|
+
{
|
202
|
+
var repoRoot = input.Item1;
|
203
|
+
var workspacePath = input.Item2;
|
204
|
+
var dependencyName = input.Item3;
|
205
|
+
var previousVersion = input.Item4;
|
206
|
+
var newVersion = input.Item5;
|
207
|
+
var isTransitive = input.Item6;
|
208
|
+
|
209
|
+
ImmutableArray<UpdateOperationBase> updateOperations = [];
|
210
|
+
if (workspacePath.EndsWith("project2.csproj"))
|
211
|
+
{
|
212
|
+
// only report an update performed on the second project
|
213
|
+
updateOperations = [new DirectUpdate() { DependencyName = "Some.Dependency", NewVersion = NuGetVersion.Parse("2.0.0"), UpdatedFiles = ["/src/project2.csproj"] }];
|
214
|
+
await File.WriteAllTextAsync(Path.Join(repoRoot, workspacePath), "updated contents");
|
215
|
+
}
|
216
|
+
|
217
|
+
return new UpdateOperationResult()
|
218
|
+
{
|
219
|
+
UpdateOperations = updateOperations,
|
220
|
+
};
|
221
|
+
}),
|
222
|
+
expectedUpdateHandler: RefreshGroupUpdatePullRequestHandler.Instance,
|
223
|
+
expectedApiMessages: [
|
224
|
+
new UpdatedDependencyList()
|
225
|
+
{
|
226
|
+
Dependencies = [
|
227
|
+
new()
|
228
|
+
{
|
229
|
+
Name = "Some.Dependency",
|
230
|
+
Version = "1.0.0",
|
231
|
+
Requirements = [
|
232
|
+
new() { Requirement = "1.0.0", File = "/src/project1.csproj", Groups = ["dependencies"] },
|
233
|
+
],
|
234
|
+
},
|
235
|
+
new()
|
236
|
+
{
|
237
|
+
Name = "Unrelated.Dependency",
|
238
|
+
Version = "3.0.0",
|
239
|
+
Requirements = [
|
240
|
+
new() { Requirement = "3.0.0", File = "/src/project1.csproj", Groups = ["dependencies"] },
|
241
|
+
],
|
242
|
+
},
|
243
|
+
new()
|
244
|
+
{
|
245
|
+
Name = "Some.Dependency",
|
246
|
+
Version = "1.0.0",
|
247
|
+
Requirements = [
|
248
|
+
new() { Requirement = "1.0.0", File = "/src/project2.csproj", Groups = ["dependencies"] },
|
249
|
+
],
|
250
|
+
},
|
251
|
+
new()
|
252
|
+
{
|
253
|
+
Name = "Unrelated.Dependency",
|
254
|
+
Version = "3.0.0",
|
255
|
+
Requirements = [
|
256
|
+
new() { Requirement = "3.0.0", File = "/src/project2.csproj", Groups = ["dependencies"] },
|
257
|
+
],
|
258
|
+
},
|
259
|
+
],
|
260
|
+
DependencyFiles = ["/src/project1.csproj", "/src/project2.csproj"],
|
261
|
+
},
|
262
|
+
new IncrementMetric()
|
263
|
+
{
|
264
|
+
Metric = "updater.started",
|
265
|
+
Tags = new()
|
266
|
+
{
|
267
|
+
["operation"] = "update_version_group_pr",
|
268
|
+
}
|
269
|
+
},
|
270
|
+
new UpdatePullRequest()
|
271
|
+
{
|
272
|
+
DependencyNames = ["Some.Dependency"],
|
273
|
+
DependencyGroup = "test_group",
|
274
|
+
UpdatedDependencyFiles = [
|
275
|
+
new()
|
276
|
+
{
|
277
|
+
Directory = "/src",
|
278
|
+
Name = "project2.csproj",
|
279
|
+
Content = "updated contents",
|
280
|
+
}
|
281
|
+
],
|
282
|
+
BaseCommitSha = "TEST-COMMIT-SHA",
|
283
|
+
CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
|
284
|
+
PrTitle = RunWorkerTests.TestPullRequestTitle,
|
285
|
+
PrBody = RunWorkerTests.TestPullRequestBody,
|
286
|
+
},
|
287
|
+
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
288
|
+
]
|
289
|
+
);
|
290
|
+
}
|
291
|
+
|
292
|
+
[Fact]
|
293
|
+
public async Task GeneratesUpdatePullRequest_FirstDependencyNotAbleToUpdate()
|
294
|
+
{
|
295
|
+
var responseNumber = 0; // used to track which request was sent
|
296
|
+
await TestAsync(
|
297
|
+
job: new Job()
|
298
|
+
{
|
299
|
+
Dependencies = ["Some.Dependency"],
|
300
|
+
DependencyGroups = [new() { Name = "test_group" }],
|
301
|
+
DependencyGroupToRefresh = "test_group",
|
302
|
+
ExistingPullRequests = [new() { Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("2.0.0") }] }],
|
303
|
+
Source = CreateJobSource("/src"),
|
304
|
+
UpdatingAPullRequest = true,
|
305
|
+
},
|
306
|
+
files: [
|
307
|
+
("src/project1.csproj", "initial contents"),
|
308
|
+
("src/project2.csproj", "initial contents"),
|
309
|
+
],
|
310
|
+
discoveryWorker: TestDiscoveryWorker.FromResults(
|
311
|
+
("/src", new WorkspaceDiscoveryResult()
|
312
|
+
{
|
313
|
+
Path = "/src",
|
314
|
+
Projects = [
|
315
|
+
new()
|
316
|
+
{
|
317
|
+
FilePath = "project1.csproj",
|
318
|
+
Dependencies = [
|
319
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
320
|
+
new("Unrelated.Dependency", "3.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
321
|
+
],
|
322
|
+
ImportedFiles = [],
|
323
|
+
AdditionalFiles = [],
|
324
|
+
},
|
325
|
+
new()
|
326
|
+
{
|
327
|
+
FilePath = "project2.csproj",
|
328
|
+
Dependencies = [
|
329
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
330
|
+
new("Unrelated.Dependency", "3.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
331
|
+
],
|
332
|
+
ImportedFiles = [],
|
333
|
+
AdditionalFiles = [],
|
334
|
+
},
|
335
|
+
],
|
336
|
+
})
|
337
|
+
),
|
338
|
+
analyzeWorker: new TestAnalyzeWorker(input =>
|
339
|
+
{
|
340
|
+
var repoRoot = input.Item1;
|
341
|
+
var discovery = input.Item2;
|
342
|
+
var dependencyInfo = input.Item3;
|
343
|
+
if (dependencyInfo.Name != "Some.Dependency")
|
344
|
+
{
|
345
|
+
throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}");
|
346
|
+
}
|
347
|
+
|
348
|
+
AnalysisResult result = responseNumber == 0
|
349
|
+
? new() { CanUpdate = false, UpdatedVersion = "1.0.0", UpdatedDependencies = [] }
|
350
|
+
: new() { CanUpdate = true, UpdatedVersion = "2.0.0", UpdatedDependencies = [] };
|
351
|
+
responseNumber++;
|
352
|
+
|
353
|
+
return Task.FromResult(result);
|
354
|
+
}),
|
355
|
+
updaterWorker: new TestUpdaterWorker(async input =>
|
356
|
+
{
|
357
|
+
var repoRoot = input.Item1;
|
358
|
+
var workspacePath = input.Item2;
|
359
|
+
var dependencyName = input.Item3;
|
360
|
+
var previousVersion = input.Item4;
|
361
|
+
var newVersion = input.Item5;
|
362
|
+
var isTransitive = input.Item6;
|
363
|
+
|
364
|
+
ImmutableArray<UpdateOperationBase> updateOperations = [];
|
365
|
+
if (workspacePath.EndsWith("project2.csproj"))
|
366
|
+
{
|
367
|
+
// only report an update performed on the second project
|
368
|
+
updateOperations = [new DirectUpdate() { DependencyName = "Some.Dependency", NewVersion = NuGetVersion.Parse("2.0.0"), UpdatedFiles = ["/src/project2.csproj"] }];
|
369
|
+
await File.WriteAllTextAsync(Path.Join(repoRoot, workspacePath), "updated contents");
|
370
|
+
}
|
371
|
+
|
372
|
+
return new UpdateOperationResult()
|
373
|
+
{
|
374
|
+
UpdateOperations = updateOperations,
|
375
|
+
};
|
376
|
+
}),
|
377
|
+
expectedUpdateHandler: RefreshGroupUpdatePullRequestHandler.Instance,
|
378
|
+
expectedApiMessages: [
|
379
|
+
new UpdatedDependencyList()
|
380
|
+
{
|
381
|
+
Dependencies = [
|
382
|
+
new()
|
383
|
+
{
|
384
|
+
Name = "Some.Dependency",
|
385
|
+
Version = "1.0.0",
|
386
|
+
Requirements = [
|
387
|
+
new() { Requirement = "1.0.0", File = "/src/project1.csproj", Groups = ["dependencies"] },
|
388
|
+
],
|
389
|
+
},
|
390
|
+
new()
|
391
|
+
{
|
392
|
+
Name = "Unrelated.Dependency",
|
393
|
+
Version = "3.0.0",
|
394
|
+
Requirements = [
|
395
|
+
new() { Requirement = "3.0.0", File = "/src/project1.csproj", Groups = ["dependencies"] },
|
396
|
+
],
|
397
|
+
},
|
398
|
+
new()
|
399
|
+
{
|
400
|
+
Name = "Some.Dependency",
|
401
|
+
Version = "1.0.0",
|
402
|
+
Requirements = [
|
403
|
+
new() { Requirement = "1.0.0", File = "/src/project2.csproj", Groups = ["dependencies"] },
|
404
|
+
],
|
405
|
+
},
|
406
|
+
new()
|
407
|
+
{
|
408
|
+
Name = "Unrelated.Dependency",
|
409
|
+
Version = "3.0.0",
|
410
|
+
Requirements = [
|
411
|
+
new() { Requirement = "3.0.0", File = "/src/project2.csproj", Groups = ["dependencies"] },
|
412
|
+
],
|
413
|
+
},
|
414
|
+
],
|
415
|
+
DependencyFiles = ["/src/project1.csproj", "/src/project2.csproj"],
|
416
|
+
},
|
417
|
+
new IncrementMetric()
|
418
|
+
{
|
419
|
+
Metric = "updater.started",
|
420
|
+
Tags = new()
|
421
|
+
{
|
422
|
+
["operation"] = "update_version_group_pr",
|
423
|
+
}
|
424
|
+
},
|
425
|
+
new UpdatePullRequest()
|
426
|
+
{
|
427
|
+
DependencyNames = ["Some.Dependency"],
|
428
|
+
DependencyGroup = "test_group",
|
429
|
+
UpdatedDependencyFiles = [
|
430
|
+
new()
|
431
|
+
{
|
432
|
+
Directory = "/src",
|
433
|
+
Name = "project2.csproj",
|
434
|
+
Content = "updated contents",
|
435
|
+
}
|
436
|
+
],
|
437
|
+
BaseCommitSha = "TEST-COMMIT-SHA",
|
438
|
+
CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
|
439
|
+
PrTitle = RunWorkerTests.TestPullRequestTitle,
|
440
|
+
PrBody = RunWorkerTests.TestPullRequestBody,
|
441
|
+
},
|
442
|
+
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
443
|
+
]
|
444
|
+
);
|
445
|
+
}
|
446
|
+
|
142
447
|
[Fact]
|
143
448
|
public async Task GeneratesClosePullRequest_UpdateNoLongerPossible()
|
144
449
|
{
|
@@ -271,6 +271,279 @@ public class RefreshSecurityUpdatePullRequestHandlerTests : UpdateHandlersTestsB
|
|
271
271
|
);
|
272
272
|
}
|
273
273
|
|
274
|
+
[Fact]
|
275
|
+
public async Task GeneratesUpdatePullRequest_FirstUpdateDidNothingSecondUpdateSucceeded()
|
276
|
+
{
|
277
|
+
await TestAsync(
|
278
|
+
job: new Job()
|
279
|
+
{
|
280
|
+
Dependencies = ["Some.Dependency"],
|
281
|
+
ExistingPullRequests = [new() { Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("2.0.0") }] }],
|
282
|
+
SecurityAdvisories = [new() { DependencyName = "Some.Dependency", AffectedVersions = [Requirement.Parse("= 1.0.0")] }],
|
283
|
+
SecurityUpdatesOnly = true,
|
284
|
+
Source = CreateJobSource("/src"),
|
285
|
+
UpdatingAPullRequest = true,
|
286
|
+
},
|
287
|
+
files: [
|
288
|
+
("src/Directory.Packages.props", "initial contents"),
|
289
|
+
("src/project1.csproj", "initial contents"),
|
290
|
+
("src/project2.csproj", "initial contents"),
|
291
|
+
],
|
292
|
+
discoveryWorker: TestDiscoveryWorker.FromResults(
|
293
|
+
("/src", new WorkspaceDiscoveryResult()
|
294
|
+
{
|
295
|
+
Path = "/src",
|
296
|
+
Projects = [
|
297
|
+
new()
|
298
|
+
{
|
299
|
+
FilePath = "project1.csproj",
|
300
|
+
Dependencies = [
|
301
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
302
|
+
],
|
303
|
+
ImportedFiles = ["Directory.Packages.props"],
|
304
|
+
AdditionalFiles = [],
|
305
|
+
},
|
306
|
+
new()
|
307
|
+
{
|
308
|
+
FilePath = "project2.csproj",
|
309
|
+
Dependencies = [
|
310
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
311
|
+
],
|
312
|
+
ImportedFiles = ["Directory.Packages.props"],
|
313
|
+
AdditionalFiles = [],
|
314
|
+
},
|
315
|
+
],
|
316
|
+
})
|
317
|
+
),
|
318
|
+
analyzeWorker: new TestAnalyzeWorker(input =>
|
319
|
+
{
|
320
|
+
var repoRoot = input.Item1;
|
321
|
+
var discovery = input.Item2;
|
322
|
+
var dependencyInfo = input.Item3;
|
323
|
+
if (dependencyInfo.Name != "Some.Dependency")
|
324
|
+
{
|
325
|
+
throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}");
|
326
|
+
}
|
327
|
+
|
328
|
+
return Task.FromResult(new AnalysisResult()
|
329
|
+
{
|
330
|
+
CanUpdate = true,
|
331
|
+
UpdatedVersion = "2.0.0",
|
332
|
+
UpdatedDependencies = [],
|
333
|
+
});
|
334
|
+
}),
|
335
|
+
updaterWorker: new TestUpdaterWorker(async input =>
|
336
|
+
{
|
337
|
+
var repoRoot = input.Item1;
|
338
|
+
var workspacePath = input.Item2;
|
339
|
+
var dependencyName = input.Item3;
|
340
|
+
var previousVersion = input.Item4;
|
341
|
+
var newVersion = input.Item5;
|
342
|
+
var isTransitive = input.Item6;
|
343
|
+
|
344
|
+
await File.WriteAllTextAsync(Path.Join(repoRoot, "src/Directory.Packages.props"), "updated contents");
|
345
|
+
|
346
|
+
// only report an update performed on the second project
|
347
|
+
ImmutableArray<UpdateOperationBase> updateOperations = workspacePath.EndsWith("project2.csproj")
|
348
|
+
? [new DirectUpdate() { DependencyName = "Some.Dependency", NewVersion = NuGetVersion.Parse("2.0.0"), UpdatedFiles = ["/src/Directory.Packages.csproj"] }]
|
349
|
+
: [];
|
350
|
+
|
351
|
+
return new UpdateOperationResult()
|
352
|
+
{
|
353
|
+
UpdateOperations = updateOperations,
|
354
|
+
};
|
355
|
+
}),
|
356
|
+
expectedUpdateHandler: RefreshSecurityUpdatePullRequestHandler.Instance,
|
357
|
+
expectedApiMessages: [
|
358
|
+
new UpdatedDependencyList()
|
359
|
+
{
|
360
|
+
Dependencies = [
|
361
|
+
new()
|
362
|
+
{
|
363
|
+
Name = "Some.Dependency",
|
364
|
+
Version = "1.0.0",
|
365
|
+
Requirements = [
|
366
|
+
new() { Requirement = "1.0.0", File = "/src/project1.csproj", Groups = ["dependencies"] },
|
367
|
+
],
|
368
|
+
},
|
369
|
+
new()
|
370
|
+
{
|
371
|
+
Name = "Some.Dependency",
|
372
|
+
Version = "1.0.0",
|
373
|
+
Requirements = [
|
374
|
+
new() { Requirement = "1.0.0", File = "/src/project2.csproj", Groups = ["dependencies"] },
|
375
|
+
],
|
376
|
+
},
|
377
|
+
],
|
378
|
+
DependencyFiles = ["/src/Directory.Packages.props", "/src/project1.csproj", "/src/project2.csproj"],
|
379
|
+
},
|
380
|
+
new IncrementMetric()
|
381
|
+
{
|
382
|
+
Metric = "updater.started",
|
383
|
+
Tags = new()
|
384
|
+
{
|
385
|
+
["operation"] = "update_security_pr",
|
386
|
+
}
|
387
|
+
},
|
388
|
+
new UpdatePullRequest()
|
389
|
+
{
|
390
|
+
DependencyNames = ["Some.Dependency"],
|
391
|
+
DependencyGroup = null,
|
392
|
+
UpdatedDependencyFiles = [
|
393
|
+
new()
|
394
|
+
{
|
395
|
+
Directory = "/src",
|
396
|
+
Name = "Directory.Packages.props",
|
397
|
+
Content = "updated contents",
|
398
|
+
}
|
399
|
+
],
|
400
|
+
BaseCommitSha = "TEST-COMMIT-SHA",
|
401
|
+
CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
|
402
|
+
PrTitle = RunWorkerTests.TestPullRequestTitle,
|
403
|
+
PrBody = RunWorkerTests.TestPullRequestBody,
|
404
|
+
},
|
405
|
+
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
406
|
+
]
|
407
|
+
);
|
408
|
+
}
|
409
|
+
|
410
|
+
[Fact]
|
411
|
+
public async Task GeneratesUpdatePullRequest_FirstDependencyNotAbleToUpdate()
|
412
|
+
{
|
413
|
+
var responseNumber = 0; // used to track which request was sent
|
414
|
+
await TestAsync(
|
415
|
+
job: new Job()
|
416
|
+
{
|
417
|
+
Dependencies = ["Some.Dependency"],
|
418
|
+
ExistingPullRequests = [new() { Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("2.0.0") }] }],
|
419
|
+
SecurityAdvisories = [new() { DependencyName = "Some.Dependency", AffectedVersions = [Requirement.Parse("= 1.0.0")] }],
|
420
|
+
SecurityUpdatesOnly = true,
|
421
|
+
Source = CreateJobSource("/src"),
|
422
|
+
UpdatingAPullRequest = true,
|
423
|
+
},
|
424
|
+
files: [
|
425
|
+
("src/Directory.Packages.props", "initial contents"),
|
426
|
+
("src/project1.csproj", "initial contents"),
|
427
|
+
("src/project2.csproj", "initial contents"),
|
428
|
+
],
|
429
|
+
discoveryWorker: TestDiscoveryWorker.FromResults(
|
430
|
+
("/src", new WorkspaceDiscoveryResult()
|
431
|
+
{
|
432
|
+
Path = "/src",
|
433
|
+
Projects = [
|
434
|
+
new()
|
435
|
+
{
|
436
|
+
FilePath = "project1.csproj",
|
437
|
+
Dependencies = [
|
438
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
439
|
+
],
|
440
|
+
ImportedFiles = ["Directory.Packages.props"],
|
441
|
+
AdditionalFiles = [],
|
442
|
+
},
|
443
|
+
new()
|
444
|
+
{
|
445
|
+
FilePath = "project2.csproj",
|
446
|
+
Dependencies = [
|
447
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
448
|
+
],
|
449
|
+
ImportedFiles = ["Directory.Packages.props"],
|
450
|
+
AdditionalFiles = [],
|
451
|
+
},
|
452
|
+
],
|
453
|
+
})
|
454
|
+
),
|
455
|
+
analyzeWorker: new TestAnalyzeWorker(input =>
|
456
|
+
{
|
457
|
+
var repoRoot = input.Item1;
|
458
|
+
var discovery = input.Item2;
|
459
|
+
var dependencyInfo = input.Item3;
|
460
|
+
if (dependencyInfo.Name != "Some.Dependency")
|
461
|
+
{
|
462
|
+
throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}");
|
463
|
+
}
|
464
|
+
|
465
|
+
AnalysisResult result = responseNumber == 0
|
466
|
+
? new() { CanUpdate = false, UpdatedVersion = "1.0.0", UpdatedDependencies = [] }
|
467
|
+
: new() { CanUpdate = true, UpdatedVersion = "2.0.0", UpdatedDependencies = [] };
|
468
|
+
responseNumber++;
|
469
|
+
|
470
|
+
return Task.FromResult(result);
|
471
|
+
}),
|
472
|
+
updaterWorker: new TestUpdaterWorker(async input =>
|
473
|
+
{
|
474
|
+
var repoRoot = input.Item1;
|
475
|
+
var workspacePath = input.Item2;
|
476
|
+
var dependencyName = input.Item3;
|
477
|
+
var previousVersion = input.Item4;
|
478
|
+
var newVersion = input.Item5;
|
479
|
+
var isTransitive = input.Item6;
|
480
|
+
|
481
|
+
await File.WriteAllTextAsync(Path.Join(repoRoot, "src/Directory.Packages.props"), "updated contents");
|
482
|
+
|
483
|
+
// only report an update performed on the second project
|
484
|
+
ImmutableArray<UpdateOperationBase> updateOperations = workspacePath.EndsWith("project2.csproj")
|
485
|
+
? [new DirectUpdate() { DependencyName = "Some.Dependency", NewVersion = NuGetVersion.Parse("2.0.0"), UpdatedFiles = ["/src/Directory.Packages.csproj"] }]
|
486
|
+
: [];
|
487
|
+
|
488
|
+
return new UpdateOperationResult()
|
489
|
+
{
|
490
|
+
UpdateOperations = updateOperations,
|
491
|
+
};
|
492
|
+
}),
|
493
|
+
expectedUpdateHandler: RefreshSecurityUpdatePullRequestHandler.Instance,
|
494
|
+
expectedApiMessages: [
|
495
|
+
new UpdatedDependencyList()
|
496
|
+
{
|
497
|
+
Dependencies = [
|
498
|
+
new()
|
499
|
+
{
|
500
|
+
Name = "Some.Dependency",
|
501
|
+
Version = "1.0.0",
|
502
|
+
Requirements = [
|
503
|
+
new() { Requirement = "1.0.0", File = "/src/project1.csproj", Groups = ["dependencies"] },
|
504
|
+
],
|
505
|
+
},
|
506
|
+
new()
|
507
|
+
{
|
508
|
+
Name = "Some.Dependency",
|
509
|
+
Version = "1.0.0",
|
510
|
+
Requirements = [
|
511
|
+
new() { Requirement = "1.0.0", File = "/src/project2.csproj", Groups = ["dependencies"] },
|
512
|
+
],
|
513
|
+
},
|
514
|
+
],
|
515
|
+
DependencyFiles = ["/src/Directory.Packages.props", "/src/project1.csproj", "/src/project2.csproj"],
|
516
|
+
},
|
517
|
+
new IncrementMetric()
|
518
|
+
{
|
519
|
+
Metric = "updater.started",
|
520
|
+
Tags = new()
|
521
|
+
{
|
522
|
+
["operation"] = "update_security_pr",
|
523
|
+
}
|
524
|
+
},
|
525
|
+
new UpdatePullRequest()
|
526
|
+
{
|
527
|
+
DependencyNames = ["Some.Dependency"],
|
528
|
+
DependencyGroup = null,
|
529
|
+
UpdatedDependencyFiles = [
|
530
|
+
new()
|
531
|
+
{
|
532
|
+
Directory = "/src",
|
533
|
+
Name = "Directory.Packages.props",
|
534
|
+
Content = "updated contents",
|
535
|
+
}
|
536
|
+
],
|
537
|
+
BaseCommitSha = "TEST-COMMIT-SHA",
|
538
|
+
CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
|
539
|
+
PrTitle = RunWorkerTests.TestPullRequestTitle,
|
540
|
+
PrBody = RunWorkerTests.TestPullRequestBody,
|
541
|
+
},
|
542
|
+
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
543
|
+
]
|
544
|
+
);
|
545
|
+
}
|
546
|
+
|
274
547
|
[Fact]
|
275
548
|
public async Task GeneratesClosePullRequest_DependenciesRemoved()
|
276
549
|
{
|