dependabot-nuget 0.315.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.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 +150 -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 +82 -31
- 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 +278 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/IUpdateHandler.cs +22 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshGroupUpdatePullRequestHandler.cs +194 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandler.cs +203 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandler.cs +193 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/SpecialImportsConditionPatcher.cs +15 -2
- 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 +299 -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 +798 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshGroupUpdatePullRequestHandlerTests.cs +818 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandlerTests.cs +1079 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandlerTests.cs +896 -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/SpecialFilePatcherTests.cs +25 -0
- 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,818 @@
|
|
1
|
+
using System.Collections.Immutable;
|
2
|
+
|
3
|
+
using NuGet.Versioning;
|
4
|
+
|
5
|
+
using NuGetUpdater.Core.Analyze;
|
6
|
+
using NuGetUpdater.Core.Discover;
|
7
|
+
using NuGetUpdater.Core.Run.ApiModel;
|
8
|
+
using NuGetUpdater.Core.Run.UpdateHandlers;
|
9
|
+
using NuGetUpdater.Core.Updater;
|
10
|
+
|
11
|
+
using Xunit;
|
12
|
+
|
13
|
+
namespace NuGetUpdater.Core.Test.Run.UpdateHandlers;
|
14
|
+
|
15
|
+
public class RefreshGroupUpdatePullRequestHandlerTests : UpdateHandlersTestsBase
|
16
|
+
{
|
17
|
+
[Fact]
|
18
|
+
public async Task GeneratesUpdatePullRequest()
|
19
|
+
{
|
20
|
+
await TestAsync(
|
21
|
+
job: new Job()
|
22
|
+
{
|
23
|
+
Dependencies = ["Some.Dependency"],
|
24
|
+
DependencyGroups = [new() { Name = "test_group" }],
|
25
|
+
DependencyGroupToRefresh = "test_group",
|
26
|
+
ExistingPullRequests = [new() { Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("2.0.0") }] }],
|
27
|
+
Source = CreateJobSource("/src"),
|
28
|
+
UpdatingAPullRequest = true,
|
29
|
+
},
|
30
|
+
files: [
|
31
|
+
("src/project.csproj", "initial contents"),
|
32
|
+
],
|
33
|
+
discoveryWorker: TestDiscoveryWorker.FromResults(
|
34
|
+
("/src", new WorkspaceDiscoveryResult()
|
35
|
+
{
|
36
|
+
Path = "/src",
|
37
|
+
Projects = [
|
38
|
+
new()
|
39
|
+
{
|
40
|
+
FilePath = "project.csproj",
|
41
|
+
Dependencies = [
|
42
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
43
|
+
new("Unrelated.Dependency", "3.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
44
|
+
],
|
45
|
+
ImportedFiles = [],
|
46
|
+
AdditionalFiles = [],
|
47
|
+
}
|
48
|
+
],
|
49
|
+
})
|
50
|
+
),
|
51
|
+
analyzeWorker: new TestAnalyzeWorker(input =>
|
52
|
+
{
|
53
|
+
var repoRoot = input.Item1;
|
54
|
+
var discovery = input.Item2;
|
55
|
+
var dependencyInfo = input.Item3;
|
56
|
+
if (dependencyInfo.Name != "Some.Dependency")
|
57
|
+
{
|
58
|
+
throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}");
|
59
|
+
}
|
60
|
+
|
61
|
+
return Task.FromResult(new AnalysisResult()
|
62
|
+
{
|
63
|
+
CanUpdate = true,
|
64
|
+
UpdatedVersion = "2.0.0",
|
65
|
+
UpdatedDependencies = [],
|
66
|
+
});
|
67
|
+
}),
|
68
|
+
updaterWorker: new TestUpdaterWorker(async input =>
|
69
|
+
{
|
70
|
+
var repoRoot = input.Item1;
|
71
|
+
var workspacePath = input.Item2;
|
72
|
+
var dependencyName = input.Item3;
|
73
|
+
var previousVersion = input.Item4;
|
74
|
+
var newVersion = input.Item5;
|
75
|
+
var isTransitive = input.Item6;
|
76
|
+
|
77
|
+
await File.WriteAllTextAsync(Path.Join(repoRoot, workspacePath), "updated contents");
|
78
|
+
|
79
|
+
return new UpdateOperationResult()
|
80
|
+
{
|
81
|
+
UpdateOperations = [new DirectUpdate() { DependencyName = "Some.Dependency", NewVersion = NuGetVersion.Parse("2.0.0"), UpdatedFiles = ["/src/project.csproj"] }],
|
82
|
+
};
|
83
|
+
}),
|
84
|
+
expectedUpdateHandler: RefreshGroupUpdatePullRequestHandler.Instance,
|
85
|
+
expectedApiMessages: [
|
86
|
+
new UpdatedDependencyList()
|
87
|
+
{
|
88
|
+
Dependencies = [
|
89
|
+
new()
|
90
|
+
{
|
91
|
+
Name = "Some.Dependency",
|
92
|
+
Version = "1.0.0",
|
93
|
+
Requirements = [
|
94
|
+
new() { Requirement = "1.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
95
|
+
],
|
96
|
+
},
|
97
|
+
new()
|
98
|
+
{
|
99
|
+
Name = "Unrelated.Dependency",
|
100
|
+
Version = "3.0.0",
|
101
|
+
Requirements = [
|
102
|
+
new() { Requirement = "3.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
103
|
+
],
|
104
|
+
},
|
105
|
+
],
|
106
|
+
DependencyFiles = ["/src/project.csproj"],
|
107
|
+
},
|
108
|
+
new IncrementMetric()
|
109
|
+
{
|
110
|
+
Metric = "updater.started",
|
111
|
+
Tags = new()
|
112
|
+
{
|
113
|
+
["operation"] = "update_version_group_pr",
|
114
|
+
}
|
115
|
+
},
|
116
|
+
new UpdatePullRequest()
|
117
|
+
{
|
118
|
+
DependencyNames = ["Some.Dependency"],
|
119
|
+
DependencyGroup = "test_group",
|
120
|
+
UpdatedDependencyFiles = [
|
121
|
+
new()
|
122
|
+
{
|
123
|
+
Directory = "/src",
|
124
|
+
Name = "project.csproj",
|
125
|
+
Content = "updated contents",
|
126
|
+
}
|
127
|
+
],
|
128
|
+
BaseCommitSha = "TEST-COMMIT-SHA",
|
129
|
+
CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
|
130
|
+
PrTitle = RunWorkerTests.TestPullRequestTitle,
|
131
|
+
PrBody = RunWorkerTests.TestPullRequestBody,
|
132
|
+
},
|
133
|
+
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
134
|
+
]
|
135
|
+
);
|
136
|
+
}
|
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
|
+
|
447
|
+
[Fact]
|
448
|
+
public async Task GeneratesClosePullRequest_UpdateNoLongerPossible()
|
449
|
+
{
|
450
|
+
await TestAsync(
|
451
|
+
job: new Job()
|
452
|
+
{
|
453
|
+
Dependencies = ["Some.Dependency"],
|
454
|
+
DependencyGroups = [new() { Name = "test_group" }],
|
455
|
+
DependencyGroupToRefresh = "test_group",
|
456
|
+
ExistingPullRequests = [new() { Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("2.0.0") }] }],
|
457
|
+
Source = CreateJobSource("/src"),
|
458
|
+
UpdatingAPullRequest = true,
|
459
|
+
},
|
460
|
+
files: [
|
461
|
+
("src/project.csproj", "initial contents"),
|
462
|
+
],
|
463
|
+
discoveryWorker: TestDiscoveryWorker.FromResults(
|
464
|
+
("/src", new WorkspaceDiscoveryResult()
|
465
|
+
{
|
466
|
+
Path = "/src",
|
467
|
+
Projects = [
|
468
|
+
new()
|
469
|
+
{
|
470
|
+
FilePath = "project.csproj",
|
471
|
+
Dependencies = [
|
472
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
473
|
+
],
|
474
|
+
ImportedFiles = [],
|
475
|
+
AdditionalFiles = [],
|
476
|
+
}
|
477
|
+
],
|
478
|
+
})
|
479
|
+
),
|
480
|
+
analyzeWorker: new TestAnalyzeWorker(input =>
|
481
|
+
{
|
482
|
+
var repoRoot = input.Item1;
|
483
|
+
var discovery = input.Item2;
|
484
|
+
var dependencyInfo = input.Item3;
|
485
|
+
if (dependencyInfo.Name != "Some.Dependency")
|
486
|
+
{
|
487
|
+
throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}");
|
488
|
+
}
|
489
|
+
|
490
|
+
return Task.FromResult(new AnalysisResult()
|
491
|
+
{
|
492
|
+
CanUpdate = false,
|
493
|
+
UpdatedVersion = "1.0.0",
|
494
|
+
UpdatedDependencies = [],
|
495
|
+
});
|
496
|
+
}),
|
497
|
+
updaterWorker: new TestUpdaterWorker(input => throw new NotImplementedException("test shouldn't get this far")),
|
498
|
+
expectedUpdateHandler: RefreshGroupUpdatePullRequestHandler.Instance,
|
499
|
+
expectedApiMessages: [
|
500
|
+
new UpdatedDependencyList()
|
501
|
+
{
|
502
|
+
Dependencies = [
|
503
|
+
new()
|
504
|
+
{
|
505
|
+
Name = "Some.Dependency",
|
506
|
+
Version = "1.0.0",
|
507
|
+
Requirements = [
|
508
|
+
new() { Requirement = "1.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
509
|
+
],
|
510
|
+
}
|
511
|
+
],
|
512
|
+
DependencyFiles = ["/src/project.csproj"],
|
513
|
+
},
|
514
|
+
new IncrementMetric()
|
515
|
+
{
|
516
|
+
Metric = "updater.started",
|
517
|
+
Tags = new()
|
518
|
+
{
|
519
|
+
["operation"] = "update_version_group_pr",
|
520
|
+
}
|
521
|
+
},
|
522
|
+
new ClosePullRequest() { DependencyNames = ["Some.Dependency"], Reason = "update_no_longer_possible" },
|
523
|
+
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
524
|
+
]
|
525
|
+
);
|
526
|
+
}
|
527
|
+
|
528
|
+
[Fact]
|
529
|
+
public async Task RecreatesPullRequest()
|
530
|
+
{
|
531
|
+
await TestAsync(
|
532
|
+
job: new Job()
|
533
|
+
{
|
534
|
+
Dependencies = ["Some.Dependency", "Some.Other.Dependency"],
|
535
|
+
DependencyGroups = [new() { Name = "test_group" }],
|
536
|
+
DependencyGroupToRefresh = "test_group",
|
537
|
+
ExistingPullRequests = [
|
538
|
+
new()
|
539
|
+
{
|
540
|
+
Dependencies = [
|
541
|
+
new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("2.0.0") },
|
542
|
+
new() { DependencyName = "Some.Other.Dependency", DependencyVersion = NuGetVersion.Parse("4.0.0") },
|
543
|
+
]
|
544
|
+
},
|
545
|
+
],
|
546
|
+
Source = CreateJobSource("/src"),
|
547
|
+
UpdatingAPullRequest = true,
|
548
|
+
},
|
549
|
+
files: [
|
550
|
+
("src/project.csproj", "initial contents"),
|
551
|
+
],
|
552
|
+
discoveryWorker: TestDiscoveryWorker.FromResults(
|
553
|
+
("/src", new WorkspaceDiscoveryResult()
|
554
|
+
{
|
555
|
+
Path = "/src",
|
556
|
+
Projects = [
|
557
|
+
new()
|
558
|
+
{
|
559
|
+
FilePath = "project.csproj",
|
560
|
+
Dependencies = [
|
561
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
562
|
+
new("Some.Other.Dependency", "3.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
563
|
+
],
|
564
|
+
ImportedFiles = [],
|
565
|
+
AdditionalFiles = [],
|
566
|
+
}
|
567
|
+
],
|
568
|
+
})
|
569
|
+
),
|
570
|
+
analyzeWorker: new TestAnalyzeWorker(input =>
|
571
|
+
{
|
572
|
+
var repoRoot = input.Item1;
|
573
|
+
var discovery = input.Item2;
|
574
|
+
var dependencyInfo = input.Item3;
|
575
|
+
var updatedVersion = dependencyInfo.Name switch
|
576
|
+
{
|
577
|
+
"Some.Dependency" => "2.0.1",
|
578
|
+
"Some.Other.Dependency" => "4.0.1",
|
579
|
+
_ => throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}"),
|
580
|
+
};
|
581
|
+
|
582
|
+
return Task.FromResult(new AnalysisResult()
|
583
|
+
{
|
584
|
+
CanUpdate = true,
|
585
|
+
UpdatedVersion = updatedVersion,
|
586
|
+
UpdatedDependencies = [],
|
587
|
+
});
|
588
|
+
}),
|
589
|
+
updaterWorker: new TestUpdaterWorker(async input =>
|
590
|
+
{
|
591
|
+
var repoRoot = input.Item1;
|
592
|
+
var workspacePath = input.Item2;
|
593
|
+
var dependencyName = input.Item3;
|
594
|
+
var previousVersion = input.Item4;
|
595
|
+
var newVersion = input.Item5;
|
596
|
+
var isTransitive = input.Item6;
|
597
|
+
|
598
|
+
await File.WriteAllTextAsync(Path.Join(repoRoot, workspacePath), "updated contents");
|
599
|
+
|
600
|
+
return new UpdateOperationResult()
|
601
|
+
{
|
602
|
+
UpdateOperations = [new DirectUpdate() { DependencyName = dependencyName, NewVersion = NuGetVersion.Parse(newVersion), UpdatedFiles = ["/src/project.csproj"] }],
|
603
|
+
};
|
604
|
+
}),
|
605
|
+
expectedUpdateHandler: RefreshGroupUpdatePullRequestHandler.Instance,
|
606
|
+
expectedApiMessages: [
|
607
|
+
new UpdatedDependencyList()
|
608
|
+
{
|
609
|
+
Dependencies = [
|
610
|
+
new()
|
611
|
+
{
|
612
|
+
Name = "Some.Dependency",
|
613
|
+
Version = "1.0.0",
|
614
|
+
Requirements = [
|
615
|
+
new() { Requirement = "1.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
616
|
+
],
|
617
|
+
},
|
618
|
+
new()
|
619
|
+
{
|
620
|
+
Name = "Some.Other.Dependency",
|
621
|
+
Version = "3.0.0",
|
622
|
+
Requirements = [
|
623
|
+
new() { Requirement = "3.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
624
|
+
],
|
625
|
+
}
|
626
|
+
],
|
627
|
+
DependencyFiles = ["/src/project.csproj"],
|
628
|
+
},
|
629
|
+
new IncrementMetric()
|
630
|
+
{
|
631
|
+
Metric = "updater.started",
|
632
|
+
Tags = new()
|
633
|
+
{
|
634
|
+
["operation"] = "update_version_group_pr",
|
635
|
+
}
|
636
|
+
},
|
637
|
+
new ClosePullRequest() { DependencyNames = ["Some.Dependency", "Some.Other.Dependency"], Reason = "dependencies_changed" },
|
638
|
+
new CreatePullRequest()
|
639
|
+
{
|
640
|
+
Dependencies = [
|
641
|
+
new()
|
642
|
+
{
|
643
|
+
Name = "Some.Dependency",
|
644
|
+
Version = "2.0.1",
|
645
|
+
Requirements = [
|
646
|
+
new() { Requirement = "2.0.1", File = "/src/project.csproj", Groups = ["dependencies"], Source = new() { SourceUrl = null } },
|
647
|
+
],
|
648
|
+
PreviousVersion = "1.0.0",
|
649
|
+
PreviousRequirements = [
|
650
|
+
new() { Requirement = "1.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
651
|
+
],
|
652
|
+
},
|
653
|
+
new()
|
654
|
+
{
|
655
|
+
Name = "Some.Other.Dependency",
|
656
|
+
Version = "4.0.1",
|
657
|
+
Requirements = [
|
658
|
+
new() { Requirement = "4.0.1", File = "/src/project.csproj", Groups = ["dependencies"], Source = new() { SourceUrl = null } },
|
659
|
+
],
|
660
|
+
PreviousVersion = "3.0.0",
|
661
|
+
PreviousRequirements = [
|
662
|
+
new() { Requirement = "3.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
663
|
+
],
|
664
|
+
}
|
665
|
+
],
|
666
|
+
UpdatedDependencyFiles = [
|
667
|
+
new()
|
668
|
+
{
|
669
|
+
Directory = "/src",
|
670
|
+
Name = "project.csproj",
|
671
|
+
Content = "updated contents",
|
672
|
+
}
|
673
|
+
],
|
674
|
+
BaseCommitSha = "TEST-COMMIT-SHA",
|
675
|
+
CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
|
676
|
+
PrTitle = RunWorkerTests.TestPullRequestTitle,
|
677
|
+
PrBody = RunWorkerTests.TestPullRequestBody,
|
678
|
+
DependencyGroup = "test_group",
|
679
|
+
},
|
680
|
+
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
681
|
+
]
|
682
|
+
);
|
683
|
+
}
|
684
|
+
|
685
|
+
[Fact]
|
686
|
+
public async Task GeneratesCreatePullRequest()
|
687
|
+
{
|
688
|
+
await TestAsync(
|
689
|
+
job: new Job()
|
690
|
+
{
|
691
|
+
Dependencies = ["Some.Dependency"],
|
692
|
+
DependencyGroups = [new() { Name = "test_group" }],
|
693
|
+
DependencyGroupToRefresh = "test_group",
|
694
|
+
ExistingPullRequests = [
|
695
|
+
new()
|
696
|
+
{
|
697
|
+
Dependencies = [
|
698
|
+
new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("2.0.0") },
|
699
|
+
new() { DependencyName = "Some.Other.Dependency", DependencyVersion = NuGetVersion.Parse("4.0.0") },
|
700
|
+
]
|
701
|
+
},
|
702
|
+
],
|
703
|
+
Source = CreateJobSource("/src"),
|
704
|
+
UpdatingAPullRequest = true,
|
705
|
+
},
|
706
|
+
files: [
|
707
|
+
("src/project.csproj", "initial contents"),
|
708
|
+
],
|
709
|
+
discoveryWorker: TestDiscoveryWorker.FromResults(
|
710
|
+
("/src", new WorkspaceDiscoveryResult()
|
711
|
+
{
|
712
|
+
Path = "/src",
|
713
|
+
Projects = [
|
714
|
+
new()
|
715
|
+
{
|
716
|
+
FilePath = "project.csproj",
|
717
|
+
Dependencies = [
|
718
|
+
new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
|
719
|
+
],
|
720
|
+
ImportedFiles = [],
|
721
|
+
AdditionalFiles = [],
|
722
|
+
}
|
723
|
+
],
|
724
|
+
})
|
725
|
+
),
|
726
|
+
analyzeWorker: new TestAnalyzeWorker(input =>
|
727
|
+
{
|
728
|
+
var repoRoot = input.Item1;
|
729
|
+
var discovery = input.Item2;
|
730
|
+
var dependencyInfo = input.Item3;
|
731
|
+
var updatedVersion = dependencyInfo.Name switch
|
732
|
+
{
|
733
|
+
"Some.Dependency" => "2.0.0",
|
734
|
+
_ => throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}"),
|
735
|
+
};
|
736
|
+
|
737
|
+
return Task.FromResult(new AnalysisResult()
|
738
|
+
{
|
739
|
+
CanUpdate = true,
|
740
|
+
UpdatedVersion = updatedVersion,
|
741
|
+
UpdatedDependencies = [],
|
742
|
+
});
|
743
|
+
}),
|
744
|
+
updaterWorker: new TestUpdaterWorker(async input =>
|
745
|
+
{
|
746
|
+
var repoRoot = input.Item1;
|
747
|
+
var workspacePath = input.Item2;
|
748
|
+
var dependencyName = input.Item3;
|
749
|
+
var previousVersion = input.Item4;
|
750
|
+
var newVersion = input.Item5;
|
751
|
+
var isTransitive = input.Item6;
|
752
|
+
|
753
|
+
await File.WriteAllTextAsync(Path.Join(repoRoot, workspacePath), "updated contents");
|
754
|
+
|
755
|
+
return new UpdateOperationResult()
|
756
|
+
{
|
757
|
+
UpdateOperations = [new DirectUpdate() { DependencyName = dependencyName, NewVersion = NuGetVersion.Parse(newVersion), UpdatedFiles = ["/src/project.csproj"] }],
|
758
|
+
};
|
759
|
+
}),
|
760
|
+
expectedUpdateHandler: RefreshGroupUpdatePullRequestHandler.Instance,
|
761
|
+
expectedApiMessages: [
|
762
|
+
new UpdatedDependencyList()
|
763
|
+
{
|
764
|
+
Dependencies = [
|
765
|
+
new()
|
766
|
+
{
|
767
|
+
Name = "Some.Dependency",
|
768
|
+
Version = "1.0.0",
|
769
|
+
Requirements = [
|
770
|
+
new() { Requirement = "1.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
771
|
+
],
|
772
|
+
}
|
773
|
+
],
|
774
|
+
DependencyFiles = ["/src/project.csproj"],
|
775
|
+
},
|
776
|
+
new IncrementMetric()
|
777
|
+
{
|
778
|
+
Metric = "updater.started",
|
779
|
+
Tags = new()
|
780
|
+
{
|
781
|
+
["operation"] = "update_version_group_pr",
|
782
|
+
}
|
783
|
+
},
|
784
|
+
new CreatePullRequest()
|
785
|
+
{
|
786
|
+
Dependencies = [
|
787
|
+
new()
|
788
|
+
{
|
789
|
+
Name = "Some.Dependency",
|
790
|
+
Version = "2.0.0",
|
791
|
+
Requirements = [
|
792
|
+
new() { Requirement = "2.0.0", File = "/src/project.csproj", Groups = ["dependencies"], Source = new() { SourceUrl = null } },
|
793
|
+
],
|
794
|
+
PreviousVersion = "1.0.0",
|
795
|
+
PreviousRequirements = [
|
796
|
+
new() { Requirement = "1.0.0", File = "/src/project.csproj", Groups = ["dependencies"] },
|
797
|
+
],
|
798
|
+
}
|
799
|
+
],
|
800
|
+
UpdatedDependencyFiles = [
|
801
|
+
new()
|
802
|
+
{
|
803
|
+
Directory = "/src",
|
804
|
+
Name = "project.csproj",
|
805
|
+
Content = "updated contents",
|
806
|
+
}
|
807
|
+
],
|
808
|
+
BaseCommitSha = "TEST-COMMIT-SHA",
|
809
|
+
CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
|
810
|
+
PrTitle = RunWorkerTests.TestPullRequestTitle,
|
811
|
+
PrBody = RunWorkerTests.TestPullRequestBody,
|
812
|
+
DependencyGroup = "test_group",
|
813
|
+
},
|
814
|
+
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
815
|
+
]
|
816
|
+
);
|
817
|
+
}
|
818
|
+
}
|