69 lines
1.9 KiB
C#
69 lines
1.9 KiB
C#
#!/usr/bin/env -S dotnet run
|
|
|
|
#:package StudioWhy.Gitea.Net@1.24.2.*
|
|
|
|
using System.Text.Json;
|
|
using System.Text;
|
|
using Gitea.Net.Api;
|
|
using Gitea.Net.Client;
|
|
using Gitea.Net.Model;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
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);
|
|
|
|
Configuration giteaConfig = GetGiteaConfig(configuration);
|
|
RepositoryApi repoApi = new(giteaConfig);
|
|
|
|
|
|
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}");
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|