Skip to content

Commit 1ceb420

Browse files
committed
Refactor GetReachableNuGetFeeds out of GetReachableFallbackNugetFeeds
1 parent 600f585 commit 1ceb420

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,34 @@ public HashSet<AssemblyLookupLocation> Restore()
192192
return assemblyLookupLocations;
193193
}
194194

195+
/// <summary>
196+
/// Tests which of the feeds given by <paramref name="feedsToCheck"/> are reachable.
197+
/// </summary>
198+
/// <param name="feedsToCheck">The feeds to check.</param>
199+
/// <param name="isFallback">Whether the feeds are fallback feeds or not.</param>
200+
/// <returns>The list of feeds that could be reached.</returns>
201+
private List<string> GetReachableNuGetFeeds(HashSet<string> feedsToCheck, bool isFallback)
202+
{
203+
var fallbackStr = isFallback ? "fallback " : "";
204+
logger.LogInfo($"Checking {fallbackStr}NuGet feed reachability on feeds: {string.Join(", ", feedsToCheck.OrderBy(f => f))}");
205+
206+
var (initialTimeout, tryCount) = GetFeedRequestSettings(isFallback);
207+
var reachableFeeds = feedsToCheck
208+
.Where(feed => IsFeedReachable(feed, initialTimeout, tryCount, allowExceptions: false))
209+
.ToList();
210+
211+
if (reachableFeeds.Count == 0)
212+
{
213+
logger.LogWarning($"No {fallbackStr}NuGet feeds are reachable.");
214+
}
215+
else
216+
{
217+
logger.LogInfo($"Reachable {fallbackStr}NuGet feeds: {string.Join(", ", reachableFeeds.OrderBy(f => f))}");
218+
}
219+
220+
return reachableFeeds;
221+
}
222+
195223
private List<string> GetReachableFallbackNugetFeeds(HashSet<string>? feedsFromNugetConfigs)
196224
{
197225
var fallbackFeeds = EnvironmentVariables.GetURLs(EnvironmentVariableNames.FallbackNugetFeeds).ToHashSet();
@@ -212,21 +240,7 @@ private List<string> GetReachableFallbackNugetFeeds(HashSet<string>? feedsFromNu
212240
}
213241
}
214242

215-
logger.LogInfo($"Checking fallback NuGet feed reachability on feeds: {string.Join(", ", fallbackFeeds.OrderBy(f => f))}");
216-
var (initialTimeout, tryCount) = GetFeedRequestSettings(isFallback: true);
217-
var reachableFallbackFeeds = fallbackFeeds.Where(feed => IsFeedReachable(feed, initialTimeout, tryCount, allowExceptions: false)).ToList();
218-
if (reachableFallbackFeeds.Count == 0)
219-
{
220-
logger.LogWarning("No fallback NuGet feeds are reachable.");
221-
}
222-
else
223-
{
224-
logger.LogInfo($"Reachable fallback NuGet feeds: {string.Join(", ", reachableFallbackFeeds.OrderBy(f => f))}");
225-
}
226-
227-
compilationInfoContainer.CompilationInfos.Add(("Reachable fallback NuGet feed count", reachableFallbackFeeds.Count.ToString()));
228-
229-
return reachableFallbackFeeds;
243+
return GetReachableNuGetFeeds(fallbackFeeds, isFallback: true);
230244
}
231245

232246
/// <summary>

0 commit comments

Comments
 (0)