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
![](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.Json;
using Pastel;
@ -43,6 +44,8 @@ public class DependencyDashboard : IControl<Project>
}
private string GetDependencies(Source source, IEnumerable<Dependency> conventionDependencies)
{
try
{
var package = DownloadPackage(source);
@ -51,6 +54,11 @@ public class DependencyDashboard : IControl<Project>
.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<string, Package> Packages = new();
@ -62,25 +70,19 @@ public class DependencyDashboard : IControl<Project>
}
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);
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)
{

View File

@ -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; }
}

View File

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

View File

@ -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);
}