Added request to gitlab to get the package.json

This commit is contained in:
Kolosov Alexandr 2023-08-04 09:09:49 +05:00
parent 0bcfa26d26
commit 5c8f6dd76c
5 changed files with 37 additions and 21 deletions

View File

@ -5,3 +5,9 @@ Team Lead Dashboard CLI To Manage Your Work In Style!
## Dependencies ## Dependencies
![](docs/Dependencies.png) ![](docs/Dependencies.png)
## Configuration
### Environments
- TLD_GITLAB_PAT personal access token to gitlab

View File

@ -1,3 +1,4 @@
using System.Drawing;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using Pastel; using Pastel;
@ -43,6 +44,8 @@ public class DependencyDashboard : IControl<Project>
} }
private string GetDependencies(Source source, IEnumerable<Dependency> conventionDependencies) private string GetDependencies(Source source, IEnumerable<Dependency> conventionDependencies)
{
try
{ {
var package = DownloadPackage(source); var package = DownloadPackage(source);
@ -51,6 +54,11 @@ public class DependencyDashboard : IControl<Project>
.Select(package.Dependencies.GetVersion) .Select(package.Dependencies.GetVersion)
.Select(GetCurrentVersion)); .Select(GetCurrentVersion));
} }
catch
{
return "󰋔 We tried to send a request but couldn't. Check your configuration.".Pastel(Palette.ErrorColor);
}
}
private readonly static Dictionary<string, Package> Packages = new(); private readonly static Dictionary<string, Package> Packages = new();
@ -62,25 +70,19 @@ public class DependencyDashboard : IControl<Project>
} }
using HttpClient client = new(); 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<Package>(json); var package = JsonSerializer.Deserialize<Package>(json);
Packages.Add(source.Repo, package); Packages.Add(source.Repo, package);
return package; return package;
} }
// private string GetVersions(string title) private static string GetGitlabEndpoint(Source source)
// { {
// // var source = sources[index]; var token = Environment.GetEnvironmentVariable("TLD_GITLAB_PAT");
// // var package = DownloadPackage(source); return $"{source.Repo}/api/v4/projects/{source.ProjectId}/repository/files/package.json/raw?" +
// // var resultText = package.Dependencies.React; $"private_token={token}&ref=master";
// // resultText = new string(' ', ColumnWidth - resultText.Width()) + resultText; }
// // if (selectedRowNumber == index + 1)
// // {
// // resultText = resultText.PastelBg("292928");
// // }
//
// return resultText;
// }
private static string GetConventionVersion(Dependency dependency) private static string GetConventionVersion(Dependency dependency)
{ {

View File

@ -12,6 +12,10 @@ public class Source
[YamlMember] [YamlMember]
public string Name { get; set; } public string Name { get; set; }
[YamlMember]
// [YamlMember(Alias = "project_id")]
public int ProjectId { get; set; } = 0;
[YamlMember] [YamlMember]
public string Repo { get; set; } public string Repo { get; set; }
} }

View File

@ -5,6 +5,7 @@
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AssemblyVersion>0.1.0</AssemblyVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,3 +1,4 @@
using System.Drawing;
using Pastel; using Pastel;
@ -8,6 +9,8 @@ public static class Palette
public const string HoverColor = "292928"; public const string HoverColor = "292928";
public const string PrimaryColor = "84BA64"; public const string PrimaryColor = "84BA64";
public const string HintColor = "71797E"; public const string HintColor = "71797E";
public const string ErrorColor = "D3B3AC";
public static string Primary(this string currentText) => currentText.Pastel(PrimaryColor); public static string Primary(this string currentText) => currentText.Pastel(PrimaryColor);
public static string Hint(this string currentText) => currentText.Pastel(HintColor); public static string Hint(this string currentText) => currentText.Pastel(HintColor);
} }