dependabot-nuget 0.401.0 → 0.403.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/Analyze/DependencyFinder.cs +10 -7
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/NuGetContext.cs +2 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Job.cs +7 -4
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/DetailedPullRequestBodyGenerator.cs +102 -97
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandler.cs +2 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/AnalyzeWorkerTests.cs +83 -11
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/DependencyFinderTests.cs +177 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/VersionFinderTests.cs +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/ApiModel/JobTests.cs +55 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestBodyGenerator/DetailedPullRequestBodyGeneratorTests.cs +76 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/GatedRequests.cs +62 -0
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 70b41cf5ca1d42b9d660ec764608de4bc6810788b05b0f2e9d6c03eefd90f277
|
|
4
|
+
data.tar.gz: c437530231b3a4991a98d6f9f6783b45f97e40529610676a920a19258f92ceca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3959f15dd5206ef05509dbf432ce41fdcf9a73fdb9bf49872d0f251368bb958a46a3687c18050ce1d26dc848de5b583a6d46853eb1190a3b6476ac700fa4f62c
|
|
7
|
+
data.tar.gz: f49fa46553521a7bc9635ba0df71993c4fd677f9527b3c59bf3022813dc99c4d7642515e18971c8ec9fe6842393f3eb87179ca6dcea14364c2246bf5016399a3
|
|
@@ -30,13 +30,16 @@ internal static class DependencyFinder
|
|
|
30
30
|
framework,
|
|
31
31
|
packages,
|
|
32
32
|
logger);
|
|
33
|
-
var updatedDependencies = new
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
var updatedDependencies = new Dependency[dependencies.Length];
|
|
34
|
+
await Parallel.ForEachAsync(
|
|
35
|
+
Enumerable.Range(0, dependencies.Length),
|
|
36
|
+
new ParallelOptions { MaxDegreeOfParallelism = 4, CancellationToken = cancellationToken },
|
|
37
|
+
async (index, token) =>
|
|
38
|
+
{
|
|
39
|
+
var dependency = dependencies[index];
|
|
40
|
+
var infoUrl = await nugetContext.GetPackageInfoUrlAsync(dependency.Name, dependency.Version!, token);
|
|
41
|
+
updatedDependencies[index] = dependency with { IsTopLevel = true, InfoUrl = infoUrl };
|
|
42
|
+
});
|
|
40
43
|
|
|
41
44
|
result.Add(framework, updatedDependencies.ToImmutableArray());
|
|
42
45
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
using System.Collections.Concurrent;
|
|
1
2
|
using System.Collections.Immutable;
|
|
2
3
|
using System.Text;
|
|
3
4
|
|
|
@@ -51,7 +52,7 @@ internal record NuGetContext : IDisposable
|
|
|
51
52
|
SourceCacheContext.Dispose();
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
private readonly
|
|
55
|
+
private readonly ConcurrentDictionary<PackageIdentity, string?> _packageInfoUrlCache = new();
|
|
55
56
|
|
|
56
57
|
public static string[] GetPackageSourceUrls(string currentDirectory)
|
|
57
58
|
{
|
|
@@ -143,9 +143,10 @@ public sealed record Job
|
|
|
143
143
|
|
|
144
144
|
public Tuple<string?, ImmutableArray<PullRequestDependency>>? GetExistingPullRequestForDependencies(
|
|
145
145
|
IEnumerable<ReportedDependencyWithDirectory> dependencies,
|
|
146
|
-
bool considerVersions
|
|
146
|
+
bool considerVersions,
|
|
147
|
+
bool treatEmptyDirectoryAsWildcard = false)
|
|
147
148
|
{
|
|
148
|
-
return GetExistingPullRequestForDependencies(dependencies, considerVersions, dependencyGroupName: null, matchGroupName: false);
|
|
149
|
+
return GetExistingPullRequestForDependencies(dependencies, considerVersions, dependencyGroupName: null, matchGroupName: false, treatEmptyDirectoryAsWildcard);
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
public Tuple<string?, ImmutableArray<PullRequestDependency>>? GetExistingGroupPullRequestForDependencies(
|
|
@@ -153,14 +154,15 @@ public sealed record Job
|
|
|
153
154
|
bool considerVersions,
|
|
154
155
|
string dependencyGroupName)
|
|
155
156
|
{
|
|
156
|
-
return GetExistingPullRequestForDependencies(dependencies, considerVersions, dependencyGroupName, matchGroupName: true);
|
|
157
|
+
return GetExistingPullRequestForDependencies(dependencies, considerVersions, dependencyGroupName, matchGroupName: true, treatEmptyDirectoryAsWildcard: false);
|
|
157
158
|
}
|
|
158
159
|
|
|
159
160
|
private Tuple<string?, ImmutableArray<PullRequestDependency>>? GetExistingPullRequestForDependencies(
|
|
160
161
|
IEnumerable<ReportedDependencyWithDirectory> dependencies,
|
|
161
162
|
bool considerVersions,
|
|
162
163
|
string? dependencyGroupName,
|
|
163
|
-
bool matchGroupName
|
|
164
|
+
bool matchGroupName,
|
|
165
|
+
bool treatEmptyDirectoryAsWildcard)
|
|
164
166
|
{
|
|
165
167
|
var desiredDependencies = dependencies.ToArray();
|
|
166
168
|
if (desiredDependencies.Any(d => d.Version is null))
|
|
@@ -179,6 +181,7 @@ public sealed record Job
|
|
|
179
181
|
{
|
|
180
182
|
return NamesAndVersionsMatch(desiredDependency, existingDependency) &&
|
|
181
183
|
(existingDependency.Directory is null ||
|
|
184
|
+
(treatEmptyDirectoryAsWildcard && existingDependency.Directory.Length == 0) ||
|
|
182
185
|
desiredDependency.Directory.Equals(existingDependency.Directory, StringComparison.Ordinal));
|
|
183
186
|
}
|
|
184
187
|
|
|
@@ -27,135 +27,140 @@ internal class DetailedPullRequestBodyGenerator : IPullRequestBodyGenerator, IDi
|
|
|
27
27
|
|
|
28
28
|
public async Task<string> GeneratePullRequestBodyTextAsync(Job job, ImmutableArray<UpdateOperationBase> updateOperationsPerformed, ImmutableArray<ReportedDependency> updatedDependencies)
|
|
29
29
|
{
|
|
30
|
-
var sb = new StringBuilder();
|
|
31
30
|
var dedupedUpdateOperations = updateOperationsPerformed
|
|
32
31
|
.DistinctBy(u => $"{u.DependencyName}/{u.OldVersion}/{u.NewVersion}", StringComparer.OrdinalIgnoreCase)
|
|
33
32
|
.OrderBy(u => u.DependencyName, StringComparer.OrdinalIgnoreCase)
|
|
34
33
|
.ThenBy(u => u.OldVersion, NullableNuGetVersionComparer.Instance)
|
|
35
34
|
.ThenBy(u => u.NewVersion)
|
|
36
35
|
.ToImmutableArray();
|
|
37
|
-
|
|
36
|
+
var sections = new string[dedupedUpdateOperations.Length];
|
|
37
|
+
await Parallel.ForEachAsync(
|
|
38
|
+
Enumerable.Range(0, dedupedUpdateOperations.Length),
|
|
39
|
+
new ParallelOptions { MaxDegreeOfParallelism = 4 },
|
|
40
|
+
async (index, _) =>
|
|
41
|
+
{
|
|
42
|
+
sections[index] = await GenerateUpdateSectionAsync(job, dedupedUpdateOperations[index], updatedDependencies);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
var prBody = string.Join(Environment.NewLine, sections).Replace("\r", "").TrimEnd();
|
|
46
|
+
var scrubbedBody = ScrubLinksAndMentions(prBody);
|
|
47
|
+
var truncatedPrBody = TruncateCharacterCount(scrubbedBody, GetMaxPrLength(job.Source.Provider));
|
|
48
|
+
return truncatedPrBody;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private async Task<string> GenerateUpdateSectionAsync(Job job, UpdateOperationBase updateOperation, ImmutableArray<ReportedDependency> updatedDependencies)
|
|
52
|
+
{
|
|
53
|
+
var sb = new StringBuilder();
|
|
54
|
+
var reportText = $"{updateOperation.GetReport(includeFileNames: false)}.";
|
|
55
|
+
var updatedDependency = updatedDependencies
|
|
56
|
+
.Where(d => d.Name.Equals(updateOperation.DependencyName, StringComparison.OrdinalIgnoreCase))
|
|
57
|
+
.Where(d => NuGetVersion.TryParse(d.Version, out var version) && version == updateOperation.NewVersion)
|
|
58
|
+
.FirstOrDefault();
|
|
59
|
+
var sourceUrl = (updatedDependency?.Requirements ?? [])
|
|
60
|
+
.Select(r => r.Source?.SourceUrl)
|
|
61
|
+
.FirstOrDefault(u => u is not null);
|
|
62
|
+
if (sourceUrl is null)
|
|
38
63
|
{
|
|
39
|
-
|
|
64
|
+
// no source url, just append the report text
|
|
65
|
+
sb.AppendLine(reportText);
|
|
66
|
+
}
|
|
67
|
+
else
|
|
68
|
+
{
|
|
69
|
+
if (sourceUrl.EndsWith(".git"))
|
|
40
70
|
{
|
|
41
|
-
//
|
|
42
|
-
|
|
71
|
+
// remove the trailing .git if present
|
|
72
|
+
sourceUrl = sourceUrl[..^4];
|
|
43
73
|
}
|
|
44
74
|
|
|
45
|
-
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
.Where(d => NuGetVersion.TryParse(d.Version, out var version) && version == updateOperation.NewVersion)
|
|
49
|
-
.FirstOrDefault();
|
|
50
|
-
var sourceUrl = (updatedDependency?.Requirements ?? [])
|
|
51
|
-
.Select(r => r.Source?.SourceUrl)
|
|
52
|
-
.FirstOrDefault(u => u is not null);
|
|
53
|
-
if (sourceUrl is null)
|
|
75
|
+
// build detailed report
|
|
76
|
+
var packageNameIndex = reportText.IndexOf(updateOperation.DependencyName, StringComparison.OrdinalIgnoreCase);
|
|
77
|
+
if (packageNameIndex >= 0)
|
|
54
78
|
{
|
|
55
|
-
//
|
|
56
|
-
sb.AppendLine(reportText);
|
|
79
|
+
// link the package name
|
|
80
|
+
sb.AppendLine($"{reportText[..packageNameIndex]}[{updateOperation.DependencyName}]({sourceUrl}){reportText[(packageNameIndex + updateOperation.DependencyName.Length)..]}");
|
|
57
81
|
}
|
|
58
82
|
else
|
|
59
83
|
{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// remove the trailing .git if present
|
|
63
|
-
sourceUrl = sourceUrl[..^4];
|
|
64
|
-
}
|
|
84
|
+
sb.AppendLine(reportText);
|
|
85
|
+
}
|
|
65
86
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
87
|
+
// more details
|
|
88
|
+
if (Uri.TryCreate(sourceUrl, UriKind.Absolute, out var uri))
|
|
89
|
+
{
|
|
90
|
+
IPackageDetailFinder? packageDetailFinder = uri.Host.ToLowerInvariant() switch
|
|
69
91
|
{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
92
|
+
"dev.azure.com" => new AzurePackageDetailFinder(),
|
|
93
|
+
"github.com" => new GitHubPackageDetailFinder(_httpFetcher),
|
|
94
|
+
"gitlab.com" => new GitLabPackageDetailFinder(_httpFetcher),
|
|
95
|
+
var host when host.EndsWith(".visualstudio.com") => new AzurePackageDetailFinder(),
|
|
96
|
+
_ => null,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
if (packageDetailFinder is not null &&
|
|
100
|
+
updateOperation.OldVersion is not null)
|
|
74
101
|
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (packageDetailFinder is not null &&
|
|
91
|
-
updateOperation.OldVersion is not null)
|
|
102
|
+
var repoName = uri.LocalPath.TrimStart('/');
|
|
103
|
+
var versionsAndDetails = await packageDetailFinder.GetReleaseDataForVersionsAsync(repoName, updateOperation.DependencyName, updateOperation.OldVersion, updateOperation.NewVersion);
|
|
104
|
+
var ordered = versionsAndDetails
|
|
105
|
+
.Where(kv => kv.Key != updateOperation.OldVersion)
|
|
106
|
+
.OrderByDescending(kv => kv.Key)
|
|
107
|
+
.ToList();
|
|
108
|
+
|
|
109
|
+
sb.AppendLine();
|
|
110
|
+
var detailsLineTemplate = IsHtmlSupported(job.Source.Provider)
|
|
111
|
+
? "<details>\n<summary>{0}</summary>"
|
|
112
|
+
: "# {0}";
|
|
113
|
+
sb.AppendLine(string.Format(detailsLineTemplate, "Release notes"));
|
|
114
|
+
|
|
115
|
+
var releasesUrlPath = packageDetailFinder.GetReleasesUrlPath();
|
|
116
|
+
if (releasesUrlPath is not null)
|
|
92
117
|
{
|
|
93
|
-
var repoName = uri.LocalPath.TrimStart('/');
|
|
94
|
-
var versionsAndDetails = await packageDetailFinder.GetReleaseDataForVersionsAsync(repoName, updateOperation.DependencyName, updateOperation.OldVersion, updateOperation.NewVersion);
|
|
95
|
-
var ordered = versionsAndDetails
|
|
96
|
-
.Where(kv => kv.Key != updateOperation.OldVersion)
|
|
97
|
-
.OrderByDescending(kv => kv.Key)
|
|
98
|
-
.ToList();
|
|
99
|
-
|
|
100
118
|
sb.AppendLine();
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
: "# {0}";
|
|
104
|
-
sb.AppendLine(string.Format(detailsLineTemplate, "Release notes"));
|
|
105
|
-
|
|
106
|
-
var releasesUrlPath = packageDetailFinder.GetReleasesUrlPath();
|
|
107
|
-
if (releasesUrlPath is not null)
|
|
108
|
-
{
|
|
109
|
-
sb.AppendLine();
|
|
110
|
-
sb.AppendLine($"_Sourced from [{updateOperation.DependencyName}'s releases]({sourceUrl}/{releasesUrlPath})._");
|
|
111
|
-
}
|
|
119
|
+
sb.AppendLine($"_Sourced from [{updateOperation.DependencyName}'s releases]({sourceUrl}/{releasesUrlPath})._");
|
|
120
|
+
}
|
|
112
121
|
|
|
113
|
-
|
|
122
|
+
foreach (var (version, (tagName, body)) in ordered)
|
|
123
|
+
{
|
|
124
|
+
sb.AppendLine();
|
|
125
|
+
sb.AppendLine($"## {version}");
|
|
126
|
+
if (body is not null)
|
|
114
127
|
{
|
|
128
|
+
var truncatedBody = TruncateLineCount(body);
|
|
115
129
|
sb.AppendLine();
|
|
116
|
-
sb.AppendLine(
|
|
117
|
-
if (body is not null)
|
|
118
|
-
{
|
|
119
|
-
var truncatedBody = TruncateLineCount(body);
|
|
120
|
-
sb.AppendLine();
|
|
121
|
-
sb.AppendLine(truncatedBody);
|
|
122
|
-
}
|
|
130
|
+
sb.AppendLine(truncatedBody);
|
|
123
131
|
}
|
|
132
|
+
}
|
|
124
133
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
134
|
+
if (ordered.Count == 0)
|
|
135
|
+
{
|
|
136
|
+
sb.AppendLine();
|
|
137
|
+
sb.AppendLine("No release notes found for this version range.");
|
|
138
|
+
}
|
|
130
139
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
140
|
+
string? oldTag = null;
|
|
141
|
+
if (versionsAndDetails.TryGetValue(updateOperation.OldVersion, out var oldVersionDetails))
|
|
142
|
+
{
|
|
143
|
+
oldTag = oldVersionDetails.TagName;
|
|
144
|
+
}
|
|
136
145
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
146
|
+
string? newTag = null;
|
|
147
|
+
if (versionsAndDetails.TryGetValue(updateOperation.NewVersion, out var newVersionDetails))
|
|
148
|
+
{
|
|
149
|
+
newTag = newVersionDetails.TagName;
|
|
150
|
+
}
|
|
142
151
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
152
|
+
var compareUrlPath = packageDetailFinder.GetCompareUrlPath(oldTag, newTag);
|
|
153
|
+
sb.AppendLine();
|
|
154
|
+
sb.AppendLine($"Commits viewable in [compare view]({sourceUrl}/{compareUrlPath}).");
|
|
155
|
+
if (IsHtmlSupported(job.Source.Provider))
|
|
156
|
+
{
|
|
157
|
+
sb.AppendLine("</details>");
|
|
150
158
|
}
|
|
151
159
|
}
|
|
152
160
|
}
|
|
153
161
|
}
|
|
154
162
|
|
|
155
|
-
|
|
156
|
-
var scrubbedBody = ScrubLinksAndMentions(prBody);
|
|
157
|
-
var truncatedPrBody = TruncateCharacterCount(scrubbedBody, GetMaxPrLength(job.Source.Provider));
|
|
158
|
-
return truncatedPrBody;
|
|
163
|
+
return sb.ToString();
|
|
159
164
|
}
|
|
160
165
|
|
|
161
166
|
private static bool IsHtmlSupported(string sourceProvider)
|
|
@@ -155,7 +155,7 @@ internal class RefreshVersionUpdatePullRequestHandler : IUpdateHandler
|
|
|
155
155
|
var prBody = await PullRequestTextGenerator.GetPullRequestBodyAsync(job, [.. updateOperationsPerformed], [.. updatedDependencies], experimentsManager);
|
|
156
156
|
|
|
157
157
|
var reportedDependencies = updatedDependencies.Select(d => ReportedDependencyWithDirectory.From(d, directory)).ToArray();
|
|
158
|
-
var existingPullRequest = job.GetExistingPullRequestForDependencies(reportedDependencies, considerVersions: true);
|
|
158
|
+
var existingPullRequest = job.GetExistingPullRequestForDependencies(reportedDependencies, considerVersions: true, treatEmptyDirectoryAsWildcard: true);
|
|
159
159
|
if (existingPullRequest is not null)
|
|
160
160
|
{
|
|
161
161
|
await apiHandler.UpdatePullRequest(new UpdatePullRequest()
|
|
@@ -172,7 +172,7 @@ internal class RefreshVersionUpdatePullRequestHandler : IUpdateHandler
|
|
|
172
172
|
}
|
|
173
173
|
else
|
|
174
174
|
{
|
|
175
|
-
var existingPrButDifferent = job.GetExistingPullRequestForDependencies(reportedDependencies, considerVersions: false);
|
|
175
|
+
var existingPrButDifferent = job.GetExistingPullRequestForDependencies(reportedDependencies, considerVersions: false, treatEmptyDirectoryAsWildcard: true);
|
|
176
176
|
if (existingPrButDifferent is not null)
|
|
177
177
|
{
|
|
178
178
|
await apiHandler.ClosePullRequest(ClosePullRequest.WithDependenciesChanged(job));
|
|
@@ -2187,7 +2187,71 @@ public partial class AnalyzeWorkerTests : AnalyzeWorkerTestBase
|
|
|
2187
2187
|
Assert.Equal(expectedUrl.ToString(), infoUrl);
|
|
2188
2188
|
}
|
|
2189
2189
|
|
|
2190
|
-
|
|
2190
|
+
[Theory]
|
|
2191
|
+
[InlineData(true)]
|
|
2192
|
+
[InlineData(false)]
|
|
2193
|
+
public async Task CompletedPackageInfoLookupsAreCached(bool hasUrl)
|
|
2194
|
+
{
|
|
2195
|
+
var requestCount = 0;
|
|
2196
|
+
var expectedUrl = hasUrl ? new Uri("https://example.com/package") : null;
|
|
2197
|
+
using var context = await CreateNuGetContextAsync(null, expectedUrl, (_, _) =>
|
|
2198
|
+
{
|
|
2199
|
+
requestCount++;
|
|
2200
|
+
return Task.CompletedTask;
|
|
2201
|
+
});
|
|
2202
|
+
|
|
2203
|
+
var first = await context.GetPackageInfoUrlAsync("Some.Package", "1.0.0", TestContext.Current.CancellationToken);
|
|
2204
|
+
var second = await context.GetPackageInfoUrlAsync("some.package", "1.0.0", TestContext.Current.CancellationToken);
|
|
2205
|
+
|
|
2206
|
+
Assert.Equal(expectedUrl?.ToString(), first);
|
|
2207
|
+
Assert.Equal(first, second);
|
|
2208
|
+
Assert.Equal(1, requestCount);
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
[Theory]
|
|
2212
|
+
[InlineData(true)]
|
|
2213
|
+
[InlineData(false)]
|
|
2214
|
+
public async Task FailedPackageInfoLookupsAreRetried(bool cancel)
|
|
2215
|
+
{
|
|
2216
|
+
var requestCount = 0;
|
|
2217
|
+
using var cancellationSource = CancellationTokenSource.CreateLinkedTokenSource(TestContext.Current.CancellationToken);
|
|
2218
|
+
var expectedUrl = new Uri("https://example.com/package");
|
|
2219
|
+
using var context = await CreateNuGetContextAsync(null, expectedUrl, (_, token) =>
|
|
2220
|
+
{
|
|
2221
|
+
if (++requestCount == 1)
|
|
2222
|
+
{
|
|
2223
|
+
if (cancel)
|
|
2224
|
+
{
|
|
2225
|
+
cancellationSource.Cancel();
|
|
2226
|
+
token.ThrowIfCancellationRequested();
|
|
2227
|
+
}
|
|
2228
|
+
|
|
2229
|
+
throw new HttpRequestException("Package metadata is unavailable.");
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
return Task.CompletedTask;
|
|
2233
|
+
});
|
|
2234
|
+
var first = context.GetPackageInfoUrlAsync("Some.Package", "1.0.0", cancellationSource.Token);
|
|
2235
|
+
if (cancel)
|
|
2236
|
+
{
|
|
2237
|
+
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => first);
|
|
2238
|
+
}
|
|
2239
|
+
else
|
|
2240
|
+
{
|
|
2241
|
+
await Assert.ThrowsAsync<HttpRequestException>(() => first);
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
var second = await context.GetPackageInfoUrlAsync("Some.Package", "1.0.0", TestContext.Current.CancellationToken);
|
|
2245
|
+
var third = await context.GetPackageInfoUrlAsync("Some.Package", "1.0.0", TestContext.Current.CancellationToken);
|
|
2246
|
+
Assert.Equal(expectedUrl.ToString(), second);
|
|
2247
|
+
Assert.Equal(second, third);
|
|
2248
|
+
Assert.Equal(2, requestCount);
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
private static async Task<NuGetContext> CreateNuGetContextAsync(
|
|
2252
|
+
DownloadResource? downloadResource,
|
|
2253
|
+
Uri? projectUrl,
|
|
2254
|
+
Func<PackageIdentity, CancellationToken, Task>? beforeGetMetadata = null)
|
|
2191
2255
|
{
|
|
2192
2256
|
using var tempDir = await TemporaryDirectory.CreateWithContentsAsync(
|
|
2193
2257
|
("NuGet.Config", """
|
|
@@ -2207,7 +2271,7 @@ public partial class AnalyzeWorkerTests : AnalyzeWorkerTestBase
|
|
|
2207
2271
|
[
|
|
2208
2272
|
new TestResourceProvider<MetadataResource>(new TestMetadataResource()),
|
|
2209
2273
|
new TestResourceProvider<DownloadResource>(downloadResource),
|
|
2210
|
-
new TestResourceProvider<PackageMetadataResource>(new TestPackageMetadataResource(projectUrl)),
|
|
2274
|
+
new TestResourceProvider<PackageMetadataResource>(new TestPackageMetadataResource(projectUrl, beforeGetMetadata)),
|
|
2211
2275
|
]));
|
|
2212
2276
|
}
|
|
2213
2277
|
|
|
@@ -2267,7 +2331,9 @@ public partial class AnalyzeWorkerTests : AnalyzeWorkerTestBase
|
|
|
2267
2331
|
CancellationToken token) => Task.FromResult(result);
|
|
2268
2332
|
}
|
|
2269
2333
|
|
|
2270
|
-
private sealed class TestPackageMetadataResource(
|
|
2334
|
+
private sealed class TestPackageMetadataResource(
|
|
2335
|
+
Uri? projectUrl,
|
|
2336
|
+
Func<PackageIdentity, CancellationToken, Task>? beforeGetMetadata = null) : PackageMetadataResource
|
|
2271
2337
|
{
|
|
2272
2338
|
public override Task<IEnumerable<IPackageSearchMetadata>> GetMetadataAsync(
|
|
2273
2339
|
string packageId,
|
|
@@ -2277,17 +2343,23 @@ public partial class AnalyzeWorkerTests : AnalyzeWorkerTestBase
|
|
|
2277
2343
|
NuGet.Common.ILogger log,
|
|
2278
2344
|
CancellationToken token) => Task.FromResult<IEnumerable<IPackageSearchMetadata>>([]);
|
|
2279
2345
|
|
|
2280
|
-
public override Task<IPackageSearchMetadata> GetMetadataAsync(
|
|
2346
|
+
public override async Task<IPackageSearchMetadata> GetMetadataAsync(
|
|
2281
2347
|
PackageIdentity package,
|
|
2282
2348
|
SourceCacheContext sourceCacheContext,
|
|
2283
2349
|
NuGet.Common.ILogger log,
|
|
2284
|
-
CancellationToken token)
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2350
|
+
CancellationToken token)
|
|
2351
|
+
{
|
|
2352
|
+
if (beforeGetMetadata is not null)
|
|
2353
|
+
{
|
|
2354
|
+
await beforeGetMetadata(package, token);
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
return new PackageSearchMetadataBuilder.ClonedPackageSearchMetadata
|
|
2358
|
+
{
|
|
2359
|
+
Identity = package,
|
|
2360
|
+
ProjectUrl = projectUrl,
|
|
2361
|
+
};
|
|
2362
|
+
}
|
|
2291
2363
|
}
|
|
2292
2364
|
|
|
2293
2365
|
private sealed class SelectivePackageMetadataResource(NuGetVersion failingVersion) : PackageMetadataResource
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
using System.Collections.Immutable;
|
|
2
|
+
|
|
3
|
+
using NuGet.Packaging.Core;
|
|
4
|
+
using NuGet.Protocol;
|
|
5
|
+
using NuGet.Protocol.Core.Types;
|
|
6
|
+
using NuGet.Versioning;
|
|
7
|
+
|
|
8
|
+
using NuGetUpdater.Core.Analyze;
|
|
9
|
+
using NuGetUpdater.Core.Test.Update;
|
|
10
|
+
using NuGetUpdater.Core.Test.Utilities;
|
|
11
|
+
|
|
12
|
+
using Xunit;
|
|
13
|
+
|
|
14
|
+
namespace NuGetUpdater.Core.Test.Analyze;
|
|
15
|
+
|
|
16
|
+
public class DependencyFinderTests : TestBase
|
|
17
|
+
{
|
|
18
|
+
private static readonly string[] PackageNames = Enumerable.Range(0, 8).Select(i => $"Package.{i}").ToArray();
|
|
19
|
+
|
|
20
|
+
[Fact]
|
|
21
|
+
public async Task EnrichesDependenciesConcurrentlyInOrderAndReusesCachedResultsAcrossFrameworks()
|
|
22
|
+
{
|
|
23
|
+
var cancellationToken = TestContext.Current.CancellationToken;
|
|
24
|
+
using var directory = await CreateProjectAsync();
|
|
25
|
+
var responses = new GatedRequests<IPackageSearchMetadata>(PackageNames);
|
|
26
|
+
using var context = CreateContext(directory.DirectoryPath, responses);
|
|
27
|
+
var dependenciesTask = FindDependenciesAsync(directory.DirectoryPath, context, ["net8.0", "net9.0"], cancellationToken);
|
|
28
|
+
try
|
|
29
|
+
{
|
|
30
|
+
for (var batch = 0; batch < 2; batch++)
|
|
31
|
+
{
|
|
32
|
+
var requests = await responses.ReadRequestsAsync(4, cancellationToken);
|
|
33
|
+
Assert.Equal(4, responses.PeakConcurrency);
|
|
34
|
+
foreach (var name in requests.Reverse())
|
|
35
|
+
{
|
|
36
|
+
responses.Respond(name, CreateMetadata(name));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
var dependencies = await dependenciesTask.WaitAsync(cancellationToken);
|
|
41
|
+
Assert.Equal(2, dependencies.Count);
|
|
42
|
+
foreach (var framework in new[] { "net8.0", "net9.0" })
|
|
43
|
+
{
|
|
44
|
+
Assert.Equal(PackageNames, dependencies[framework].Select(d => d.Name));
|
|
45
|
+
Assert.All(dependencies[framework], dependency =>
|
|
46
|
+
{
|
|
47
|
+
Assert.Equal("1.0.0", dependency.Version);
|
|
48
|
+
Assert.True(dependency.IsTopLevel);
|
|
49
|
+
Assert.Equal([framework], dependency.TargetFrameworks);
|
|
50
|
+
Assert.Equal(CreateMetadata(dependency.Name).ProjectUrl?.ToString(), dependency.InfoUrl);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Assert.Equal(8, responses.RequestCount);
|
|
55
|
+
Assert.Equal(0, responses.ActiveRequests);
|
|
56
|
+
}
|
|
57
|
+
finally
|
|
58
|
+
{
|
|
59
|
+
responses.RespondAll(CreateMetadata);
|
|
60
|
+
await dependenciesTask.WaitAsync(cancellationToken);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
[Theory]
|
|
65
|
+
[InlineData(true)]
|
|
66
|
+
[InlineData(false)]
|
|
67
|
+
public async Task LookupFailureOrCancellationPropagatesAfterStartedRequestsSettle(bool cancel)
|
|
68
|
+
{
|
|
69
|
+
using var cancellationSource = CancellationTokenSource.CreateLinkedTokenSource(TestContext.Current.CancellationToken);
|
|
70
|
+
using var directory = await CreateProjectAsync();
|
|
71
|
+
var responses = new GatedRequests<IPackageSearchMetadata>(PackageNames);
|
|
72
|
+
using var context = CreateContext(directory.DirectoryPath, responses);
|
|
73
|
+
var dependenciesTask = FindDependenciesAsync(directory.DirectoryPath, context, ["net8.0"], cancellationSource.Token);
|
|
74
|
+
try
|
|
75
|
+
{
|
|
76
|
+
var requests = await responses.ReadRequestsAsync(4, TestContext.Current.CancellationToken);
|
|
77
|
+
if (cancel)
|
|
78
|
+
{
|
|
79
|
+
await cancellationSource.CancelAsync();
|
|
80
|
+
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => dependenciesTask);
|
|
81
|
+
}
|
|
82
|
+
else
|
|
83
|
+
{
|
|
84
|
+
responses.Fail(requests[0], new HttpRequestException("Package metadata is unavailable."));
|
|
85
|
+
await Assert.ThrowsAsync<HttpRequestException>(() => dependenciesTask);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
Assert.Equal(0, responses.ActiveRequests);
|
|
89
|
+
Assert.Equal(4, responses.RequestCount);
|
|
90
|
+
}
|
|
91
|
+
finally
|
|
92
|
+
{
|
|
93
|
+
responses.RespondAll(CreateMetadata);
|
|
94
|
+
if (!dependenciesTask.IsCompleted)
|
|
95
|
+
{
|
|
96
|
+
await dependenciesTask.WaitAsync(TestContext.Current.CancellationToken);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private static Task<ImmutableDictionary<string, ImmutableArray<Dependency>>> FindDependenciesAsync(
|
|
102
|
+
string directory,
|
|
103
|
+
NuGetContext context,
|
|
104
|
+
string[] frameworks,
|
|
105
|
+
CancellationToken cancellationToken) =>
|
|
106
|
+
DependencyFinder.GetDependenciesAsync(
|
|
107
|
+
directory,
|
|
108
|
+
Path.Combine(directory, "project.csproj"),
|
|
109
|
+
frameworks,
|
|
110
|
+
PackageNames.ToImmutableHashSet(StringComparer.OrdinalIgnoreCase),
|
|
111
|
+
NuGetVersion.Parse("1.0.0"),
|
|
112
|
+
context,
|
|
113
|
+
new TestLogger(),
|
|
114
|
+
cancellationToken);
|
|
115
|
+
|
|
116
|
+
private static async Task<TemporaryDirectory> CreateProjectAsync()
|
|
117
|
+
{
|
|
118
|
+
var directory = await TemporaryDirectory.CreateWithContentsAsync(("project.csproj", """
|
|
119
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
|
120
|
+
<PropertyGroup><TargetFramework>net8.0</TargetFramework></PropertyGroup>
|
|
121
|
+
</Project>
|
|
122
|
+
"""));
|
|
123
|
+
var packages = PackageNames.Select(name => MockNuGetPackage.CreateSimplePackage(name, "1.0.0", "net8.0")).ToArray();
|
|
124
|
+
await UpdateWorkerTestBase.MockNuGetPackagesInDirectory(packages, directory.DirectoryPath);
|
|
125
|
+
return directory;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private static NuGetContext CreateContext(string directory, GatedRequests<IPackageSearchMetadata> responses) =>
|
|
129
|
+
new(directory, sourceRepositoryFactory: source => new SourceRepository(source,
|
|
130
|
+
[
|
|
131
|
+
new ResourceProvider<MetadataResource>(new ExistingMetadataResource()),
|
|
132
|
+
new ResourceProvider<DownloadResource>(null),
|
|
133
|
+
new ResourceProvider<PackageMetadataResource>(new GatedMetadataResource(responses)),
|
|
134
|
+
]));
|
|
135
|
+
|
|
136
|
+
private static IPackageSearchMetadata CreateMetadata(string name) =>
|
|
137
|
+
new PackageSearchMetadataBuilder.ClonedPackageSearchMetadata()
|
|
138
|
+
{
|
|
139
|
+
Identity = new PackageIdentity(name, NuGetVersion.Parse("1.0.0")),
|
|
140
|
+
ProjectUrl = name == "Package.3" ? null : new Uri($"https://example.com/{name}"),
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
private sealed class ResourceProvider<T>(T? resource) : INuGetResourceProvider where T : class, INuGetResource
|
|
144
|
+
{
|
|
145
|
+
public Type ResourceType => typeof(T);
|
|
146
|
+
public string Name => typeof(T).Name;
|
|
147
|
+
public IEnumerable<string> Before => [];
|
|
148
|
+
public IEnumerable<string> After => [];
|
|
149
|
+
|
|
150
|
+
public Task<Tuple<bool, INuGetResource?>> TryCreate(SourceRepository source, CancellationToken token) =>
|
|
151
|
+
Task.FromResult(Tuple.Create(true, (INuGetResource?)resource));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private sealed class ExistingMetadataResource : MetadataResource
|
|
155
|
+
{
|
|
156
|
+
public override Task<bool> Exists(PackageIdentity identity, bool includeUnlisted, SourceCacheContext sourceCacheContext, NuGet.Common.ILogger log, CancellationToken token) =>
|
|
157
|
+
Task.FromResult(true);
|
|
158
|
+
|
|
159
|
+
public override Task<bool> Exists(string packageId, bool includePrerelease, bool includeUnlisted, SourceCacheContext sourceCacheContext, NuGet.Common.ILogger log, CancellationToken token) =>
|
|
160
|
+
Task.FromResult(true);
|
|
161
|
+
|
|
162
|
+
public override Task<IEnumerable<NuGetVersion>> GetVersions(string packageId, bool includePrerelease, bool includeUnlisted, SourceCacheContext sourceCacheContext, NuGet.Common.ILogger log, CancellationToken token) =>
|
|
163
|
+
Task.FromResult<IEnumerable<NuGetVersion>>([]);
|
|
164
|
+
|
|
165
|
+
public override Task<IEnumerable<KeyValuePair<string, NuGetVersion>>> GetLatestVersions(IEnumerable<string> packageIds, bool includePrerelease, bool includeUnlisted, SourceCacheContext sourceCacheContext, NuGet.Common.ILogger log, CancellationToken token) =>
|
|
166
|
+
Task.FromResult<IEnumerable<KeyValuePair<string, NuGetVersion>>>([]);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private sealed class GatedMetadataResource(GatedRequests<IPackageSearchMetadata> responses) : PackageMetadataResource
|
|
170
|
+
{
|
|
171
|
+
public override Task<IEnumerable<IPackageSearchMetadata>> GetMetadataAsync(string packageId, bool includePrerelease, bool includeUnlisted, SourceCacheContext sourceCacheContext, NuGet.Common.ILogger log, CancellationToken token) =>
|
|
172
|
+
Task.FromResult<IEnumerable<IPackageSearchMetadata>>([]);
|
|
173
|
+
|
|
174
|
+
public override Task<IPackageSearchMetadata> GetMetadataAsync(PackageIdentity package, SourceCacheContext sourceCacheContext, NuGet.Common.ILogger log, CancellationToken token) =>
|
|
175
|
+
responses.GetResponseAsync(package.Id, token);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -265,7 +265,7 @@ public class VersionFinderTests : TestBase
|
|
|
265
265
|
CancellationToken.None);
|
|
266
266
|
|
|
267
267
|
// assert
|
|
268
|
-
var actual = versionResult.GetVersions().Select(v => v.ToString()).ToArray();
|
|
268
|
+
var actual = versionResult.GetVersions().Order().Select(v => v.ToString()).ToArray();
|
|
269
269
|
var expected = new[] { "2.0.0", "3.0.0" };
|
|
270
270
|
AssertEx.Equal(expected, actual);
|
|
271
271
|
}
|
|
@@ -85,6 +85,61 @@ public class JobTests
|
|
|
85
85
|
Assert.Equal(expectedMatch, pullRequest is not null);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
[Theory]
|
|
89
|
+
[InlineData(null, "/src/Project", true)]
|
|
90
|
+
[InlineData("", "/src/Project", true)]
|
|
91
|
+
[InlineData("/", "/src/Project", false)]
|
|
92
|
+
[InlineData("/src/Project", "/src/Project", true)]
|
|
93
|
+
[InlineData("/src/Other", "/src/Project", false)]
|
|
94
|
+
public void GetExistingPullRequestForDependencies_DirectoryMatching_Refresh(string? existingDirectory, string desiredDirectory, bool expectedMatch)
|
|
95
|
+
{
|
|
96
|
+
var job = new Job()
|
|
97
|
+
{
|
|
98
|
+
Source = new JobSource() { Provider = "github", Repo = "some/repo" },
|
|
99
|
+
ExistingPullRequests = [
|
|
100
|
+
new PullRequest()
|
|
101
|
+
{
|
|
102
|
+
Dependencies = [
|
|
103
|
+
new PullRequestDependency() { DependencyName = "Some.Package", DependencyVersion = NuGetVersion.Parse("1.1.0"), Directory = existingDirectory }
|
|
104
|
+
],
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
};
|
|
108
|
+
var dependencies = new[]
|
|
109
|
+
{
|
|
110
|
+
new ReportedDependencyWithDirectory() { Name = "Some.Package", Version = "1.1.0", Requirements = [], Directory = desiredDirectory },
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
var pullRequest = job.GetExistingPullRequestForDependencies(dependencies, considerVersions: true, treatEmptyDirectoryAsWildcard: true);
|
|
114
|
+
|
|
115
|
+
Assert.Equal(expectedMatch, pullRequest is not null);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
[Fact]
|
|
119
|
+
public void GetExistingPullRequestForDependencies_RootDirectoryIsLiteral()
|
|
120
|
+
{
|
|
121
|
+
var job = new Job()
|
|
122
|
+
{
|
|
123
|
+
Source = new JobSource() { Provider = "github", Repo = "some/repo" },
|
|
124
|
+
ExistingPullRequests = [
|
|
125
|
+
new PullRequest()
|
|
126
|
+
{
|
|
127
|
+
Dependencies = [
|
|
128
|
+
new PullRequestDependency() { DependencyName = "Some.Package", DependencyVersion = NuGetVersion.Parse("1.1.0"), Directory = "/" }
|
|
129
|
+
],
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
};
|
|
133
|
+
var dependencies = new[]
|
|
134
|
+
{
|
|
135
|
+
new ReportedDependencyWithDirectory() { Name = "Some.Package", Version = "1.1.0", Requirements = [], Directory = "/src/Project" },
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
var pullRequest = job.GetExistingPullRequestForDependencies(dependencies, considerVersions: true, treatEmptyDirectoryAsWildcard: true);
|
|
139
|
+
|
|
140
|
+
Assert.Null(pullRequest);
|
|
141
|
+
}
|
|
142
|
+
|
|
88
143
|
public static IEnumerable<object?[]> IsUpdatePermittedTestData()
|
|
89
144
|
{
|
|
90
145
|
// with default allowed updates on a transitive dependency
|
|
@@ -5,6 +5,7 @@ using NuGet.Versioning;
|
|
|
5
5
|
|
|
6
6
|
using NuGetUpdater.Core.Run.ApiModel;
|
|
7
7
|
using NuGetUpdater.Core.Run.PullRequestBodyGenerator;
|
|
8
|
+
using NuGetUpdater.Core.Test.Utilities;
|
|
8
9
|
using NuGetUpdater.Core.Updater;
|
|
9
10
|
|
|
10
11
|
using Xunit;
|
|
@@ -1138,6 +1139,81 @@ public class DetailedPullRequestBodyGeneratorTests
|
|
|
1138
1139
|
Assert.Contains("No release notes found for this version range.", prBody);
|
|
1139
1140
|
}
|
|
1140
1141
|
|
|
1142
|
+
[Fact]
|
|
1143
|
+
public async Task FetchesReleaseNotesConcurrentlyWithoutReorderingOrLosingFallbacks()
|
|
1144
|
+
{
|
|
1145
|
+
var cancellationToken = TestContext.Current.CancellationToken;
|
|
1146
|
+
const string releaseResponse = """[{"name":"2.0.0","tag_name":"2.0.0","body":"Release notes."},{"name":"1.0.0","tag_name":"1.0.0","body":"Initial release."}]""";
|
|
1147
|
+
var packageNames = Enumerable.Range(0, 8).Select(i => $"Package.{i}").ToArray();
|
|
1148
|
+
var responses = new GatedRequests<string?>(packageNames.Select(name => $"https://api.github.com/repos/test/{name}/releases?per_page=100"));
|
|
1149
|
+
using var generator = new DetailedPullRequestBodyGenerator(new GatedHttpFetcher(responses));
|
|
1150
|
+
var operations = packageNames.Reverse().Select(name => (UpdateOperationBase)new DirectUpdate()
|
|
1151
|
+
{
|
|
1152
|
+
DependencyName = name,
|
|
1153
|
+
OldVersion = NuGetVersion.Parse("1.0.0"),
|
|
1154
|
+
NewVersion = NuGetVersion.Parse("2.0.0"),
|
|
1155
|
+
UpdatedFiles = [],
|
|
1156
|
+
}).ToImmutableArray();
|
|
1157
|
+
var dependencies = packageNames.Select(name => new ReportedDependency()
|
|
1158
|
+
{
|
|
1159
|
+
Name = name,
|
|
1160
|
+
Version = "2.0.0",
|
|
1161
|
+
Requirements = [
|
|
1162
|
+
new() { File = "", Requirement = "2.0.0", Source = new() { SourceUrl = $"https://github.com/test/{name}" } },
|
|
1163
|
+
],
|
|
1164
|
+
}).ToImmutableArray();
|
|
1165
|
+
var job = new Job() { Source = new() { Provider = "github", Repo = "test/repo" } };
|
|
1166
|
+
var bodyTask = generator.GeneratePullRequestBodyTextAsync(job, operations, dependencies);
|
|
1167
|
+
try
|
|
1168
|
+
{
|
|
1169
|
+
for (var batch = 0; batch < 2; batch++)
|
|
1170
|
+
{
|
|
1171
|
+
var requests = await responses.ReadRequestsAsync(4, cancellationToken);
|
|
1172
|
+
Assert.Equal(4, responses.PeakConcurrency);
|
|
1173
|
+
foreach (var url in requests.Reverse())
|
|
1174
|
+
{
|
|
1175
|
+
if (url.Contains("/Package.3/"))
|
|
1176
|
+
{
|
|
1177
|
+
responses.Fail(url, new HttpRequestException("Release notes are unavailable."));
|
|
1178
|
+
}
|
|
1179
|
+
else
|
|
1180
|
+
{
|
|
1181
|
+
responses.Respond(url, releaseResponse);
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
var body = await bodyTask.WaitAsync(cancellationToken);
|
|
1187
|
+
var expectedSections = packageNames.Select(name => $"""
|
|
1188
|
+
Updated [{name}](https://github.com/test/{name}) from 1.0.0 to 2.0.0.
|
|
1189
|
+
|
|
1190
|
+
<details>
|
|
1191
|
+
<summary>Release notes</summary>
|
|
1192
|
+
|
|
1193
|
+
_Sourced from [{name}'s releases](https://github.com/test/{name}/releases)._
|
|
1194
|
+
|
|
1195
|
+
{(name == "Package.3" ? "No release notes found for this version range." : "## 2.0.0\n\nRelease notes.")}
|
|
1196
|
+
|
|
1197
|
+
Commits viewable in [compare view](https://github.com/test/{name}/{(name == "Package.3" ? "commits" : "compare/1.0.0...2.0.0")}).
|
|
1198
|
+
</details>
|
|
1199
|
+
""");
|
|
1200
|
+
Assert.Equal(string.Join("\n\n", expectedSections), body);
|
|
1201
|
+
Assert.Equal(8, responses.RequestCount);
|
|
1202
|
+
Assert.Equal(0, responses.ActiveRequests);
|
|
1203
|
+
}
|
|
1204
|
+
finally
|
|
1205
|
+
{
|
|
1206
|
+
responses.RespondAll(_ => releaseResponse);
|
|
1207
|
+
await bodyTask.WaitAsync(cancellationToken);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
private sealed class GatedHttpFetcher(GatedRequests<string?> responses) : IHttpFetcher
|
|
1212
|
+
{
|
|
1213
|
+
public Task<string?> GetStringAsync(string url) => responses.GetResponseAsync(url);
|
|
1214
|
+
public void Dispose() { }
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1141
1217
|
private static async Task TestAsync(
|
|
1142
1218
|
ImmutableArray<UpdateOperationBase> updateOperationsPerformed,
|
|
1143
1219
|
ImmutableArray<ReportedDependency> updatedDependencies,
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
using System.Threading.Channels;
|
|
2
|
+
|
|
3
|
+
namespace NuGetUpdater.Core.Test.Utilities;
|
|
4
|
+
|
|
5
|
+
internal sealed class GatedRequests<T>(IEnumerable<string> keys)
|
|
6
|
+
{
|
|
7
|
+
private readonly Dictionary<string, TaskCompletionSource<T>> _responses = keys.ToDictionary(
|
|
8
|
+
key => key,
|
|
9
|
+
_ => new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously));
|
|
10
|
+
private readonly Channel<string> _requests = Channel.CreateUnbounded<string>();
|
|
11
|
+
private readonly object _gate = new();
|
|
12
|
+
private int _activeRequests;
|
|
13
|
+
|
|
14
|
+
public int PeakConcurrency { get; private set; }
|
|
15
|
+
public int RequestCount { get; private set; }
|
|
16
|
+
public int ActiveRequests => Volatile.Read(ref _activeRequests);
|
|
17
|
+
|
|
18
|
+
public async Task<T> GetResponseAsync(string key, CancellationToken cancellationToken = default)
|
|
19
|
+
{
|
|
20
|
+
var active = Interlocked.Increment(ref _activeRequests);
|
|
21
|
+
lock (_gate)
|
|
22
|
+
{
|
|
23
|
+
PeakConcurrency = Math.Max(PeakConcurrency, active);
|
|
24
|
+
RequestCount++;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try
|
|
28
|
+
{
|
|
29
|
+
var response = _responses[key];
|
|
30
|
+
_requests.Writer.TryWrite(key);
|
|
31
|
+
return await response.Task.WaitAsync(cancellationToken);
|
|
32
|
+
}
|
|
33
|
+
finally
|
|
34
|
+
{
|
|
35
|
+
Interlocked.Decrement(ref _activeRequests);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public async Task<string[]> ReadRequestsAsync(int count, CancellationToken cancellationToken)
|
|
40
|
+
{
|
|
41
|
+
var requests = new string[count];
|
|
42
|
+
for (var i = 0; i < count; i++)
|
|
43
|
+
{
|
|
44
|
+
requests[i] = await _requests.Reader.ReadAsync(cancellationToken).AsTask()
|
|
45
|
+
.WaitAsync(TimeSpan.FromSeconds(30), cancellationToken);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return requests;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public void Respond(string key, T response) => _responses[key].TrySetResult(response);
|
|
52
|
+
|
|
53
|
+
public void Fail(string key, Exception exception) => _responses[key].TrySetException(exception);
|
|
54
|
+
|
|
55
|
+
public void RespondAll(Func<string, T> response)
|
|
56
|
+
{
|
|
57
|
+
foreach (var key in _responses.Keys)
|
|
58
|
+
{
|
|
59
|
+
Respond(key, response(key));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dependabot-nuget
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.403.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dependabot
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - '='
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.
|
|
18
|
+
version: 0.403.0
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - '='
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.
|
|
25
|
+
version: 0.403.0
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: debug
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -304,6 +304,7 @@ files:
|
|
|
304
304
|
- helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/AnalyzeWorkerTestBase.cs
|
|
305
305
|
- helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/AnalyzeWorkerTests.cs
|
|
306
306
|
- helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/CompatibilityCheckerTests.cs
|
|
307
|
+
- helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/DependencyFinderTests.cs
|
|
307
308
|
- helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/ExpectedAnalysisResult.cs
|
|
308
309
|
- helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/RequirementTests.cs
|
|
309
310
|
- helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/SecurityVulnerabilityExtensionsTests.cs
|
|
@@ -390,6 +391,7 @@ files:
|
|
|
390
391
|
- helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/BOMHandlingTests.cs
|
|
391
392
|
- helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/DiffUtil.cs
|
|
392
393
|
- helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/EOLHandlingTests.cs
|
|
394
|
+
- helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/GatedRequests.cs
|
|
393
395
|
- helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/GitSubmoduleParserTests.cs
|
|
394
396
|
- helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/JsonHelperTests.cs
|
|
395
397
|
- helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/LinuxOnlyAttribute.cs
|
|
@@ -590,7 +592,7 @@ licenses:
|
|
|
590
592
|
- MIT
|
|
591
593
|
metadata:
|
|
592
594
|
bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
|
|
593
|
-
changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.
|
|
595
|
+
changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.403.0
|
|
594
596
|
rdoc_options: []
|
|
595
597
|
require_paths:
|
|
596
598
|
- lib
|