mirror of
https://github.com/dnwSilver/tld.git
synced 2024-11-25 16:42:07 +00:00
🐛 Fix bug when engines not found.
This commit is contained in:
parent
8e6ce6bd3e
commit
44eb08f5e8
@ -49,7 +49,7 @@ public class DependencyDashboard : IControl<Project>
|
|||||||
|
|
||||||
return string.Join("",
|
return string.Join("",
|
||||||
conventionDependencies
|
conventionDependencies
|
||||||
.Select(package.Dependencies.GetVersion)
|
.Select(dependency => GetVersion(dependency, package))
|
||||||
.Select(RenderCurrentVersion));
|
.Select(RenderCurrentVersion));
|
||||||
}
|
}
|
||||||
catch (HttpRequestException exception)
|
catch (HttpRequestException exception)
|
||||||
@ -61,7 +61,7 @@ public class DependencyDashboard : IControl<Project>
|
|||||||
case HttpStatusCode.Forbidden:
|
case HttpStatusCode.Forbidden:
|
||||||
return " Not enough rights.".Pastel(Palette.ErrorColor);
|
return " Not enough rights.".Pastel(Palette.ErrorColor);
|
||||||
case HttpStatusCode.NotFound:
|
case HttpStatusCode.NotFound:
|
||||||
return " Repository not found.".Pastel(Palette.ErrorColor);
|
return " Repository or branch master not found.".Pastel(Palette.ErrorColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
@ -73,6 +73,37 @@ public class DependencyDashboard : IControl<Project>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static string GetVersion(DependencyDto dependency, Package package)
|
||||||
|
{
|
||||||
|
var currentVersion = package.ParseVersion(dependency.Name);
|
||||||
|
|
||||||
|
if (currentVersion == null)
|
||||||
|
{
|
||||||
|
return "".Hint();
|
||||||
|
}
|
||||||
|
|
||||||
|
var conventionVersion = dependency.Version?.ToVersion();
|
||||||
|
return PaintingVersion(currentVersion, conventionVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string PaintingVersion(Version current, Version? convention)
|
||||||
|
{
|
||||||
|
var textVersion = current.ToString();
|
||||||
|
|
||||||
|
if (current > convention)
|
||||||
|
{
|
||||||
|
return textVersion.Info();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current < convention)
|
||||||
|
{
|
||||||
|
return current.Major == convention.Major ? textVersion.Warning() : textVersion.Error();
|
||||||
|
}
|
||||||
|
|
||||||
|
return textVersion.Primary();
|
||||||
|
}
|
||||||
|
|
||||||
private readonly static Dictionary<string, Package> Packages = new();
|
private readonly static Dictionary<string, Package> Packages = new();
|
||||||
|
|
||||||
private static Package DownloadPackage(SourceDto sourceDto)
|
private static Package DownloadPackage(SourceDto sourceDto)
|
||||||
@ -86,7 +117,7 @@ public class DependencyDashboard : IControl<Project>
|
|||||||
var endpoint = sourceDto.Tags.Have("gitlab") ? GetGitlabEndpoint(sourceDto) : sourceDto.Repo;
|
var endpoint = sourceDto.Tags.Have("gitlab") ? GetGitlabEndpoint(sourceDto) : sourceDto.Repo;
|
||||||
var json = client.GetStringAsync(endpoint).GetAwaiter().GetResult();
|
var json = client.GetStringAsync(endpoint).GetAwaiter().GetResult();
|
||||||
var package = JsonSerializer.Deserialize<Package>(json);
|
var package = JsonSerializer.Deserialize<Package>(json);
|
||||||
Packages.Add(sourceDto.Repo, package);
|
Packages.Add(endpoint, package);
|
||||||
return package;
|
return package;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,30 +146,38 @@ public class DependencyDashboard : IControl<Project>
|
|||||||
|
|
||||||
private static string GetTitle(SourceDto sourceDto)
|
private static string GetTitle(SourceDto sourceDto)
|
||||||
{
|
{
|
||||||
var rowText = new StringBuilder();
|
var title = "";
|
||||||
|
|
||||||
RenderPadding(rowText);
|
title += RenderPadding();
|
||||||
RenderTags(rowText, sourceDto);
|
title += RenderTags(sourceDto);
|
||||||
rowText.Append(sourceDto.Name);
|
if (title.Width() + sourceDto.Name.Length + Theme.Padding <= TitleWidth)
|
||||||
RenderPadding(rowText);
|
{
|
||||||
var text = rowText.ToString();
|
title += sourceDto.Name;
|
||||||
return $"{text}{' '.Repeat(TitleWidth - text.Width())}";
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var maxNameWidth = TitleWidth - title.Width() - Theme.Padding;
|
||||||
|
title += $"{sourceDto.Name[..(maxNameWidth - 1)]}{"#".Hint()}";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RenderPadding(StringBuilder rowText)
|
title += RenderPadding();
|
||||||
{
|
return $"{title}{' '.Repeat(TitleWidth - title.Width())}";
|
||||||
rowText.Append(new string(' ', Theme.Padding));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RenderTags(StringBuilder rowText, SourceDto sourceDto)
|
private static string RenderPadding()
|
||||||
{
|
{
|
||||||
rowText.Append(GetGitApplication(sourceDto));
|
return new string(' ', Theme.Padding);
|
||||||
rowText.Append(sourceDto.Tags.Have("public")
|
}
|
||||||
? GetIcon("", "00FFFF")
|
|
||||||
: GetIcon("", "AFE1AF"));
|
private static string RenderTags(SourceDto sourceDto)
|
||||||
rowText.Append(GetIcon("", "4285F4", sourceDto.Tags.Have("seo")));
|
{
|
||||||
rowText.Append(GetIcon("", "FFD700", sourceDto.Tags.Have("auth")));
|
var tags = "";
|
||||||
rowText.Append(GetApplicationType(sourceDto));
|
tags += GetGitApplication(sourceDto);
|
||||||
|
tags += sourceDto.Tags.Have("public") ? GetIcon("", "00FFFF") : GetIcon("", "AFE1AF");
|
||||||
|
tags += GetIcon("", "4285F4", sourceDto.Tags.Have("seo"));
|
||||||
|
tags += GetIcon("", "FFD700", sourceDto.Tags.Have("auth"));
|
||||||
|
tags += GetApplicationType(sourceDto);
|
||||||
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetApplicationType(SourceDto sourceDto)
|
private static string GetApplicationType(SourceDto sourceDto)
|
||||||
|
@ -7,5 +7,36 @@ namespace TUI.Domain;
|
|||||||
public class Package
|
public class Package
|
||||||
{
|
{
|
||||||
[JsonPropertyName("dependencies")]
|
[JsonPropertyName("dependencies")]
|
||||||
public JsonObject Dependencies { get; set; }
|
public JsonObject? Dependencies { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("devDependencies")]
|
||||||
|
public JsonObject? DevDependencies { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("engines")]
|
||||||
|
public JsonObject? Engines { get; set; }
|
||||||
|
|
||||||
|
public Version? ParseVersion(string? dependencyName)
|
||||||
|
{
|
||||||
|
if (dependencyName == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonNode? version = null;
|
||||||
|
|
||||||
|
var lowerDependencyName = dependencyName.ToLower();
|
||||||
|
Dependencies?.TryGetPropertyValue(lowerDependencyName, out version);
|
||||||
|
|
||||||
|
if (version == null)
|
||||||
|
{
|
||||||
|
Engines?.TryGetPropertyValue(lowerDependencyName, out version);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version == null)
|
||||||
|
{
|
||||||
|
DevDependencies?.TryGetPropertyValue(lowerDependencyName, out version);
|
||||||
|
}
|
||||||
|
|
||||||
|
return version?.GetValue<string>().ToVersion();
|
||||||
|
}
|
||||||
}
|
}
|
@ -16,7 +16,7 @@ public static class Extensions
|
|||||||
|
|
||||||
public static string Repeat(this char symbol, int repeatCount)
|
public static string Repeat(this char symbol, int repeatCount)
|
||||||
{
|
{
|
||||||
return new string(symbol, repeatCount);
|
return repeatCount < 0 ? "" : new string(symbol, repeatCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Width(this string text)
|
public static int Width(this string text)
|
||||||
@ -31,36 +31,7 @@ public static class Extensions
|
|||||||
return stringInfo.LengthInTextElements;
|
return stringInfo.LengthInTextElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetVersion(this JsonObject dependencies, DependencyDto dependencyDto)
|
public static Version? ToVersion(this string textVersion)
|
||||||
{
|
|
||||||
dependencies.TryGetPropertyValue(dependencyDto.Name.ToLower(), out var version);
|
|
||||||
var currentVersion = version?.GetValue<string>().ToVersion();
|
|
||||||
if (currentVersion == null)
|
|
||||||
{
|
|
||||||
return "".Hint();
|
|
||||||
}
|
|
||||||
|
|
||||||
var conventionVersion = dependencyDto.Version.ToVersion();
|
|
||||||
|
|
||||||
if (currentVersion > conventionVersion)
|
|
||||||
{
|
|
||||||
return currentVersion.ToString().Info();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentVersion < conventionVersion)
|
|
||||||
{
|
|
||||||
if (currentVersion.Major == conventionVersion.Major)
|
|
||||||
{
|
|
||||||
return currentVersion.ToString().Warning();
|
|
||||||
}
|
|
||||||
|
|
||||||
return currentVersion.ToString().Error();
|
|
||||||
}
|
|
||||||
|
|
||||||
return currentVersion.ToString().Primary();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Version? ToVersion(this string textVersion)
|
|
||||||
{
|
{
|
||||||
var version = textVersion.Replace("^", "").Replace("~", "").Split(".");
|
var version = textVersion.Replace("^", "").Replace("~", "").Split(".");
|
||||||
if (version.Length != 3)
|
if (version.Length != 3)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
using System.Drawing;
|
|
||||||
using Pastel;
|
using Pastel;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user