dependabot-nuget 0.300.0 → 0.301.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/Commands/DiscoverCommand.cs +1 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs +2 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/ClosePullRequest.cs +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/CommitOptions.cs +5 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/CreatePullRequest.cs +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/GroupPullRequest.cs +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Job.cs +36 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/JobErrorBase.cs +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/MessageBase.cs +5 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/PullRequest.cs +2 -5
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/PullRequestDependency.cs +11 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/UpdatePullRequest.cs +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/CommitOptions_IncludeScopeConverter.cs +29 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/HttpApiHandler.cs +5 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/IApiHandler.cs +1 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestConverter.cs +35 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestTextGenerator.cs +44 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +205 -49
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.cs +76 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/MiscellaneousTests.cs +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestMessageTests.cs +252 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestTextTests.cs +136 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs +145 -22
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/SerializationTests.cs +15 -10
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/TestApiHandler.cs +6 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/{UpdateAllowedTests.cs → UpdatePermittedAndMessageTests.cs} +110 -6
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestHttpServer.cs +105 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackageReference.cs +75 -0
- metadata +13 -6
@@ -0,0 +1,252 @@
|
|
1
|
+
using NuGet.Versioning;
|
2
|
+
|
3
|
+
using NuGetUpdater.Core.Run;
|
4
|
+
using NuGetUpdater.Core.Run.ApiModel;
|
5
|
+
|
6
|
+
using Xunit;
|
7
|
+
|
8
|
+
namespace NuGetUpdater.Core.Test.Run;
|
9
|
+
|
10
|
+
public class PullRequestMessageTests
|
11
|
+
{
|
12
|
+
[Theory]
|
13
|
+
[MemberData(nameof(GetPullRequestApiMessageData))]
|
14
|
+
public void GetPullRequestApiMessage(Job job, DependencyFile[] updatedFiles, ReportedDependency[] updatedDependencies, MessageBase expectedMessage)
|
15
|
+
{
|
16
|
+
var actualMessage = RunWorker.GetPullRequestApiMessage(job, updatedFiles, updatedDependencies, "TEST-COMMIT-SHA");
|
17
|
+
Assert.NotNull(actualMessage);
|
18
|
+
actualMessage = actualMessage switch
|
19
|
+
{
|
20
|
+
// this isn't the place to verify the generated text
|
21
|
+
CreatePullRequest create => create with { CommitMessage = RunWorkerTests.TestPullRequestCommitMessage, PrTitle = RunWorkerTests.TestPullRequestTitle, PrBody = RunWorkerTests.TestPullRequestBody },
|
22
|
+
UpdatePullRequest update => update with { CommitMessage = RunWorkerTests.TestPullRequestCommitMessage, PrTitle = RunWorkerTests.TestPullRequestTitle, PrBody = RunWorkerTests.TestPullRequestBody },
|
23
|
+
_ => actualMessage,
|
24
|
+
};
|
25
|
+
Assert.Equal(expectedMessage.GetType(), actualMessage.GetType());
|
26
|
+
var actualMessageJson = HttpApiHandler.Serialize(actualMessage);
|
27
|
+
var expectedMessageJson = HttpApiHandler.Serialize(expectedMessage);
|
28
|
+
Assert.Equal(expectedMessageJson, actualMessageJson);
|
29
|
+
}
|
30
|
+
|
31
|
+
public static IEnumerable<object[]> GetPullRequestApiMessageData()
|
32
|
+
{
|
33
|
+
// candidate pull request does not match existing, no matching security advisory => create
|
34
|
+
yield return
|
35
|
+
[
|
36
|
+
// job
|
37
|
+
new Job()
|
38
|
+
{
|
39
|
+
Source = new()
|
40
|
+
{
|
41
|
+
Provider = "github",
|
42
|
+
Repo = "test/repo",
|
43
|
+
}
|
44
|
+
},
|
45
|
+
// updatedFiles
|
46
|
+
new[]
|
47
|
+
{
|
48
|
+
new DependencyFile()
|
49
|
+
{
|
50
|
+
Directory = "/src/",
|
51
|
+
Name = "project.csproj",
|
52
|
+
Content = "project contents irrelevant",
|
53
|
+
}
|
54
|
+
},
|
55
|
+
// updatedDependencies
|
56
|
+
new[]
|
57
|
+
{
|
58
|
+
new ReportedDependency()
|
59
|
+
{
|
60
|
+
Name = "Some.Dependency",
|
61
|
+
Version = "1.0.1",
|
62
|
+
Requirements = [],
|
63
|
+
}
|
64
|
+
},
|
65
|
+
// expectedMessage
|
66
|
+
new CreatePullRequest()
|
67
|
+
{
|
68
|
+
Dependencies = [new ReportedDependency() { Name = "Some.Dependency", Version = "1.0.1", Requirements = [] }],
|
69
|
+
UpdatedDependencyFiles = [new DependencyFile() { Directory = "/src/", Name = "project.csproj", Content = "project contents irrelevant" } ],
|
70
|
+
BaseCommitSha = "TEST-COMMIT-SHA",
|
71
|
+
CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
|
72
|
+
PrTitle = RunWorkerTests.TestPullRequestTitle,
|
73
|
+
PrBody = RunWorkerTests.TestPullRequestBody,
|
74
|
+
}
|
75
|
+
];
|
76
|
+
|
77
|
+
// candidate pull request matches existing, no matching security advisory found => close
|
78
|
+
yield return
|
79
|
+
[
|
80
|
+
// job
|
81
|
+
new Job()
|
82
|
+
{
|
83
|
+
Source = new()
|
84
|
+
{
|
85
|
+
Provider = "github",
|
86
|
+
Repo = "test/repo",
|
87
|
+
},
|
88
|
+
SecurityUpdatesOnly = true,
|
89
|
+
SecurityAdvisories = [], // no matching advisory
|
90
|
+
ExistingPullRequests = [
|
91
|
+
new PullRequest()
|
92
|
+
{
|
93
|
+
Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("1.0.1") }]
|
94
|
+
}
|
95
|
+
]
|
96
|
+
},
|
97
|
+
// updatedFiles
|
98
|
+
Array.Empty<DependencyFile>(), // not used
|
99
|
+
// updatedDependencies
|
100
|
+
new[]
|
101
|
+
{
|
102
|
+
new ReportedDependency()
|
103
|
+
{
|
104
|
+
Name = "Some.Dependency",
|
105
|
+
Version = "1.0.1",
|
106
|
+
Requirements = [], // not used
|
107
|
+
}
|
108
|
+
},
|
109
|
+
// expectedMessage
|
110
|
+
new ClosePullRequest() { DependencyNames = ["Some.Dependency"], Reason = "up_to_date" },
|
111
|
+
];
|
112
|
+
|
113
|
+
// broken
|
114
|
+
// started a security job, but no changes were made => find matching existing PR and close
|
115
|
+
yield return
|
116
|
+
[
|
117
|
+
// job
|
118
|
+
new Job()
|
119
|
+
{
|
120
|
+
Source = new()
|
121
|
+
{
|
122
|
+
Provider = "github",
|
123
|
+
Repo = "test/repo",
|
124
|
+
},
|
125
|
+
Dependencies = ["Some.Dependency"],
|
126
|
+
ExistingPullRequests = [
|
127
|
+
new PullRequest()
|
128
|
+
{
|
129
|
+
Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("1.0.1") }]
|
130
|
+
}
|
131
|
+
],
|
132
|
+
SecurityAdvisories = [
|
133
|
+
new Advisory()
|
134
|
+
{
|
135
|
+
DependencyName = "Some.Dependency",
|
136
|
+
}
|
137
|
+
]
|
138
|
+
},
|
139
|
+
// updatedFiles
|
140
|
+
Array.Empty<DependencyFile>(),
|
141
|
+
// updatedDependencies
|
142
|
+
Array.Empty<ReportedDependency>(),
|
143
|
+
// expectedMessage
|
144
|
+
new ClosePullRequest() { DependencyNames = ["Some.Dependency"], Reason = "dependency_removed" },
|
145
|
+
];
|
146
|
+
|
147
|
+
// candidate pull request matches existing and updating is true => update
|
148
|
+
yield return
|
149
|
+
[
|
150
|
+
// job
|
151
|
+
new Job()
|
152
|
+
{
|
153
|
+
Source = new()
|
154
|
+
{
|
155
|
+
Provider = "github",
|
156
|
+
Repo = "test/repo",
|
157
|
+
},
|
158
|
+
ExistingPullRequests = [
|
159
|
+
new PullRequest()
|
160
|
+
{
|
161
|
+
Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("1.0.1") }]
|
162
|
+
}
|
163
|
+
],
|
164
|
+
UpdatingAPullRequest = true,
|
165
|
+
},
|
166
|
+
// updatedFiles
|
167
|
+
new[]
|
168
|
+
{
|
169
|
+
new DependencyFile()
|
170
|
+
{
|
171
|
+
Directory = "/src/",
|
172
|
+
Name = "project.csproj",
|
173
|
+
Content = "project contents irrelevant",
|
174
|
+
}
|
175
|
+
},
|
176
|
+
// updatedDependencies
|
177
|
+
new[]
|
178
|
+
{
|
179
|
+
new ReportedDependency()
|
180
|
+
{
|
181
|
+
Name = "Some.Dependency",
|
182
|
+
Version = "1.0.1",
|
183
|
+
Requirements = [],
|
184
|
+
}
|
185
|
+
},
|
186
|
+
// expectedMessage
|
187
|
+
new UpdatePullRequest()
|
188
|
+
{
|
189
|
+
DependencyGroup = null,
|
190
|
+
DependencyNames = ["Some.Dependency"],
|
191
|
+
UpdatedDependencyFiles = [new DependencyFile() { Directory = "/src/", Name = "project.csproj", Content = "project contents irrelevant" } ],
|
192
|
+
BaseCommitSha = "TEST-COMMIT-SHA",
|
193
|
+
CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
|
194
|
+
PrTitle = RunWorkerTests.TestPullRequestTitle,
|
195
|
+
PrBody = RunWorkerTests.TestPullRequestBody,
|
196
|
+
}
|
197
|
+
];
|
198
|
+
|
199
|
+
// candidate pull request matches existing group and updating is true => update
|
200
|
+
yield return
|
201
|
+
[
|
202
|
+
// job
|
203
|
+
new Job()
|
204
|
+
{
|
205
|
+
Source = new()
|
206
|
+
{
|
207
|
+
Provider = "github",
|
208
|
+
Repo = "test/repo",
|
209
|
+
},
|
210
|
+
ExistingGroupPullRequests = [
|
211
|
+
new GroupPullRequest()
|
212
|
+
{
|
213
|
+
DependencyGroupName = "test-group",
|
214
|
+
Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("1.0.1") }]
|
215
|
+
}
|
216
|
+
],
|
217
|
+
UpdatingAPullRequest = true,
|
218
|
+
},
|
219
|
+
// updatedFiles
|
220
|
+
new[]
|
221
|
+
{
|
222
|
+
new DependencyFile()
|
223
|
+
{
|
224
|
+
Directory = "/src/",
|
225
|
+
Name = "project.csproj",
|
226
|
+
Content = "project contents irrelevant",
|
227
|
+
}
|
228
|
+
},
|
229
|
+
// updatedDependencies
|
230
|
+
new[]
|
231
|
+
{
|
232
|
+
new ReportedDependency()
|
233
|
+
{
|
234
|
+
Name = "Some.Dependency",
|
235
|
+
Version = "1.0.1",
|
236
|
+
Requirements = [],
|
237
|
+
}
|
238
|
+
},
|
239
|
+
// expectedMessage
|
240
|
+
new UpdatePullRequest()
|
241
|
+
{
|
242
|
+
DependencyGroup = "test-group",
|
243
|
+
DependencyNames = ["Some.Dependency"],
|
244
|
+
UpdatedDependencyFiles = [new DependencyFile() { Directory = "/src/", Name = "project.csproj", Content = "project contents irrelevant" } ],
|
245
|
+
BaseCommitSha = "TEST-COMMIT-SHA",
|
246
|
+
CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
|
247
|
+
PrTitle = RunWorkerTests.TestPullRequestTitle,
|
248
|
+
PrBody = RunWorkerTests.TestPullRequestBody,
|
249
|
+
}
|
250
|
+
];
|
251
|
+
}
|
252
|
+
}
|
@@ -0,0 +1,136 @@
|
|
1
|
+
using NuGetUpdater.Core.Run;
|
2
|
+
using NuGetUpdater.Core.Run.ApiModel;
|
3
|
+
|
4
|
+
using Xunit;
|
5
|
+
|
6
|
+
namespace NuGetUpdater.Core.Test.Run;
|
7
|
+
|
8
|
+
public class PullRequestTextTests
|
9
|
+
{
|
10
|
+
[Theory]
|
11
|
+
[MemberData(nameof(GetPullRequestTextTestData))]
|
12
|
+
public void PullRequestText(Job job, ReportedDependency[] updatedDependencies, DependencyFile[] updatedFiles, string? dependencyGroupName, string expectedTitle, string expectedCommitMessage, string expectedBody)
|
13
|
+
{
|
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);
|
17
|
+
Assert.Equal(expectedTitle, actualTitle);
|
18
|
+
Assert.Equal(expectedCommitMessage, actualCommitMessage);
|
19
|
+
Assert.Equal(expectedBody, actualBody);
|
20
|
+
}
|
21
|
+
|
22
|
+
public static IEnumerable<object?[]> GetPullRequestTextTestData()
|
23
|
+
{
|
24
|
+
// single dependency, no optional values
|
25
|
+
yield return
|
26
|
+
[
|
27
|
+
// job
|
28
|
+
FromCommitOptions(null),
|
29
|
+
// updatedDependencies
|
30
|
+
new []
|
31
|
+
{
|
32
|
+
new ReportedDependency()
|
33
|
+
{
|
34
|
+
Name = "Some.Package",
|
35
|
+
Version = "1.2.3",
|
36
|
+
Requirements = []
|
37
|
+
}
|
38
|
+
},
|
39
|
+
// updatedFiles
|
40
|
+
Array.Empty<DependencyFile>(),
|
41
|
+
// dependencyGroupName
|
42
|
+
null,
|
43
|
+
// expectedTitle
|
44
|
+
"Update Some.Package to 1.2.3",
|
45
|
+
// expectedCommitMessage
|
46
|
+
"Update Some.Package to 1.2.3",
|
47
|
+
// expectedBody
|
48
|
+
"Update Some.Package to 1.2.3"
|
49
|
+
];
|
50
|
+
|
51
|
+
// single dependency, prefix given
|
52
|
+
yield return
|
53
|
+
[
|
54
|
+
// job
|
55
|
+
FromCommitOptions(new(){ Prefix = "[SECURITY] " }),
|
56
|
+
// updatedDependencies
|
57
|
+
new []
|
58
|
+
{
|
59
|
+
new ReportedDependency()
|
60
|
+
{
|
61
|
+
Name = "Some.Package",
|
62
|
+
Version = "1.2.3",
|
63
|
+
Requirements = []
|
64
|
+
}
|
65
|
+
},
|
66
|
+
// updatedFiles
|
67
|
+
Array.Empty<DependencyFile>(),
|
68
|
+
// dependencyGroupName
|
69
|
+
null,
|
70
|
+
// expectedTitle
|
71
|
+
"[SECURITY] Update Some.Package to 1.2.3",
|
72
|
+
// expectedCommitMessage
|
73
|
+
"[SECURITY] Update Some.Package to 1.2.3",
|
74
|
+
// expectedBody
|
75
|
+
"[SECURITY] Update Some.Package to 1.2.3"
|
76
|
+
];
|
77
|
+
|
78
|
+
// multiple dependencies, multiple versions
|
79
|
+
yield return
|
80
|
+
[
|
81
|
+
// job
|
82
|
+
FromCommitOptions(null),
|
83
|
+
// updatedDependencies
|
84
|
+
new[]
|
85
|
+
{
|
86
|
+
new ReportedDependency()
|
87
|
+
{
|
88
|
+
Name = "Package.A",
|
89
|
+
Version = "1.0.0",
|
90
|
+
Requirements = []
|
91
|
+
},
|
92
|
+
new ReportedDependency()
|
93
|
+
{
|
94
|
+
Name = "Package.A",
|
95
|
+
Version = "2.0.0",
|
96
|
+
Requirements = []
|
97
|
+
},
|
98
|
+
new ReportedDependency()
|
99
|
+
{
|
100
|
+
Name = "Package.B",
|
101
|
+
Version = "3.0.0",
|
102
|
+
Requirements = []
|
103
|
+
},
|
104
|
+
new ReportedDependency()
|
105
|
+
{
|
106
|
+
Name = "Package.B",
|
107
|
+
Version = "4.0.0",
|
108
|
+
Requirements = []
|
109
|
+
},
|
110
|
+
},
|
111
|
+
// updatedFiles
|
112
|
+
Array.Empty<DependencyFile>(),
|
113
|
+
// dependencyGroupName
|
114
|
+
null,
|
115
|
+
// expectedTitle
|
116
|
+
"Update Package.A to 1.0.0, 2.0.0; Package.B to 3.0.0, 4.0.0",
|
117
|
+
// expectedCommitMessage
|
118
|
+
"Update Package.A to 1.0.0, 2.0.0; Package.B to 3.0.0, 4.0.0",
|
119
|
+
// expectedBody
|
120
|
+
"Update Package.A to 1.0.0, 2.0.0; Package.B to 3.0.0, 4.0.0"
|
121
|
+
];
|
122
|
+
}
|
123
|
+
|
124
|
+
private static Job FromCommitOptions(CommitOptions? commitOptions)
|
125
|
+
{
|
126
|
+
return new Job()
|
127
|
+
{
|
128
|
+
Source = new()
|
129
|
+
{
|
130
|
+
Provider = "github",
|
131
|
+
Repo = "test/repo"
|
132
|
+
},
|
133
|
+
CommitMessageOptions = commitOptions,
|
134
|
+
};
|
135
|
+
}
|
136
|
+
}
|
@@ -3,6 +3,8 @@ using System.Text;
|
|
3
3
|
using System.Text.Json;
|
4
4
|
using System.Xml.Linq;
|
5
5
|
|
6
|
+
using NuGet.Versioning;
|
7
|
+
|
6
8
|
using NuGetUpdater.Core.Analyze;
|
7
9
|
using NuGetUpdater.Core.Discover;
|
8
10
|
using NuGetUpdater.Core.Run;
|
@@ -20,6 +22,10 @@ using TestFile = (string Path, string Content);
|
|
20
22
|
|
21
23
|
public class RunWorkerTests
|
22
24
|
{
|
25
|
+
public const string TestPullRequestCommitMessage = "test-pull-request-commit-message";
|
26
|
+
public const string TestPullRequestTitle = "test-pull-request-title";
|
27
|
+
public const string TestPullRequestBody = "test-pull-request-body";
|
28
|
+
|
23
29
|
[Theory]
|
24
30
|
[InlineData(EOLType.CR)]
|
25
31
|
[InlineData(EOLType.LF)]
|
@@ -208,9 +214,9 @@ public class RunWorkerTests
|
|
208
214
|
},
|
209
215
|
],
|
210
216
|
BaseCommitSha = "TEST-COMMIT-SHA",
|
211
|
-
CommitMessage =
|
212
|
-
PrTitle =
|
213
|
-
PrBody =
|
217
|
+
CommitMessage = TestPullRequestCommitMessage,
|
218
|
+
PrTitle = TestPullRequestTitle,
|
219
|
+
PrBody = TestPullRequestBody,
|
214
220
|
},
|
215
221
|
new MarkAsProcessed("TEST-COMMIT-SHA")
|
216
222
|
]
|
@@ -460,9 +466,9 @@ public class RunWorkerTests
|
|
460
466
|
|
461
467
|
],
|
462
468
|
BaseCommitSha = "TEST-COMMIT-SHA",
|
463
|
-
CommitMessage =
|
464
|
-
PrTitle =
|
465
|
-
PrBody =
|
469
|
+
CommitMessage = TestPullRequestCommitMessage,
|
470
|
+
PrTitle = TestPullRequestTitle,
|
471
|
+
PrBody = TestPullRequestBody,
|
466
472
|
},
|
467
473
|
new MarkAsProcessed("TEST-COMMIT-SHA")
|
468
474
|
]
|
@@ -854,9 +860,9 @@ public class RunWorkerTests
|
|
854
860
|
},
|
855
861
|
],
|
856
862
|
BaseCommitSha = "TEST-COMMIT-SHA",
|
857
|
-
CommitMessage =
|
858
|
-
PrTitle =
|
859
|
-
PrBody =
|
863
|
+
CommitMessage = TestPullRequestCommitMessage,
|
864
|
+
PrTitle = TestPullRequestTitle,
|
865
|
+
PrBody = TestPullRequestBody,
|
860
866
|
},
|
861
867
|
new MarkAsProcessed("TEST-COMMIT-SHA")
|
862
868
|
]
|
@@ -1414,9 +1420,9 @@ public class RunWorkerTests
|
|
1414
1420
|
},
|
1415
1421
|
],
|
1416
1422
|
BaseCommitSha = "TEST-COMMIT-SHA",
|
1417
|
-
CommitMessage =
|
1418
|
-
PrTitle =
|
1419
|
-
PrBody =
|
1423
|
+
CommitMessage = TestPullRequestCommitMessage,
|
1424
|
+
PrTitle = TestPullRequestTitle,
|
1425
|
+
PrBody = TestPullRequestBody,
|
1420
1426
|
},
|
1421
1427
|
new MarkAsProcessed("TEST-COMMIT-SHA")
|
1422
1428
|
]
|
@@ -1722,9 +1728,9 @@ public class RunWorkerTests
|
|
1722
1728
|
}
|
1723
1729
|
],
|
1724
1730
|
BaseCommitSha = "TEST-COMMIT-SHA",
|
1725
|
-
CommitMessage =
|
1726
|
-
PrTitle =
|
1727
|
-
PrBody =
|
1731
|
+
CommitMessage = TestPullRequestCommitMessage,
|
1732
|
+
PrTitle = TestPullRequestTitle,
|
1733
|
+
PrBody = TestPullRequestBody,
|
1728
1734
|
},
|
1729
1735
|
new MarkAsProcessed("TEST-COMMIT-SHA")
|
1730
1736
|
]
|
@@ -2063,9 +2069,9 @@ public class RunWorkerTests
|
|
2063
2069
|
}
|
2064
2070
|
],
|
2065
2071
|
BaseCommitSha = "TEST-COMMIT-SHA",
|
2066
|
-
CommitMessage =
|
2067
|
-
PrTitle =
|
2068
|
-
PrBody =
|
2072
|
+
CommitMessage = TestPullRequestCommitMessage,
|
2073
|
+
PrTitle = TestPullRequestTitle,
|
2074
|
+
PrBody = TestPullRequestBody
|
2069
2075
|
},
|
2070
2076
|
new MarkAsProcessed("TEST-COMMIT-SHA")
|
2071
2077
|
]
|
@@ -2448,15 +2454,123 @@ public class RunWorkerTests
|
|
2448
2454
|
},
|
2449
2455
|
],
|
2450
2456
|
BaseCommitSha = "TEST-COMMIT-SHA",
|
2451
|
-
CommitMessage =
|
2452
|
-
PrTitle =
|
2453
|
-
PrBody =
|
2457
|
+
CommitMessage = TestPullRequestCommitMessage,
|
2458
|
+
PrTitle = TestPullRequestTitle,
|
2459
|
+
PrBody = TestPullRequestBody,
|
2454
2460
|
},
|
2455
2461
|
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
2456
2462
|
]
|
2457
2463
|
);
|
2458
2464
|
}
|
2459
2465
|
|
2466
|
+
[Fact]
|
2467
|
+
public async Task PullRequestAlreadyExistsForLatestVersion()
|
2468
|
+
{
|
2469
|
+
await RunAsync(
|
2470
|
+
job: new()
|
2471
|
+
{
|
2472
|
+
Source = new()
|
2473
|
+
{
|
2474
|
+
Provider = "github",
|
2475
|
+
Repo = "test/repo",
|
2476
|
+
},
|
2477
|
+
Dependencies = [
|
2478
|
+
"Some.Package"
|
2479
|
+
],
|
2480
|
+
ExistingPullRequests = [
|
2481
|
+
new PullRequest()
|
2482
|
+
{
|
2483
|
+
Dependencies = [new() { DependencyName = "Some.Package", DependencyVersion = NuGetVersion.Parse("1.2.0") }]
|
2484
|
+
}
|
2485
|
+
],
|
2486
|
+
SecurityAdvisories = [
|
2487
|
+
new Advisory() { DependencyName = "Some.Package", AffectedVersions = [Requirement.Parse("= 1.1.0")] }
|
2488
|
+
],
|
2489
|
+
SecurityUpdatesOnly = true,
|
2490
|
+
UpdatingAPullRequest = false
|
2491
|
+
},
|
2492
|
+
files: [
|
2493
|
+
("project.csproj", "contents irrelevant")
|
2494
|
+
],
|
2495
|
+
discoveryWorker: new TestDiscoveryWorker(_input =>
|
2496
|
+
{
|
2497
|
+
return Task.FromResult(new WorkspaceDiscoveryResult()
|
2498
|
+
{
|
2499
|
+
Path = "",
|
2500
|
+
Projects = [
|
2501
|
+
new()
|
2502
|
+
{
|
2503
|
+
FilePath = "project.csproj",
|
2504
|
+
Dependencies = [
|
2505
|
+
new("Some.Package", "1.1.0", DependencyType.PackageReference)
|
2506
|
+
],
|
2507
|
+
ImportedFiles = [],
|
2508
|
+
AdditionalFiles = [],
|
2509
|
+
}
|
2510
|
+
]
|
2511
|
+
});
|
2512
|
+
}),
|
2513
|
+
analyzeWorker: new TestAnalyzeWorker(_input =>
|
2514
|
+
{
|
2515
|
+
return Task.FromResult(new AnalysisResult()
|
2516
|
+
{
|
2517
|
+
CanUpdate = true,
|
2518
|
+
UpdatedVersion = "1.2.0",
|
2519
|
+
UpdatedDependencies = [
|
2520
|
+
new("Some.Package", "1.2.0", DependencyType.PackageReference)
|
2521
|
+
]
|
2522
|
+
});
|
2523
|
+
}),
|
2524
|
+
updaterWorker: new TestUpdaterWorker(input =>
|
2525
|
+
{
|
2526
|
+
throw new NotImplementedException("test should never get here");
|
2527
|
+
}),
|
2528
|
+
expectedResult: new()
|
2529
|
+
{
|
2530
|
+
Base64DependencyFiles = [
|
2531
|
+
new()
|
2532
|
+
{
|
2533
|
+
Directory = "/",
|
2534
|
+
Name = "project.csproj",
|
2535
|
+
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("contents irrelevant"))
|
2536
|
+
}
|
2537
|
+
],
|
2538
|
+
BaseCommitSha = "TEST-COMMIT-SHA",
|
2539
|
+
},
|
2540
|
+
expectedApiMessages: [
|
2541
|
+
new UpdatedDependencyList()
|
2542
|
+
{
|
2543
|
+
Dependencies = [
|
2544
|
+
new()
|
2545
|
+
{
|
2546
|
+
Name = "Some.Package",
|
2547
|
+
Version = "1.1.0",
|
2548
|
+
Requirements = [
|
2549
|
+
new()
|
2550
|
+
{
|
2551
|
+
Requirement = "1.1.0",
|
2552
|
+
File = "/project.csproj",
|
2553
|
+
Groups = ["dependencies"],
|
2554
|
+
}
|
2555
|
+
]
|
2556
|
+
}
|
2557
|
+
],
|
2558
|
+
DependencyFiles = ["/project.csproj"]
|
2559
|
+
},
|
2560
|
+
new IncrementMetric()
|
2561
|
+
{
|
2562
|
+
Metric = "updater.started",
|
2563
|
+
Tags = new()
|
2564
|
+
{
|
2565
|
+
["operation"] = "create_security_pr"
|
2566
|
+
}
|
2567
|
+
},
|
2568
|
+
new PullRequestExistsForLatestVersion("Some.Package", "1.2.0"),
|
2569
|
+
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
2570
|
+
]
|
2571
|
+
);
|
2572
|
+
}
|
2573
|
+
|
2460
2574
|
private static async Task RunAsync(Job job, TestFile[] files, IDiscoveryWorker? discoveryWorker, IAnalyzeWorker? analyzeWorker, IUpdaterWorker? updaterWorker, RunResult expectedResult, object[] expectedApiMessages, MockNuGetPackage[]? packages = null, ExperimentsManager? experimentsManager = null, string? repoContentsPath = null)
|
2461
2575
|
{
|
2462
2576
|
// arrange
|
@@ -2483,7 +2597,16 @@ public class RunWorkerTests
|
|
2483
2597
|
var worker = new RunWorker(jobId, testApiHandler, discoveryWorker, analyzeWorker, updaterWorker, logger);
|
2484
2598
|
var repoContentsPathDirectoryInfo = new DirectoryInfo(tempDirectory.DirectoryPath);
|
2485
2599
|
var actualResult = await worker.RunAsync(job, repoContentsPathDirectoryInfo, "TEST-COMMIT-SHA");
|
2486
|
-
var actualApiMessages = testApiHandler.ReceivedMessages
|
2600
|
+
var actualApiMessages = testApiHandler.ReceivedMessages
|
2601
|
+
.Select(m =>
|
2602
|
+
m.Object switch
|
2603
|
+
{
|
2604
|
+
// this isn't the place to verify the generated text
|
2605
|
+
CreatePullRequest create => (m.Type, create with { CommitMessage = TestPullRequestCommitMessage, PrTitle = TestPullRequestTitle, PrBody = TestPullRequestBody }),
|
2606
|
+
UpdatePullRequest update => (m.Type, update with { CommitMessage = TestPullRequestCommitMessage, PrTitle = TestPullRequestTitle, PrBody = TestPullRequestBody }),
|
2607
|
+
_ => m,
|
2608
|
+
}
|
2609
|
+
).ToArray();
|
2487
2610
|
|
2488
2611
|
// assert
|
2489
2612
|
var actualRunResultJson = JsonSerializer.Serialize(actualResult);
|
@@ -417,11 +417,11 @@ public class SerializationTests
|
|
417
417
|
""";
|
418
418
|
var jobWrapper = RunWorker.Deserialize(jsonWrapperJson)!;
|
419
419
|
Assert.Single(jobWrapper.Job.ExistingPullRequests);
|
420
|
-
Assert.Single(jobWrapper.Job.ExistingPullRequests[0]);
|
421
|
-
Assert.Equal("Some.Package", jobWrapper.Job.ExistingPullRequests[0][0].DependencyName);
|
422
|
-
Assert.Equal(NuGetVersion.Parse("1.2.3"), jobWrapper.Job.ExistingPullRequests[0][0].DependencyVersion);
|
423
|
-
Assert.False(jobWrapper.Job.ExistingPullRequests[0][0].DependencyRemoved);
|
424
|
-
Assert.Null(jobWrapper.Job.ExistingPullRequests[0][0].Directory);
|
420
|
+
Assert.Single(jobWrapper.Job.ExistingPullRequests[0].Dependencies);
|
421
|
+
Assert.Equal("Some.Package", jobWrapper.Job.ExistingPullRequests[0].Dependencies[0].DependencyName);
|
422
|
+
Assert.Equal(NuGetVersion.Parse("1.2.3"), jobWrapper.Job.ExistingPullRequests[0].Dependencies[0].DependencyVersion);
|
423
|
+
Assert.False(jobWrapper.Job.ExistingPullRequests[0].Dependencies[0].DependencyRemoved);
|
424
|
+
Assert.Null(jobWrapper.Job.ExistingPullRequests[0].Dependencies[0].Directory);
|
425
425
|
}
|
426
426
|
|
427
427
|
[Fact]
|
@@ -517,10 +517,15 @@ public class SerializationTests
|
|
517
517
|
Assert.Null(jobWrapper.Job.SecurityAdvisories[0].PatchedVersions);
|
518
518
|
}
|
519
519
|
|
520
|
-
[
|
521
|
-
|
520
|
+
[Theory]
|
521
|
+
[InlineData("true", true)] // bool
|
522
|
+
[InlineData("false", false)]
|
523
|
+
[InlineData("\"true\"", true)] // stringified bool
|
524
|
+
[InlineData("\"false\"", false)]
|
525
|
+
[InlineData("null", false)]
|
526
|
+
public void DeserializeCommitOptions(string includeScopeJsonValue, bool expectedIncludeScopeValue)
|
522
527
|
{
|
523
|
-
var jsonWrapperJson = """
|
528
|
+
var jsonWrapperJson = $$"""
|
524
529
|
{
|
525
530
|
"job": {
|
526
531
|
"source": {
|
@@ -530,7 +535,7 @@ public class SerializationTests
|
|
530
535
|
"commit-message-options": {
|
531
536
|
"prefix": "[SECURITY] ",
|
532
537
|
"prefix-development": null,
|
533
|
-
"include-scope":
|
538
|
+
"include-scope": {{includeScopeJsonValue}}
|
534
539
|
}
|
535
540
|
}
|
536
541
|
}
|
@@ -538,7 +543,7 @@ public class SerializationTests
|
|
538
543
|
var jobWrapper = RunWorker.Deserialize(jsonWrapperJson)!;
|
539
544
|
Assert.Equal("[SECURITY] ", jobWrapper.Job.CommitMessageOptions!.Prefix);
|
540
545
|
Assert.Null(jobWrapper.Job.CommitMessageOptions!.PrefixDevelopment);
|
541
|
-
Assert.
|
546
|
+
Assert.Equal(expectedIncludeScopeValue, jobWrapper.Job.CommitMessageOptions!.IncludeScope);
|
542
547
|
}
|
543
548
|
|
544
549
|
[Fact]
|