dependabot-nuget 0.402.0 → 0.404.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/Analyze/VersionFinder.cs +7 -2
- 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/RefreshSecurityUpdatePullRequestHandler.cs +24 -8
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandler.cs +17 -7
- 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 +11 -9
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/ApiModel/JobTests.cs +55 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/MiscellaneousTests.cs +33 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestBodyGenerator/DetailedPullRequestBodyGeneratorTests.cs +76 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandlerTests.cs +278 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandlerTests.cs +274 -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: def91d11e5d6c2dc8574fb7dc559e89e6a1a5d0e6f005ec8825c7cd9357772ac
|
|
4
|
+
data.tar.gz: cea0054ad998339589f1c9b8a55430b1753adb4f96e1cba0f41c0040a3046d29
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 06f6fdaa57705064b5b85677ea34dd9429a223264b054e08a0517cbe2ef0c876cff4156c46a728b39bbb7e08e9fcba34eac01629095018010f3783daa8081946
|
|
7
|
+
data.tar.gz: 49f43e6760d0816b034bc6186d69bc7ee9bfa0e572e6bba2b20015bf1b720661e23b89df16b3adcd9e1d95e5f7d7e3fca3998ef7760bac3f654762a075ca2ecb
|
|
@@ -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
|
{
|
|
@@ -329,15 +329,20 @@ internal static class VersionFinder
|
|
|
329
329
|
var isMajorBump = version.Major > currentVersion.Major;
|
|
330
330
|
var isMinorBump = version.Major == currentVersion.Major && version.Minor > currentVersion.Minor;
|
|
331
331
|
var isPatchBump = version.Major == currentVersion.Major && version.Minor == currentVersion.Minor && version.Patch > currentVersion.Patch;
|
|
332
|
+
|
|
333
|
+
// each ignored update type only rejects bumps of exactly that type, e.g., ignoring `semver-patch`
|
|
334
|
+
// still allows minor and major bumps; this matches the ignore ranges of the other ecosystems and is
|
|
335
|
+
// required for groups, whose `update-types` are forwarded as the ignored complement (a group with
|
|
336
|
+
// `update-types: [major]` ignores `semver-minor` and `semver-patch`, but must still find major bumps)
|
|
332
337
|
foreach (var ignoreType in dependencyInfo.IgnoredUpdateTypes)
|
|
333
338
|
{
|
|
334
339
|
switch (ignoreType)
|
|
335
340
|
{
|
|
336
341
|
case ConditionUpdateType.SemVerPatch:
|
|
337
|
-
isIgnoredByType = isIgnoredByType || isPatchBump
|
|
342
|
+
isIgnoredByType = isIgnoredByType || isPatchBump;
|
|
338
343
|
break;
|
|
339
344
|
case ConditionUpdateType.SemVerMinor:
|
|
340
|
-
isIgnoredByType = isIgnoredByType || isMinorBump
|
|
345
|
+
isIgnoredByType = isIgnoredByType || isMinorBump;
|
|
341
346
|
break;
|
|
342
347
|
case ConditionUpdateType.SemVerMajor:
|
|
343
348
|
isIgnoredByType = isIgnoredByType || isMajorBump;
|
|
@@ -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)
|
|
@@ -31,6 +31,10 @@ internal class RefreshSecurityUpdatePullRequestHandler : IUpdateHandler
|
|
|
31
31
|
var repoContentsPath = caseInsensitiveRepoContentsPath ?? originalRepoContentsPath;
|
|
32
32
|
var jobDependencies = job.Dependencies.ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
33
33
|
var initialFiles = ModifiedFilesTracker.GetInitiallyExistingFiles(repoContentsPath);
|
|
34
|
+
// directories share a working tree, so an earlier directory may already have updated (or created) the PR
|
|
35
|
+
var pullRequestUpdated = false;
|
|
36
|
+
// closing is deferred until every directory has been evaluated so the outcome doesn't depend on directory order
|
|
37
|
+
ClosePullRequest? pendingClose = null;
|
|
34
38
|
foreach (var directory in job.GetAllDirectories(repoContentsPath.FullName))
|
|
35
39
|
{
|
|
36
40
|
var discoveryResult = await discoveryWorker.RunAsync(repoContentsPath.FullName, directory);
|
|
@@ -59,8 +63,7 @@ internal class RefreshSecurityUpdatePullRequestHandler : IUpdateHandler
|
|
|
59
63
|
if (groupedUpdateOperationsToPerform.Count == 0)
|
|
60
64
|
{
|
|
61
65
|
var close = ClosePullRequest.WithDependenciesRemoved(job);
|
|
62
|
-
|
|
63
|
-
await apiHandler.ClosePullRequest(close);
|
|
66
|
+
pendingClose ??= close;
|
|
64
67
|
continue;
|
|
65
68
|
}
|
|
66
69
|
|
|
@@ -71,11 +74,11 @@ internal class RefreshSecurityUpdatePullRequestHandler : IUpdateHandler
|
|
|
71
74
|
if (missingDependencies.Length > 0)
|
|
72
75
|
{
|
|
73
76
|
var close = ClosePullRequest.WithDependencyRemoved(job);
|
|
74
|
-
|
|
75
|
-
await apiHandler.ClosePullRequest(close);
|
|
77
|
+
pendingClose ??= close;
|
|
76
78
|
continue;
|
|
77
79
|
}
|
|
78
80
|
|
|
81
|
+
var noVulnerableDependencies = false;
|
|
79
82
|
var tracker = new ModifiedFilesTracker(originalRepoContentsPath, initialFiles, logger);
|
|
80
83
|
await tracker.StartTrackingAsync(discoveryResult);
|
|
81
84
|
foreach (var dependencyGroupToUpdate in groupedUpdateOperationsToPerform)
|
|
@@ -90,9 +93,9 @@ internal class RefreshSecurityUpdatePullRequestHandler : IUpdateHandler
|
|
|
90
93
|
if (vulnerableDependenciesToUpdate.Length == 0)
|
|
91
94
|
{
|
|
92
95
|
var close = ClosePullRequest.WithUpToDate(job);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
pendingClose ??= close;
|
|
97
|
+
noVulnerableDependencies = true;
|
|
98
|
+
break;
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
foreach (var (projectPath, dependency, dependencyInfo) in vulnerableDependenciesToUpdate)
|
|
@@ -141,6 +144,11 @@ internal class RefreshSecurityUpdatePullRequestHandler : IUpdateHandler
|
|
|
141
144
|
}
|
|
142
145
|
}
|
|
143
146
|
|
|
147
|
+
if (noVulnerableDependencies)
|
|
148
|
+
{
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
|
|
144
152
|
// ensure we did something
|
|
145
153
|
var updatesNotPerformed = jobDependencies
|
|
146
154
|
.Except(updatedDependencies.Select(d => d.Name), StringComparer.OrdinalIgnoreCase)
|
|
@@ -151,7 +159,7 @@ internal class RefreshSecurityUpdatePullRequestHandler : IUpdateHandler
|
|
|
151
159
|
if (updatesNotPerformed.Length > 0)
|
|
152
160
|
{
|
|
153
161
|
logger.Info($"No updates performed for: {string.Join(", ", updatesNotPerformed)}");
|
|
154
|
-
|
|
162
|
+
pendingClose ??= ClosePullRequest.WithUpdateNoLongerPossible(job);
|
|
155
163
|
continue;
|
|
156
164
|
}
|
|
157
165
|
|
|
@@ -178,6 +186,7 @@ internal class RefreshSecurityUpdatePullRequestHandler : IUpdateHandler
|
|
|
178
186
|
PrTitle = prTitle,
|
|
179
187
|
PrBody = prBody,
|
|
180
188
|
});
|
|
189
|
+
pullRequestUpdated = true;
|
|
181
190
|
continue;
|
|
182
191
|
}
|
|
183
192
|
else
|
|
@@ -198,9 +207,16 @@ internal class RefreshSecurityUpdatePullRequestHandler : IUpdateHandler
|
|
|
198
207
|
PrBody = prBody,
|
|
199
208
|
DependencyGroup = null,
|
|
200
209
|
});
|
|
210
|
+
pullRequestUpdated = true;
|
|
201
211
|
continue;
|
|
202
212
|
}
|
|
203
213
|
}
|
|
204
214
|
}
|
|
215
|
+
|
|
216
|
+
if (!pullRequestUpdated && pendingClose is not null)
|
|
217
|
+
{
|
|
218
|
+
logger.Info(pendingClose.GetReport());
|
|
219
|
+
await apiHandler.ClosePullRequest(pendingClose);
|
|
220
|
+
}
|
|
205
221
|
}
|
|
206
222
|
}
|
|
@@ -31,6 +31,10 @@ internal class RefreshVersionUpdatePullRequestHandler : IUpdateHandler
|
|
|
31
31
|
var repoContentsPath = caseInsensitiveRepoContentsPath ?? originalRepoContentsPath;
|
|
32
32
|
var jobDependencies = job.Dependencies.ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
33
33
|
var initialFiles = ModifiedFilesTracker.GetInitiallyExistingFiles(repoContentsPath);
|
|
34
|
+
// directories share a working tree, so an earlier directory may already have updated (or created) the PR
|
|
35
|
+
var pullRequestUpdated = false;
|
|
36
|
+
// closing is deferred until every directory has been evaluated so the outcome doesn't depend on directory order
|
|
37
|
+
ClosePullRequest? pendingClose = null;
|
|
34
38
|
foreach (var directory in job.GetAllDirectories(repoContentsPath.FullName))
|
|
35
39
|
{
|
|
36
40
|
var discoveryResult = await discoveryWorker.RunAsync(repoContentsPath.FullName, directory);
|
|
@@ -56,8 +60,7 @@ internal class RefreshVersionUpdatePullRequestHandler : IUpdateHandler
|
|
|
56
60
|
if (relevantUpdateOperationsToPerform.Count == 0)
|
|
57
61
|
{
|
|
58
62
|
var close = ClosePullRequest.WithDependenciesRemoved(job);
|
|
59
|
-
|
|
60
|
-
await apiHandler.ClosePullRequest(close);
|
|
63
|
+
pendingClose ??= close;
|
|
61
64
|
continue;
|
|
62
65
|
}
|
|
63
66
|
|
|
@@ -68,8 +71,7 @@ internal class RefreshVersionUpdatePullRequestHandler : IUpdateHandler
|
|
|
68
71
|
if (missingDependencies.Length > 0)
|
|
69
72
|
{
|
|
70
73
|
var close = ClosePullRequest.WithDependencyRemoved(job);
|
|
71
|
-
|
|
72
|
-
await apiHandler.ClosePullRequest(close);
|
|
74
|
+
pendingClose ??= close;
|
|
73
75
|
continue;
|
|
74
76
|
}
|
|
75
77
|
|
|
@@ -141,7 +143,7 @@ internal class RefreshVersionUpdatePullRequestHandler : IUpdateHandler
|
|
|
141
143
|
if (updatesNotPerformed.Length > 0)
|
|
142
144
|
{
|
|
143
145
|
logger.Info($"No updates performed for: {string.Join(", ", updatesNotPerformed)}");
|
|
144
|
-
|
|
146
|
+
pendingClose ??= ClosePullRequest.WithUpdateNoLongerPossible(job);
|
|
145
147
|
continue;
|
|
146
148
|
}
|
|
147
149
|
|
|
@@ -155,7 +157,7 @@ internal class RefreshVersionUpdatePullRequestHandler : IUpdateHandler
|
|
|
155
157
|
var prBody = await PullRequestTextGenerator.GetPullRequestBodyAsync(job, [.. updateOperationsPerformed], [.. updatedDependencies], experimentsManager);
|
|
156
158
|
|
|
157
159
|
var reportedDependencies = updatedDependencies.Select(d => ReportedDependencyWithDirectory.From(d, directory)).ToArray();
|
|
158
|
-
var existingPullRequest = job.GetExistingPullRequestForDependencies(reportedDependencies, considerVersions: true);
|
|
160
|
+
var existingPullRequest = job.GetExistingPullRequestForDependencies(reportedDependencies, considerVersions: true, treatEmptyDirectoryAsWildcard: true);
|
|
159
161
|
if (existingPullRequest is not null)
|
|
160
162
|
{
|
|
161
163
|
await apiHandler.UpdatePullRequest(new UpdatePullRequest()
|
|
@@ -168,11 +170,12 @@ internal class RefreshVersionUpdatePullRequestHandler : IUpdateHandler
|
|
|
168
170
|
PrTitle = prTitle,
|
|
169
171
|
PrBody = prBody,
|
|
170
172
|
});
|
|
173
|
+
pullRequestUpdated = true;
|
|
171
174
|
continue;
|
|
172
175
|
}
|
|
173
176
|
else
|
|
174
177
|
{
|
|
175
|
-
var existingPrButDifferent = job.GetExistingPullRequestForDependencies(reportedDependencies, considerVersions: false);
|
|
178
|
+
var existingPrButDifferent = job.GetExistingPullRequestForDependencies(reportedDependencies, considerVersions: false, treatEmptyDirectoryAsWildcard: true);
|
|
176
179
|
if (existingPrButDifferent is not null)
|
|
177
180
|
{
|
|
178
181
|
await apiHandler.ClosePullRequest(ClosePullRequest.WithDependenciesChanged(job));
|
|
@@ -188,9 +191,16 @@ internal class RefreshVersionUpdatePullRequestHandler : IUpdateHandler
|
|
|
188
191
|
PrBody = prBody,
|
|
189
192
|
DependencyGroup = null,
|
|
190
193
|
});
|
|
194
|
+
pullRequestUpdated = true;
|
|
191
195
|
continue;
|
|
192
196
|
}
|
|
193
197
|
}
|
|
194
198
|
}
|
|
199
|
+
|
|
200
|
+
if (!pullRequestUpdated && pendingClose is not null)
|
|
201
|
+
{
|
|
202
|
+
logger.Info(pendingClose.GetReport());
|
|
203
|
+
await apiHandler.ClosePullRequest(pendingClose);
|
|
204
|
+
}
|
|
195
205
|
}
|
|
196
206
|
}
|
|
@@ -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
|