Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6b2f348
C#: Add `CODEQL_PROXY_URLS` environment variable
mbg Jan 6, 2025
63d5517
C#: Add list of registries to `DependabotProxy`
mbg Jan 7, 2025
11efb55
C#: Parse environment variables to obtain list of registry URLs
mbg Jan 7, 2025
726123c
C#: Allow specifying package feeds for `dotnet restore` as command li…
mbg Jan 7, 2025
0db6a26
C#: Propagate explicit feeds to `RestoreProjects`
mbg Feb 24, 2025
6b15f77
C#: Fix test failures
mbg Mar 3, 2025
a8dde15
C#: Only provide feeds on command line if Dependabot proxy is enabled
mbg Mar 14, 2025
9560593
C#: Fix `.ToList()` being called on `null`
mbg Mar 14, 2025
b6c74fe
C#: Narrow `Exception` to `JsonException`
mbg Mar 14, 2025
284f612
C#: Use `StringBuilder` for feed arguments in `GetRestoreArgs`
mbg Mar 14, 2025
51874b8
Apply suggestions from code review
mbg Mar 17, 2025
7a92a72
C#: Change `RegistryConfig` to a record class
mbg Mar 18, 2025
d564529
C#: Change `RestoreSettings` to have general `extraArgs` parameter
mbg Mar 24, 2025
92eab47
C#: Refactor `CheckFeeds` to have an overloaded variant that accepts …
mbg Mar 24, 2025
4448369
C#: Check that private package registry feeds are reachable
mbg Mar 24, 2025
7cea2ad
Apply suggestions from code review
mbg Mar 25, 2025
d2b88ae
C#: Rename overloaded `CheckFeeds` method and fix comment
mbg Mar 25, 2025
4d3b024
C#: Do not manually add public feed when private registries are used
mbg Mar 25, 2025
73ca2eb
C#: Use `allFeeds` rather than `explicitFeeds` for `RestoreProjects`
mbg Mar 25, 2025
be95d33
C#: Obtain all feeds from source directory if there are no `nuget.con…
mbg Mar 25, 2025
fe1c098
C#: Accept changes to `.expected` files
mbg Mar 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
C#: Refactor CheckFeeds to have an overloaded variant that accepts …
…a given set of feeds.
  • Loading branch information
mbg committed Mar 24, 2025
commit 92eab47def3e2a45151020311ebb8acaf0892a79
Original file line number Diff line number Diff line change
Expand Up @@ -700,11 +700,36 @@ private bool IsFeedReachable(string feed, int timeoutMilliSeconds, int tryCount,
return (timeoutMilliSeconds, tryCount);
}

/// <summary>
/// Checks that we can connect to all Nuget feeds that are explicitly configured in configuration files.
/// </summary>
/// <param name="explicitFeeds">Outputs the set of explicit feeds.</param>
/// <returns>True if all feeds are reachable or false otherwise.</returns>
private bool CheckFeeds(out HashSet<string> explicitFeeds)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename one of the CheckFeeds methods. The naming is a bit confusing when their type signatures are so similar.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in d2b88ae

{
logger.LogInfo("Checking Nuget feeds...");
(explicitFeeds, var allFeeds) = GetAllFeeds();

var allFeedsReachable = this.CheckFeeds(explicitFeeds);

var inheritedFeeds = allFeeds.Except(explicitFeeds).ToHashSet();
if (inheritedFeeds.Count > 0)
{
logger.LogInfo($"Inherited Nuget feeds (not checked for reachability): {string.Join(", ", inheritedFeeds.OrderBy(f => f))}");
compilationInfoContainer.CompilationInfos.Add(("Inherited Nuget feed count", inheritedFeeds.Count.ToString()));
}

return allFeedsReachable;
}

/// <summary>
/// Checks that we can connect to the specified Nuget feeds.
/// </summary>
/// <param name="feeds">The set of package feeds to check.</param>
/// <returns>True if all feeds are reachable or false otherwise.</returns>
private bool CheckFeeds(HashSet<string> feeds)
{
logger.LogInfo("Checking that Nuget feeds are reachable...");

var excludedFeeds = EnvironmentVariables.GetURLs(EnvironmentVariableNames.ExcludedNugetFeedsFromResponsivenessCheck)
.ToHashSet();

Expand All @@ -715,7 +740,7 @@ private bool CheckFeeds(out HashSet<string> explicitFeeds)

var (initialTimeout, tryCount) = GetFeedRequestSettings(isFallback: false);

var allFeedsReachable = explicitFeeds.All(feed => excludedFeeds.Contains(feed) || IsFeedReachable(feed, initialTimeout, tryCount));
var allFeedsReachable = feeds.All(feed => excludedFeeds.Contains(feed) || IsFeedReachable(feed, initialTimeout, tryCount));
if (!allFeedsReachable)
{
logger.LogWarning("Found unreachable Nuget feed in C# analysis with build-mode 'none'. This may cause missing dependencies in the analysis.");
Expand All @@ -730,14 +755,6 @@ private bool CheckFeeds(out HashSet<string> explicitFeeds)
}
compilationInfoContainer.CompilationInfos.Add(("All Nuget feeds reachable", allFeedsReachable ? "1" : "0"));


var inheritedFeeds = allFeeds.Except(explicitFeeds).ToHashSet();
if (inheritedFeeds.Count > 0)
{
logger.LogInfo($"Inherited Nuget feeds (not checked for reachability): {string.Join(", ", inheritedFeeds.OrderBy(f => f))}");
compilationInfoContainer.CompilationInfos.Add(("Inherited Nuget feed count", inheritedFeeds.Count.ToString()));
}

return allFeedsReachable;
}

Expand Down