Skip to content

Commit 571f21b

Browse files
committed
C#: Emit diagnostic if private registries are configured
1 parent 8e39ed0 commit 571f21b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Semmle.Util;
66
using Semmle.Util.Logging;
77
using Newtonsoft.Json;
8+
using System.Linq;
89

910
namespace Semmle.Extraction.CSharp.DependencyFetching
1011
{
@@ -37,7 +38,8 @@ public record class RegistryConfig(string Type, string URL);
3738
/// </summary>
3839
internal X509Certificate2? Certificate { get; private set; }
3940

40-
internal static DependabotProxy? GetDependabotProxy(ILogger logger, TemporaryDirectory tempWorkingDirectory)
41+
internal static DependabotProxy? GetDependabotProxy(
42+
ILogger logger, IDiagnosticsWriter diagnosticsWriter, TemporaryDirectory tempWorkingDirectory)
4143
{
4244
// Setting HTTP(S)_PROXY and SSL_CERT_FILE have no effect on Windows or macOS,
4345
// but we would still end up using the Dependabot proxy to check for feed reachability.
@@ -112,6 +114,23 @@ public record class RegistryConfig(string Type, string URL);
112114
}
113115
}
114116

117+
// Emit a diagnostic for the discovered private registries, so that it is easy
118+
// for users to see that they were picked up.
119+
if (result.RegistryURLs.Count > 0)
120+
{
121+
diagnosticsWriter.AddEntry(new DiagnosticMessage(
122+
Language.CSharp,
123+
"buildless/analysis-using-private-registries",
124+
severity: DiagnosticMessage.TspSeverity.Note,
125+
visibility: new DiagnosticMessage.TspVisibility(true, true, true),
126+
name: "C# extraction used private package registries",
127+
markdownMessage: string.Format(
128+
"C# was extracted using the following private package registries:\n\n{0}\n",
129+
string.Join("\n", result.RegistryURLs.Select(url => string.Format("- `{0}`", url)))
130+
)
131+
));
132+
}
133+
115134
return result;
116135
}
117136

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void exitCallback(int ret, string msg, bool silent)
106106
return BuildScript.Success;
107107
}).Run(SystemBuildActions.Instance, startCallback, exitCallback);
108108

109-
dependabotProxy = DependabotProxy.GetDependabotProxy(logger, tempWorkingDirectory);
109+
dependabotProxy = DependabotProxy.GetDependabotProxy(logger, diagnosticsWriter, tempWorkingDirectory);
110110

111111
try
112112
{

0 commit comments

Comments
 (0)