From 5415bb71193bb4ec6a60b7191204919a479e24da Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Fri, 27 Feb 2026 14:30:57 +0000 Subject: [PATCH] Divide up `CheckSpecifiedFeeds` --- .../NugetPackageRestorer.cs | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs index 4a4029507d1..f300865d2ae 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs @@ -755,13 +755,10 @@ namespace Semmle.Extraction.CSharp.DependencyFetching } /// - /// Checks that we can connect to the specified NuGet feeds. + /// Retrieves a list of excluded NuGet feeds from the corresponding environment variable. /// - /// The set of package feeds to check. - /// True if all feeds are reachable or false otherwise. - private bool CheckSpecifiedFeeds(HashSet feeds) + private HashSet GetExcludedFeeds() { - // Exclude any feeds that are configured by the corresponding environment variable. var excludedFeeds = EnvironmentVariables.GetURLs(EnvironmentVariableNames.ExcludedNugetFeedsFromResponsivenessCheck) .ToHashSet(); @@ -770,10 +767,35 @@ namespace Semmle.Extraction.CSharp.DependencyFetching logger.LogInfo($"Excluded NuGet feeds from responsiveness check: {string.Join(", ", excludedFeeds.OrderBy(f => f))}"); } + return excludedFeeds; + } + + /// + /// Checks that we can connect to the specified NuGet feeds. + /// + /// The set of package feeds to check. + /// True if all feeds are reachable or false otherwise. + private bool CheckSpecifiedFeeds(HashSet feeds) + { + // Exclude any feeds that are configured by the corresponding environment variable. + var excludedFeeds = GetExcludedFeeds(); + var feedsToCheck = feeds.Where(feed => !excludedFeeds.Contains(feed)).ToHashSet(); var reachableFeeds = this.GetReachableNuGetFeeds(feedsToCheck, isFallback: false); var allFeedsReachable = reachableFeeds.Count == feedsToCheck.Count; + this.EmitUnreachableFeedsDiagnostics(allFeedsReachable); + + return allFeedsReachable; + } + + /// + /// If is `false`, logs this and emits a diagnostic. + /// Adds a `CompilationInfos` entry either way. + /// + /// Whether all feeds were reachable or not. + private void EmitUnreachableFeedsDiagnostics(bool allFeedsReachable) + { if (!allFeedsReachable) { logger.LogWarning("Found unreachable NuGet feed in C# analysis with build-mode 'none'. This may cause missing dependencies in the analysis."); @@ -787,8 +809,6 @@ namespace Semmle.Extraction.CSharp.DependencyFetching )); } compilationInfoContainer.CompilationInfos.Add(("All NuGet feeds reachable", allFeedsReachable ? "1" : "0")); - - return allFeedsReachable; } private IEnumerable GetFeeds(Func> getNugetFeeds)