dependabot-nuget 0.315.0 → 0.316.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.Cli.Test/EntryPointTests.Run.cs +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/WorkspaceDiscoveryResult.cs +6 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/ExperimentsManager.cs +3 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/ClosePullRequest.cs +15 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/CreatePullRequest.cs +47 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/DependencyGroup.cs +60 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Job.cs +151 -23
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/JobErrorBase.cs +4 -18
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/PullRequestExistsForSecurityUpdate.cs +15 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/SecurityUpdateDependencyNotFound.cs +9 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/SecurityUpdateIgnored.cs +10 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/SecurityUpdateNotFound.cs +11 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/SecurityUpdateNotPossible.cs +13 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/UpdatePullRequest.cs +6 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ModifiedFilesTracker.cs +151 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestTextGenerator.cs +78 -32
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +99 -111
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/CreateSecurityUpdatePullRequestHandler.cs +169 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/GroupUpdateAllVersionsHandler.cs +271 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/IUpdateHandler.cs +22 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshGroupUpdatePullRequestHandler.cs +192 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandler.cs +187 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandler.cs +175 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdateOperationBase.cs +43 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ILogger.cs +17 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +15 -9
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MarkdownListBuilder.cs +65 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/ApiModel/JobTests.cs +405 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/EndToEndTests.cs +92 -82
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/HttpApiHandlerTests.cs +5 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/MessageReportTests.cs +67 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/MiscellaneousTests.cs +445 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestMessageTests.cs +1 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestTextTests.cs +260 -20
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs +30 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/SerializationTests.cs +69 -10
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/CreateSecurityUpdatePullRequestHandlerTests.cs +766 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/GroupUpdateAllVersionsHandlerTests.cs +636 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshGroupUpdatePullRequestHandlerTests.cs +513 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandlerTests.cs +806 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandlerTests.cs +589 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/UpdateHandlerSelectionTests.cs +183 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/UpdateHandlersTestsBase.cs +43 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdatedDependencyListTests.cs +2 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateOperationBaseTests.cs +121 -7
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Mixed.cs +6 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +2 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +51 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MarkdownListBuilderTests.cs +42 -0
- metadata +26 -4
@@ -0,0 +1,636 @@
|
|
1
|
+
using NuGet.Versioning;
|
2
|
+
|
3
|
+
using NuGetUpdater.Core.Analyze;
|
4
|
+
using NuGetUpdater.Core.Discover;
|
5
|
+
using NuGetUpdater.Core.Run.ApiModel;
|
6
|
+
using NuGetUpdater.Core.Run.UpdateHandlers;
|
7
|
+
using NuGetUpdater.Core.Updater;
|
8
|
+
|
9
|
+
using Xunit;
|
10
|
+
|
11
|
+
namespace NuGetUpdater.Core.Test.Run.UpdateHandlers;
|
12
|
+
|
13
|
+
public class GroupUpdateAllVersionsHandlerTests : UpdateHandlersTestsBase
|
14
|
+
{
|
15
|
+
[Fact]
|
16
|
+
public async Task GeneratesCreatePullRequest_NoGroups()
|
17
|
+
{
|
18
|
+
// no groups specified; create 1 PR for each directory
|
19
|
+
await TestAsync(
|
20
|
+
job: new Job()
|
21
|
+
{
|
22
|
+
Source = CreateJobSource("/src", "/test"),
|
23
|
+
},
|
24
|
+
files: [
|
25
|
+
("src/project.csproj", "initial contents"),
|
26
|
+
("test/project.csproj", "initial contents"),
|
27
|
+
],
|
28
|
+
discoveryWorker: TestDiscoveryWorker.FromResults(
|
29
|
+
("/src", new WorkspaceDiscoveryResult()
|
30
|
+
{
|
31
|
+
Path = "/src",
|
32
|
+
Projects = [
|
33
|
+
new()
|
34
|
+
{
|
35
|
+
FilePath = "project.csproj",
|
36
|
+
Dependencies = [
|
37
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
38
|
+
new("Some.Other.Dependency", "3.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
39
|
+
],
|
40
|
+
ImportedFiles = [],
|
41
|
+
AdditionalFiles = [],
|
42
|
+
}
|
43
|
+
],
|
44
|
+
}),
|
45
|
+
("/test", new WorkspaceDiscoveryResult()
|
46
|
+
{
|
47
|
+
Path = "/test",
|
48
|
+
Projects = [
|
49
|
+
new()
|
50
|
+
{
|
51
|
+
FilePath = "project.csproj",
|
52
|
+
Dependencies = [
|
53
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
54
|
+
new("Some.Other.Dependency", "3.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
55
|
+
],
|
56
|
+
ImportedFiles = [],
|
57
|
+
AdditionalFiles = [],
|
58
|
+
}
|
59
|
+
],
|
60
|
+
})
|
61
|
+
),
|
62
|
+
analyzeWorker: new TestAnalyzeWorker(input =>
|
63
|
+
{
|
64
|
+
var repoRoot = input.Item1;
|
65
|
+
var discovery = input.Item2;
|
66
|
+
var dependencyInfo = input.Item3;
|
67
|
+
var newVersion = dependencyInfo.Name switch
|
68
|
+
{
|
69
|
+
"Some.Dependency" => "2.0.0",
|
70
|
+
"Some.Other.Dependency" => "4.0.0",
|
71
|
+
_ => throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}"),
|
72
|
+
};
|
73
|
+
return Task.FromResult(new AnalysisResult()
|
74
|
+
{
|
75
|
+
CanUpdate = true,
|
76
|
+
UpdatedVersion = newVersion,
|
77
|
+
UpdatedDependencies = [],
|
78
|
+
});
|
79
|
+
}),
|
80
|
+
updaterWorker: new TestUpdaterWorker(async input =>
|
81
|
+
{
|
82
|
+
var repoRoot = input.Item1;
|
83
|
+
var workspacePath = input.Item2;
|
84
|
+
var dependencyName = input.Item3;
|
85
|
+
var previousVersion = input.Item4;
|
86
|
+
var newVersion = input.Item5;
|
87
|
+
var isTransitive = input.Item6;
|
88
|
+
|
89
|
+
await File.WriteAllTextAsync(Path.Join(repoRoot, workspacePath), "updated contents");
|
90
|
+
|
91
|
+
return new UpdateOperationResult()
|
92
|
+
{
|
93
|
+
UpdateOperations = [new DirectUpdate() { DependencyName = dependencyName, NewVersion = NuGetVersion.Parse(newVersion), UpdatedFiles = [workspacePath] }],
|
94
|
+
};
|
95
|
+
}),
|
96
|
+
expectedUpdateHandler: GroupUpdateAllVersionsHandler.Instance,
|
97
|
+
expectedApiMessages: [
|
98
|
+
new IncrementMetric()
|
99
|
+
{
|
100
|
+
Metric = "updater.started",
|
101
|
+
Tags = new()
|
102
|
+
{
|
103
|
+
["operation"] = "group_update_all_versions",
|
104
|
+
}
|
105
|
+
},
|
106
|
+
// for "/src"
|
107
|
+
new UpdatedDependencyList()
|
108
|
+
{
|
109
|
+
Dependencies = [
|
110
|
+
new()
|
111
|
+
{
|
112
|
+
Name = "Some.Dependency",
|
113
|
+
Version = "1.0.0",
|
114
|
+
Requirements = [
|
115
|
+
new() { Requirement = "1.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
116
|
+
],
|
117
|
+
},
|
118
|
+
new()
|
119
|
+
{
|
120
|
+
Name = "Some.Other.Dependency",
|
121
|
+
Version = "3.0.0",
|
122
|
+
Requirements = [
|
123
|
+
new() { Requirement = "3.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
124
|
+
],
|
125
|
+
},
|
126
|
+
],
|
127
|
+
DependencyFiles = ["/src/project.csproj"],
|
128
|
+
},
|
129
|
+
new CreatePullRequest()
|
130
|
+
{
|
131
|
+
Dependencies = [
|
132
|
+
new()
|
133
|
+
{
|
134
|
+
Name = "Some.Dependency",
|
135
|
+
Version = "2.0.0",
|
136
|
+
Requirements = [
|
137
|
+
new() { Requirement = "2.0.0", File = "/src/project.csproj", Groups = ["dependencies"], Source = new() { SourceUrl = null } },
|
138
|
+
],
|
139
|
+
PreviousVersion = "1.0.0",
|
140
|
+
PreviousRequirements = [
|
141
|
+
new() { Requirement = "1.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
142
|
+
],
|
143
|
+
},
|
144
|
+
new()
|
145
|
+
{
|
146
|
+
Name = "Some.Other.Dependency",
|
147
|
+
Version = "4.0.0",
|
148
|
+
Requirements = [
|
149
|
+
new() { Requirement = "4.0.0", File = "/src/project.csproj", Groups = ["dependencies"], Source = new() { SourceUrl = null } },
|
150
|
+
],
|
151
|
+
PreviousVersion = "3.0.0",
|
152
|
+
PreviousRequirements = [
|
153
|
+
new() { Requirement = "3.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
154
|
+
],
|
155
|
+
},
|
156
|
+
],
|
157
|
+
UpdatedDependencyFiles = [
|
158
|
+
new()
|
159
|
+
{
|
160
|
+
Directory = "/src",
|
161
|
+
Name = "project.csproj",
|
162
|
+
Content = "updated contents",
|
163
|
+
},
|
164
|
+
],
|
165
|
+
BaseCommitSha = "TEST-COMMIT-SHA",
|
166
|
+
CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
|
167
|
+
PrTitle = RunWorkerTests.TestPullRequestTitle,
|
168
|
+
PrBody = RunWorkerTests.TestPullRequestBody,
|
169
|
+
DependencyGroup = null,
|
170
|
+
},
|
171
|
+
// for "/test"
|
172
|
+
new UpdatedDependencyList()
|
173
|
+
{
|
174
|
+
Dependencies = [
|
175
|
+
new()
|
176
|
+
{
|
177
|
+
Name = "Some.Dependency",
|
178
|
+
Version = "1.0.0",
|
179
|
+
Requirements = [
|
180
|
+
new() { Requirement = "1.0.0", File = "/test/project.csproj", Groups = ["dependencies"] },
|
181
|
+
],
|
182
|
+
},
|
183
|
+
new()
|
184
|
+
{
|
185
|
+
Name = "Some.Other.Dependency",
|
186
|
+
Version = "3.0.0",
|
187
|
+
Requirements = [
|
188
|
+
new() { Requirement = "3.0.0", File = "/test/project.csproj", Groups = ["dependencies"] },
|
189
|
+
],
|
190
|
+
},
|
191
|
+
],
|
192
|
+
DependencyFiles = ["/test/project.csproj"],
|
193
|
+
},
|
194
|
+
new CreatePullRequest()
|
195
|
+
{
|
196
|
+
Dependencies = [
|
197
|
+
new()
|
198
|
+
{
|
199
|
+
Name = "Some.Dependency",
|
200
|
+
Version = "2.0.0",
|
201
|
+
Requirements = [
|
202
|
+
new() { Requirement = "2.0.0", File = "/test/project.csproj", Groups = ["dependencies"], Source = new() { SourceUrl = null } },
|
203
|
+
],
|
204
|
+
PreviousVersion = "1.0.0",
|
205
|
+
PreviousRequirements = [
|
206
|
+
new() { Requirement = "1.0.0", File = "/test/project.csproj", Groups = ["dependencies"] },
|
207
|
+
],
|
208
|
+
},
|
209
|
+
new()
|
210
|
+
{
|
211
|
+
Name = "Some.Other.Dependency",
|
212
|
+
Version = "4.0.0",
|
213
|
+
Requirements = [
|
214
|
+
new() { Requirement = "4.0.0", File = "/test/project.csproj", Groups = ["dependencies"], Source = new() { SourceUrl = null } },
|
215
|
+
],
|
216
|
+
PreviousVersion = "3.0.0",
|
217
|
+
PreviousRequirements = [
|
218
|
+
new() { Requirement = "3.0.0", File = "/test/project.csproj", Groups = ["dependencies"] },
|
219
|
+
],
|
220
|
+
},
|
221
|
+
],
|
222
|
+
UpdatedDependencyFiles = [
|
223
|
+
new()
|
224
|
+
{
|
225
|
+
Directory = "/test",
|
226
|
+
Name = "project.csproj",
|
227
|
+
Content = "updated contents",
|
228
|
+
},
|
229
|
+
],
|
230
|
+
BaseCommitSha = "TEST-COMMIT-SHA",
|
231
|
+
CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
|
232
|
+
PrTitle = RunWorkerTests.TestPullRequestTitle,
|
233
|
+
PrBody = RunWorkerTests.TestPullRequestBody,
|
234
|
+
DependencyGroup = null,
|
235
|
+
},
|
236
|
+
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
237
|
+
]
|
238
|
+
);
|
239
|
+
}
|
240
|
+
|
241
|
+
[Fact]
|
242
|
+
public async Task GeneratesCreatePullRequest_Grouped()
|
243
|
+
{
|
244
|
+
// single groups specified; creates 1 PR for both directories
|
245
|
+
await TestAsync(
|
246
|
+
job: new Job()
|
247
|
+
{
|
248
|
+
Source = CreateJobSource("/src", "/test"),
|
249
|
+
DependencyGroups = [
|
250
|
+
new()
|
251
|
+
{
|
252
|
+
Name = "test-group",
|
253
|
+
Rules = new()
|
254
|
+
{
|
255
|
+
["patterns"] = new[] { "*" },
|
256
|
+
["exclude-patterns"] = new[] { "Unrelated.*" },
|
257
|
+
},
|
258
|
+
},
|
259
|
+
],
|
260
|
+
},
|
261
|
+
files: [
|
262
|
+
("src/project.csproj", "initial contents"),
|
263
|
+
("test/project.csproj", "initial contents"),
|
264
|
+
],
|
265
|
+
discoveryWorker: TestDiscoveryWorker.FromResults(
|
266
|
+
("/src", new WorkspaceDiscoveryResult()
|
267
|
+
{
|
268
|
+
Path = "/src",
|
269
|
+
Projects = [
|
270
|
+
new()
|
271
|
+
{
|
272
|
+
FilePath = "project.csproj",
|
273
|
+
Dependencies = [
|
274
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
275
|
+
new("Some.Other.Dependency", "3.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
276
|
+
new("Unrelated.Dependency", "5.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
277
|
+
],
|
278
|
+
ImportedFiles = [],
|
279
|
+
AdditionalFiles = [],
|
280
|
+
}
|
281
|
+
],
|
282
|
+
}),
|
283
|
+
("/test", new WorkspaceDiscoveryResult()
|
284
|
+
{
|
285
|
+
Path = "/test",
|
286
|
+
Projects = [
|
287
|
+
new()
|
288
|
+
{
|
289
|
+
FilePath = "project.csproj",
|
290
|
+
Dependencies = [
|
291
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
292
|
+
new("Some.Other.Dependency", "3.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
293
|
+
new("Unrelated.Dependency", "5.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
294
|
+
],
|
295
|
+
ImportedFiles = [],
|
296
|
+
AdditionalFiles = [],
|
297
|
+
}
|
298
|
+
],
|
299
|
+
})
|
300
|
+
),
|
301
|
+
analyzeWorker: new TestAnalyzeWorker(input =>
|
302
|
+
{
|
303
|
+
var repoRoot = input.Item1;
|
304
|
+
var discovery = input.Item2;
|
305
|
+
var dependencyInfo = input.Item3;
|
306
|
+
var newVersion = dependencyInfo.Name switch
|
307
|
+
{
|
308
|
+
"Some.Dependency" => "2.0.0",
|
309
|
+
"Some.Other.Dependency" => "4.0.0",
|
310
|
+
_ => throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}"),
|
311
|
+
};
|
312
|
+
return Task.FromResult(new AnalysisResult()
|
313
|
+
{
|
314
|
+
CanUpdate = true,
|
315
|
+
UpdatedVersion = newVersion,
|
316
|
+
UpdatedDependencies = [],
|
317
|
+
});
|
318
|
+
}),
|
319
|
+
updaterWorker: new TestUpdaterWorker(async input =>
|
320
|
+
{
|
321
|
+
var repoRoot = input.Item1;
|
322
|
+
var workspacePath = input.Item2;
|
323
|
+
var dependencyName = input.Item3;
|
324
|
+
var previousVersion = input.Item4;
|
325
|
+
var newVersion = input.Item5;
|
326
|
+
var isTransitive = input.Item6;
|
327
|
+
|
328
|
+
await File.WriteAllTextAsync(Path.Join(repoRoot, workspacePath), "updated contents");
|
329
|
+
|
330
|
+
return new UpdateOperationResult()
|
331
|
+
{
|
332
|
+
UpdateOperations = [new DirectUpdate() { DependencyName = dependencyName, NewVersion = NuGetVersion.Parse(newVersion), UpdatedFiles = [workspacePath] }],
|
333
|
+
};
|
334
|
+
}),
|
335
|
+
expectedUpdateHandler: GroupUpdateAllVersionsHandler.Instance,
|
336
|
+
expectedApiMessages: [
|
337
|
+
new IncrementMetric()
|
338
|
+
{
|
339
|
+
Metric = "updater.started",
|
340
|
+
Tags = new()
|
341
|
+
{
|
342
|
+
["operation"] = "group_update_all_versions",
|
343
|
+
}
|
344
|
+
},
|
345
|
+
// for "/src"
|
346
|
+
new UpdatedDependencyList()
|
347
|
+
{
|
348
|
+
Dependencies = [
|
349
|
+
new()
|
350
|
+
{
|
351
|
+
Name = "Some.Dependency",
|
352
|
+
Version = "1.0.0",
|
353
|
+
Requirements = [
|
354
|
+
new() { Requirement = "1.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
355
|
+
],
|
356
|
+
},
|
357
|
+
new()
|
358
|
+
{
|
359
|
+
Name = "Some.Other.Dependency",
|
360
|
+
Version = "3.0.0",
|
361
|
+
Requirements = [
|
362
|
+
new() { Requirement = "3.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
363
|
+
],
|
364
|
+
},
|
365
|
+
new()
|
366
|
+
{
|
367
|
+
Name = "Unrelated.Dependency",
|
368
|
+
Version = "5.0.0",
|
369
|
+
Requirements = [
|
370
|
+
new() { Requirement = "5.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
371
|
+
],
|
372
|
+
},
|
373
|
+
],
|
374
|
+
DependencyFiles = ["/src/project.csproj"],
|
375
|
+
},
|
376
|
+
// for "/test"
|
377
|
+
new UpdatedDependencyList()
|
378
|
+
{
|
379
|
+
Dependencies = [
|
380
|
+
new()
|
381
|
+
{
|
382
|
+
Name = "Some.Dependency",
|
383
|
+
Version = "1.0.0",
|
384
|
+
Requirements = [
|
385
|
+
new() { Requirement = "1.0.0", File = "/test/project.csproj", Groups = ["dependencies"] },
|
386
|
+
],
|
387
|
+
},
|
388
|
+
new()
|
389
|
+
{
|
390
|
+
Name = "Some.Other.Dependency",
|
391
|
+
Version = "3.0.0",
|
392
|
+
Requirements = [
|
393
|
+
new() { Requirement = "3.0.0", File = "/test/project.csproj", Groups = ["dependencies"] },
|
394
|
+
],
|
395
|
+
},
|
396
|
+
new()
|
397
|
+
{
|
398
|
+
Name = "Unrelated.Dependency",
|
399
|
+
Version = "5.0.0",
|
400
|
+
Requirements = [
|
401
|
+
new() { Requirement = "5.0.0", File = "/test/project.csproj", Groups = ["dependencies"] },
|
402
|
+
],
|
403
|
+
},
|
404
|
+
],
|
405
|
+
DependencyFiles = ["/test/project.csproj"],
|
406
|
+
},
|
407
|
+
// for both directories
|
408
|
+
new CreatePullRequest()
|
409
|
+
{
|
410
|
+
Dependencies = [
|
411
|
+
new()
|
412
|
+
{
|
413
|
+
Name = "Some.Dependency",
|
414
|
+
Version = "2.0.0",
|
415
|
+
Requirements = [
|
416
|
+
new() { Requirement = "2.0.0", File = "/src/project.csproj", Groups = ["dependencies"], Source = new() { SourceUrl = null } },
|
417
|
+
],
|
418
|
+
PreviousVersion = "1.0.0",
|
419
|
+
PreviousRequirements = [
|
420
|
+
new() { Requirement = "1.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
421
|
+
],
|
422
|
+
},
|
423
|
+
new()
|
424
|
+
{
|
425
|
+
Name = "Some.Other.Dependency",
|
426
|
+
Version = "4.0.0",
|
427
|
+
Requirements = [
|
428
|
+
new() { Requirement = "4.0.0", File = "/src/project.csproj", Groups = ["dependencies"], Source = new() { SourceUrl = null } },
|
429
|
+
],
|
430
|
+
PreviousVersion = "3.0.0",
|
431
|
+
PreviousRequirements = [
|
432
|
+
new() { Requirement = "3.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
433
|
+
],
|
434
|
+
},
|
435
|
+
new()
|
436
|
+
{
|
437
|
+
Name = "Some.Dependency",
|
438
|
+
Version = "2.0.0",
|
439
|
+
Requirements = [
|
440
|
+
new() { Requirement = "2.0.0", File = "/test/project.csproj", Groups = ["dependencies"], Source = new() { SourceUrl = null } },
|
441
|
+
],
|
442
|
+
PreviousVersion = "1.0.0",
|
443
|
+
PreviousRequirements = [
|
444
|
+
new() { Requirement = "1.0.0", File = "/test/project.csproj", Groups = ["dependencies"] },
|
445
|
+
],
|
446
|
+
},
|
447
|
+
new()
|
448
|
+
{
|
449
|
+
Name = "Some.Other.Dependency",
|
450
|
+
Version = "4.0.0",
|
451
|
+
Requirements = [
|
452
|
+
new() { Requirement = "4.0.0", File = "/test/project.csproj", Groups = ["dependencies"], Source = new() { SourceUrl = null } },
|
453
|
+
],
|
454
|
+
PreviousVersion = "3.0.0",
|
455
|
+
PreviousRequirements = [
|
456
|
+
new() { Requirement = "3.0.0", File = "/test/project.csproj", Groups = ["dependencies"] },
|
457
|
+
],
|
458
|
+
},
|
459
|
+
],
|
460
|
+
UpdatedDependencyFiles = [
|
461
|
+
new()
|
462
|
+
{
|
463
|
+
Directory = "/src",
|
464
|
+
Name = "project.csproj",
|
465
|
+
Content = "updated contents",
|
466
|
+
},
|
467
|
+
new()
|
468
|
+
{
|
469
|
+
Directory = "/test",
|
470
|
+
Name = "project.csproj",
|
471
|
+
Content = "updated contents",
|
472
|
+
},
|
473
|
+
],
|
474
|
+
BaseCommitSha = "TEST-COMMIT-SHA",
|
475
|
+
CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
|
476
|
+
PrTitle = RunWorkerTests.TestPullRequestTitle,
|
477
|
+
PrBody = RunWorkerTests.TestPullRequestBody,
|
478
|
+
DependencyGroup = "test-group",
|
479
|
+
},
|
480
|
+
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
481
|
+
]
|
482
|
+
);
|
483
|
+
}
|
484
|
+
|
485
|
+
[Fact]
|
486
|
+
public async Task GeneratesCreatePullRequest_Grouped_SecurityUpdatesOnly()
|
487
|
+
{
|
488
|
+
// no groups specified; create 1 PR for each directory, but only for those dependencies explicitly listed
|
489
|
+
await TestAsync(
|
490
|
+
job: new Job()
|
491
|
+
{
|
492
|
+
Dependencies = ["Some.Dependency"],
|
493
|
+
DependencyGroups = [
|
494
|
+
new()
|
495
|
+
{
|
496
|
+
Name = "test-group",
|
497
|
+
Rules = new()
|
498
|
+
{
|
499
|
+
["patterns"] = new[] { "*" }
|
500
|
+
},
|
501
|
+
AppliesTo = "security-updates",
|
502
|
+
}
|
503
|
+
],
|
504
|
+
SecurityAdvisories = [
|
505
|
+
new()
|
506
|
+
{
|
507
|
+
DependencyName = "Some.Dependency",
|
508
|
+
PatchedVersions = [],
|
509
|
+
UnaffectedVersions = [],
|
510
|
+
AffectedVersions = [Requirement.Parse("< 2.0.0")]
|
511
|
+
}
|
512
|
+
],
|
513
|
+
SecurityUpdatesOnly = true,
|
514
|
+
Source = CreateJobSource("/src"),
|
515
|
+
},
|
516
|
+
files: [
|
517
|
+
("src/project.csproj", "initial contents"),
|
518
|
+
],
|
519
|
+
discoveryWorker: TestDiscoveryWorker.FromResults(
|
520
|
+
("/src", new WorkspaceDiscoveryResult()
|
521
|
+
{
|
522
|
+
Path = "/src",
|
523
|
+
Projects = [
|
524
|
+
new()
|
525
|
+
{
|
526
|
+
FilePath = "project.csproj",
|
527
|
+
Dependencies = [
|
528
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
529
|
+
new("Some.Other.Dependency", "3.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
530
|
+
],
|
531
|
+
ImportedFiles = [],
|
532
|
+
AdditionalFiles = [],
|
533
|
+
}
|
534
|
+
],
|
535
|
+
})
|
536
|
+
),
|
537
|
+
analyzeWorker: new TestAnalyzeWorker(input =>
|
538
|
+
{
|
539
|
+
var repoRoot = input.Item1;
|
540
|
+
var discovery = input.Item2;
|
541
|
+
var dependencyInfo = input.Item3;
|
542
|
+
if (dependencyInfo.Name != "Some.Dependency")
|
543
|
+
{
|
544
|
+
throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}");
|
545
|
+
}
|
546
|
+
|
547
|
+
return Task.FromResult(new AnalysisResult()
|
548
|
+
{
|
549
|
+
CanUpdate = true,
|
550
|
+
UpdatedVersion = "2.0.0",
|
551
|
+
UpdatedDependencies = [],
|
552
|
+
});
|
553
|
+
}),
|
554
|
+
updaterWorker: new TestUpdaterWorker(async input =>
|
555
|
+
{
|
556
|
+
var repoRoot = input.Item1;
|
557
|
+
var workspacePath = input.Item2;
|
558
|
+
var dependencyName = input.Item3;
|
559
|
+
var previousVersion = input.Item4;
|
560
|
+
var newVersion = input.Item5;
|
561
|
+
var isTransitive = input.Item6;
|
562
|
+
|
563
|
+
await File.WriteAllTextAsync(Path.Join(repoRoot, workspacePath), "updated contents");
|
564
|
+
|
565
|
+
return new UpdateOperationResult()
|
566
|
+
{
|
567
|
+
UpdateOperations = [new DirectUpdate() { DependencyName = dependencyName, NewVersion = NuGetVersion.Parse(newVersion), UpdatedFiles = [workspacePath] }],
|
568
|
+
};
|
569
|
+
}),
|
570
|
+
expectedUpdateHandler: GroupUpdateAllVersionsHandler.Instance,
|
571
|
+
expectedApiMessages: [
|
572
|
+
new IncrementMetric()
|
573
|
+
{
|
574
|
+
Metric = "updater.started",
|
575
|
+
Tags = new()
|
576
|
+
{
|
577
|
+
["operation"] = "group_update_all_versions",
|
578
|
+
}
|
579
|
+
},
|
580
|
+
new UpdatedDependencyList()
|
581
|
+
{
|
582
|
+
Dependencies = [
|
583
|
+
new()
|
584
|
+
{
|
585
|
+
Name = "Some.Dependency",
|
586
|
+
Version = "1.0.0",
|
587
|
+
Requirements = [
|
588
|
+
new() { Requirement = "1.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
589
|
+
],
|
590
|
+
},
|
591
|
+
new()
|
592
|
+
{
|
593
|
+
Name = "Some.Other.Dependency",
|
594
|
+
Version = "3.0.0",
|
595
|
+
Requirements = [
|
596
|
+
new() { Requirement = "3.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
597
|
+
],
|
598
|
+
},
|
599
|
+
],
|
600
|
+
DependencyFiles = ["/src/project.csproj"],
|
601
|
+
},
|
602
|
+
new CreatePullRequest()
|
603
|
+
{
|
604
|
+
Dependencies = [
|
605
|
+
new()
|
606
|
+
{
|
607
|
+
Name = "Some.Dependency",
|
608
|
+
Version = "2.0.0",
|
609
|
+
Requirements = [
|
610
|
+
new() { Requirement = "2.0.0", File = "/src/project.csproj", Groups = ["dependencies"], Source = new() { SourceUrl = null } },
|
611
|
+
],
|
612
|
+
PreviousVersion = "1.0.0",
|
613
|
+
PreviousRequirements = [
|
614
|
+
new() { Requirement = "1.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
615
|
+
],
|
616
|
+
},
|
617
|
+
],
|
618
|
+
UpdatedDependencyFiles = [
|
619
|
+
new()
|
620
|
+
{
|
621
|
+
Directory = "/src",
|
622
|
+
Name = "project.csproj",
|
623
|
+
Content = "updated contents",
|
624
|
+
},
|
625
|
+
],
|
626
|
+
BaseCommitSha = "TEST-COMMIT-SHA",
|
627
|
+
CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
|
628
|
+
PrTitle = RunWorkerTests.TestPullRequestTitle,
|
629
|
+
PrBody = RunWorkerTests.TestPullRequestBody,
|
630
|
+
DependencyGroup = "test-group",
|
631
|
+
},
|
632
|
+
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
633
|
+
]
|
634
|
+
);
|
635
|
+
}
|
636
|
+
}
|