diff --git a/README.md b/README.md index cf6f367..38461ab 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,10 @@ Team Lead Dashboard CLI To Manage Your Work In Style! ## Dependencies -![](docs/Dependencies.png) \ No newline at end of file +![](docs/Dependencies.png) + +## Configuration + +### Environments + +- TLD_GITLAB_PAT personal access token to gitlab \ No newline at end of file diff --git a/src/TUI/Dashboards/DependencyDashboard.cs b/src/TUI/Dashboards/DependencyDashboard.cs index a6ec1dc..a294960 100644 --- a/src/TUI/Dashboards/DependencyDashboard.cs +++ b/src/TUI/Dashboards/DependencyDashboard.cs @@ -1,3 +1,4 @@ +using System.Drawing; using System.Text; using System.Text.Json; using Pastel; @@ -44,12 +45,19 @@ public class DependencyDashboard : IControl private string GetDependencies(Source source, IEnumerable conventionDependencies) { - var package = DownloadPackage(source); + try + { + var package = DownloadPackage(source); - return string.Join("", - conventionDependencies - .Select(package.Dependencies.GetVersion) - .Select(GetCurrentVersion)); + return string.Join("", + conventionDependencies + .Select(package.Dependencies.GetVersion) + .Select(GetCurrentVersion)); + } + catch + { + return "󰋔 We tried to send a request but couldn't. Check your configuration.".Pastel(Palette.ErrorColor); + } } private readonly static Dictionary Packages = new(); @@ -62,26 +70,20 @@ public class DependencyDashboard : IControl } using HttpClient client = new(); - var json = client.GetStringAsync(source.Repo).GetAwaiter().GetResult(); + var endpoint = source.Tags.Have("gitlab") ? GetGitlabEndpoint(source) : source.Repo; + var json = client.GetStringAsync(endpoint).GetAwaiter().GetResult(); var package = JsonSerializer.Deserialize(json); Packages.Add(source.Repo, package); return package; } - // private string GetVersions(string title) - // { - // // var source = sources[index]; - // // var package = DownloadPackage(source); - // // var resultText = package.Dependencies.React; - // // resultText = new string(' ', ColumnWidth - resultText.Width()) + resultText; - // // if (selectedRowNumber == index + 1) - // // { - // // resultText = resultText.PastelBg("292928"); - // // } - // - // return resultText; - // } - + private static string GetGitlabEndpoint(Source source) + { + var token = Environment.GetEnvironmentVariable("TLD_GITLAB_PAT"); + return $"{source.Repo}/api/v4/projects/{source.ProjectId}/repository/files/package.json/raw?" + + $"private_token={token}&ref=master"; + } + private static string GetConventionVersion(Dependency dependency) { return dependency.Icon.Pastel(dependency.Color) + dependency.Version.Primary(); diff --git a/src/TUI/Domain/Source.cs b/src/TUI/Domain/Source.cs index e8f154a..351a83a 100644 --- a/src/TUI/Domain/Source.cs +++ b/src/TUI/Domain/Source.cs @@ -12,6 +12,10 @@ public class Source [YamlMember] public string Name { get; set; } + [YamlMember] + // [YamlMember(Alias = "project_id")] + public int ProjectId { get; set; } = 0; + [YamlMember] public string Repo { get; set; } } \ No newline at end of file diff --git a/src/TUI/TUI.csproj b/src/TUI/TUI.csproj index c3c1043..05b1ebc 100644 --- a/src/TUI/TUI.csproj +++ b/src/TUI/TUI.csproj @@ -5,6 +5,7 @@ net7.0 enable enable + 0.1.0 diff --git a/src/TUI/UserInterface/Palette.cs b/src/TUI/UserInterface/Palette.cs index 27dcdd7..e2c868b 100644 --- a/src/TUI/UserInterface/Palette.cs +++ b/src/TUI/UserInterface/Palette.cs @@ -1,3 +1,4 @@ +using System.Drawing; using Pastel; @@ -8,6 +9,8 @@ public static class Palette public const string HoverColor = "292928"; public const string PrimaryColor = "84BA64"; public const string HintColor = "71797E"; + public const string ErrorColor = "D3B3AC"; + public static string Primary(this string currentText) => currentText.Pastel(PrimaryColor); public static string Hint(this string currentText) => currentText.Pastel(HintColor); } \ No newline at end of file