Updated .net actions.
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
#!/usr/bin/env -S dotnet run
|
||||
|
||||
#:package StudioWhy.Gitea.Net@1.24.2.*
|
||||
#:package StudioWhy.Gitea.Net.API@1.24.2.*
|
||||
|
||||
using System.Text.Json;
|
||||
using System.Text;
|
||||
|
||||
using Gitea.Net.Api;
|
||||
using Gitea.Net.Client;
|
||||
using Gitea.Net.Extensions;
|
||||
using Gitea.Net.Model;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
string jsonInput = Environment.GetEnvironmentVariable("INPUTS") ?? "{}";
|
||||
const string name = "Download Previous Artifacts";
|
||||
@@ -24,18 +30,52 @@ IConfiguration configuration = new ConfigurationBuilder()
|
||||
|
||||
PrintConfiguration(configuration);
|
||||
|
||||
Configuration giteaConfig = GetGiteaConfig(configuration);
|
||||
RepositoryApi repoApi = new(giteaConfig);
|
||||
string host = configuration["Host"]!;
|
||||
string username = configuration["Username"]!;
|
||||
string password = configuration["Password"]!;
|
||||
|
||||
ServiceCollection services = new();
|
||||
services.AddApi(o =>
|
||||
{
|
||||
BasicToken basicToken = new(username, password);
|
||||
o.AddTokens(basicToken);
|
||||
});
|
||||
|
||||
UriBuilder hostUriBuilder = new(host);
|
||||
hostUriBuilder.Path = "/api/v1";
|
||||
using HttpClient httpClient = new()
|
||||
{
|
||||
BaseAddress = hostUriBuilder.Uri,
|
||||
};
|
||||
|
||||
services.AddLogging(configure => configure.AddConsole());
|
||||
services.AddSingleton(httpClient);
|
||||
services.AddSingleton<OrganizationApi>();
|
||||
services.AddSingleton<RepositoryApi>();
|
||||
|
||||
ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
OrganizationApi organizationApi = serviceProvider.GetRequiredService<OrganizationApi>();
|
||||
RepositoryApi repositoryApi = serviceProvider.GetRequiredService<RepositoryApi>();
|
||||
|
||||
IOrgGetAllApiResponse response = await organizationApi.OrgGetAllAsync();
|
||||
|
||||
if (response.TryOk(out List<Organization> organizations))
|
||||
{
|
||||
foreach (Organization org in organizations)
|
||||
{
|
||||
Console.WriteLine($"Organization: {org.Name}");
|
||||
}
|
||||
//Console.WriteLine($"Repository: {repo?.Name}");
|
||||
}
|
||||
|
||||
// string owner = configuration["GITHUB_REPOSITORY_OWNER"]!;
|
||||
// string repoName = configuration["GITHUB_REPOSITORY"]!;
|
||||
// repoName = Path.GetFileName(repoName);
|
||||
|
||||
|
||||
string owner = configuration["GITHUB_REPOSITORY_OWNER"]!;
|
||||
string repoName = configuration["GITHUB_REPOSITORY"]!;
|
||||
repoName = Path.GetFileName(repoName);
|
||||
// Repository repo = await repoApi.RepoGetAsync(owner, repoName);
|
||||
|
||||
|
||||
Repository repo = await repoApi.RepoGetAsync(owner, repoName);
|
||||
|
||||
Console.WriteLine($"Repository:\n {JsonSerializer.Serialize(repo)}");
|
||||
// Console.WriteLine($"Repository:\n {JsonSerializer.Serialize(repo)}");
|
||||
|
||||
static void PrintConfiguration(IConfiguration configuration)
|
||||
{
|
||||
@@ -44,25 +84,3 @@ static void PrintConfiguration(IConfiguration configuration)
|
||||
Console.WriteLine($"{kvp.Key}: {kvp.Value}");
|
||||
}
|
||||
}
|
||||
|
||||
static Configuration GetGiteaConfig(IConfiguration configuration)
|
||||
{
|
||||
string host = configuration["Host"]!;
|
||||
string username = configuration["Username"]!;
|
||||
string password = configuration["Password"]!;
|
||||
string accessToken = configuration["Token"]!;
|
||||
|
||||
UriBuilder hostUriBuilder = new(host);
|
||||
hostUriBuilder.Path = "/api/v1";
|
||||
string hostUri = hostUriBuilder.ToString();
|
||||
|
||||
Configuration config = new()
|
||||
{
|
||||
BasePath = hostUri,
|
||||
AccessToken = accessToken,
|
||||
Username = username,
|
||||
Password = password,
|
||||
};
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user