Skip to content

Commit 98b0d01

Browse files
committed
Add url-link in console for download content from url
1 parent 7e03dae commit 98b0d01

File tree

7 files changed

+30
-8
lines changed

7 files changed

+30
-8
lines changed

src/Atc.CodingRules.AnalyzerProviders/Providers/AnalyzerProviderBase.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ namespace Atc.CodingRules.AnalyzerProviders.Providers;
22

33
public abstract class AnalyzerProviderBase : IAnalyzerProvider
44
{
5-
[SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "OK.")]
6-
private const string GitRawAtcAnalyzerProviderBaseRulesBasePath = "https://raw.githubusercontent.com/atc-net/atc-coding-rules-updater/main/AnalyzerProviderBaseRules/";
5+
private const string GitRawAtcAnalyzerProviderBaseRulesBasePath = Constants.GitRawContentUrl + "/atc-net/atc-coding-rules-updater/main/AnalyzerProviderBaseRules/";
76
private readonly ILogger logger;
87
private readonly bool logWithAnsiConsoleMarkup;
98

@@ -133,7 +132,12 @@ protected static Task WriteToTempFolder(
133132
{
134133
ArgumentNullException.ThrowIfNull(data);
135134

136-
var rawGitData = HttpClientHelper.GetAsString(logger, GitRawAtcAnalyzerProviderBaseRulesBasePath + data.Name + ".json");
135+
var url = GitRawAtcAnalyzerProviderBaseRulesBasePath + data.Name + ".json";
136+
var displayName = url.Replace(Constants.GitRawContentUrl, Constants.GitHubPrefix, StringComparison.Ordinal);
137+
var rawGitData = HttpClientHelper.GetAsString(
138+
logger,
139+
url,
140+
displayName);
137141
return Task.FromResult(string.IsNullOrEmpty(rawGitData)
138142
? null
139143
: JsonSerializer.Deserialize<AnalyzerProviderBaseRuleData>(rawGitData, AnalyzerProviderSerialization.JsonOptions)!);

src/Atc.CodingRules.Updater.CLI/ProjectHelper.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ namespace Atc.CodingRules.Updater.CLI;
88

99
public static class ProjectHelper
1010
{
11-
[SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "OK.")]
12-
private const string RawCodingRulesDistributionBaseUrl = "https://raw.githubusercontent.com/atc-net/atc-coding-rules/main/distribution";
11+
private const string RawCodingRulesDistributionBaseUrl = Constants.GitRawContentUrl + "/atc-net/atc-coding-rules/main/distribution";
1312
private const string AtcCodingRulesSuppressionsFileName = "AtcCodingRulesSuppressions.txt";
1413

1514
private const string AtcCodingRulesSuppressionsFileNameAsExcel = "AtcCodingRulesSuppressions.xlsx";

src/Atc.CodingRules.Updater/DirectoryBuildPropsHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@ public static void HandleFile(
4040
? $"{rawCodingRulesDistribution}/{FileName}"
4141
: $"{rawCodingRulesDistribution}/{urlPart}/{FileName}";
4242

43+
var displayName = rawGitUrl.Replace(Constants.GitRawContentUrl, Constants.GitHubPrefix, StringComparison.Ordinal);
44+
4345
try
4446
{
4547
if (!file.Directory!.Exists)
4648
{
4749
Directory.CreateDirectory(file.Directory.FullName);
4850
}
4951

50-
var contentGit = HttpClientHelper.GetAsString(logger, rawGitUrl);
52+
var contentGit = HttpClientHelper.GetAsString(logger, rawGitUrl, displayName);
5153
if (useLatestMinorNugetVersion)
5254
{
5355
contentGit = EnsureLatestPackageReferencesVersion(logger, contentGit, LogCategoryType.Trace);

src/Atc.CodingRules.Updater/EditorConfigHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ public static void HandleFile(
3333
? $"{rawCodingRulesDistribution}/{FileName}"
3434
: $"{rawCodingRulesDistribution}/{urlPart}/{FileName}";
3535

36+
var displayName = rawGitUrl.Replace(Constants.GitRawContentUrl, Constants.GitHubPrefix, StringComparison.Ordinal);
37+
3638
try
3739
{
3840
if (!file.Directory!.Exists)
3941
{
4042
Directory.CreateDirectory(file.Directory.FullName);
4143
}
4244

43-
var contentGit = HttpClientHelper.GetAsString(logger, rawGitUrl).TrimEndForEmptyLines();
45+
var contentGit = HttpClientHelper.GetAsString(logger, rawGitUrl, displayName).TrimEndForEmptyLines();
4446
var contentFile = FileHelper.ReadAllText(file);
4547

4648
HandleFile(logger, area, contentGit, contentFile, descriptionPart, file);

src/Atc.CodingRules/Constants.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Atc.CodingRules;
2+
3+
public static class Constants
4+
{
5+
[SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "OK.")]
6+
public const string GitRawContentUrl = "https://raw.githubusercontent.com";
7+
public const string GitHubPrefix = "[silver][[GitHub]][/] ";
8+
}

src/Atc.CodingRules/GlobalUsings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
global using System.Collections.Concurrent;
22
global using System.Diagnostics;
3+
global using System.Diagnostics.CodeAnalysis;
34
global using System.Net;
45

56
global using Atc.Helpers;

src/Atc.CodingRules/HttpClientHelper.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public static class HttpClientHelper
77
public static string GetAsString(
88
ILogger logger,
99
string url,
10+
string displayName,
1011
CancellationToken cancellationToken = default)
1112
{
1213
var cacheValue = Cache.GetValueOrDefault(url);
@@ -15,13 +16,18 @@ public static string GetAsString(
1516
return cacheValue;
1617
}
1718

19+
if (string.IsNullOrEmpty(displayName))
20+
{
21+
displayName = url;
22+
}
23+
1824
try
1925
{
2026
var response = string.Empty;
2127
TaskHelper.RunSync(async () =>
2228
{
2329
var stopwatch = Stopwatch.StartNew();
24-
logger.LogTrace($" Download from: {url}");
30+
logger.LogTrace($" Download from: [link={url}]{displayName}[/]");
2531

2632
var uri = new Uri(url);
2733
using var client = new HttpClient();

0 commit comments

Comments
 (0)