87 lines
2.5 KiB
C#
87 lines
2.5 KiB
C#
#!/usr/bin/env -S dotnet run
|
|
|
|
#: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";
|
|
Console.WriteLine($"::group::{name} - Inputs");
|
|
Console.WriteLine(jsonInput);
|
|
Console.WriteLine("::endgroup::");
|
|
byte[] jsonBytes = Encoding.UTF8.GetBytes(jsonInput);
|
|
using MemoryStream memoryStream = new(jsonBytes);
|
|
|
|
IConfiguration configuration = new ConfigurationBuilder()
|
|
.AddJsonStream(memoryStream)
|
|
.AddEnvironmentVariables()
|
|
.Build();
|
|
|
|
PrintConfiguration(configuration);
|
|
|
|
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);
|
|
|
|
|
|
// Repository repo = await repoApi.RepoGetAsync(owner, repoName);
|
|
|
|
// Console.WriteLine($"Repository:\n {JsonSerializer.Serialize(repo)}");
|
|
|
|
static void PrintConfiguration(IConfiguration configuration)
|
|
{
|
|
foreach (var kvp in configuration.AsEnumerable())
|
|
{
|
|
Console.WriteLine($"{kvp.Key}: {kvp.Value}");
|
|
}
|
|
}
|