Try generic upload
All checks were successful
Build on push / prepare (push) Successful in 19s
Build on push / build (push) Successful in 23s

This commit is contained in:
2026-02-14 17:56:57 +01:00
parent c19921eb85
commit 0332f08194
8 changed files with 190 additions and 51 deletions

View File

@@ -1,6 +1,48 @@
namespace sh.actions.package_cleanup.Service;
public class GiteaPackageService : IGiteaPackageService
using System.Net.Http.Json;
using Microsoft.Extensions.Logging;
using sh.actions.package_cleanup.Models;
public class GiteaPackageService(HttpClient httpClient, GiteaConfig config, ILogger<GiteaPackageService> logger)
: IGiteaPackageService
{
public async Task<IEnumerable<GiteaPackage>> GetPackagesByOwnerAsync(CancellationToken cancellationToken = default)
{
try
{
var url = $"{config.GiteaUrl.TrimEnd('/')}/api/v1/packages/{config.Owner}";
logger.LogInformation("Fetching packages from Gitea: {Url}", url);
var request = new HttpRequestMessage(HttpMethod.Get, url);
// Add authentication if token is provided
if (!string.IsNullOrEmpty(config.ApiToken))
{
request.Headers.Add("Authorization", $"token {config.ApiToken}");
}
var response = await httpClient.SendAsync(request, cancellationToken);
response.EnsureSuccessStatusCode();
var packages =
await response.Content.ReadFromJsonAsync<List<GiteaPackage>>(cancellationToken: cancellationToken)
?? new List<GiteaPackage>();
logger.LogInformation("Successfully fetched {Count} packages", packages.Count);
return packages;
}
catch (HttpRequestException ex)
{
logger.LogError(ex, "Error fetching packages from Gitea");
throw;
}
catch (Exception ex)
{
logger.LogError(ex, "Unexpected error fetching packages");
throw;
}
}
}