Files
ForgejoReleaseSync/Services/GithubService.cs
T
mahdium 7ac8a5af62 feat: enhance release synchronization with cancellation support, error handling, and logging
- Added `CancellationToken` support across SyncService, GithubService, ForgejoService, and ReleaseAssetDownloadService.
- Improved error handling with detailed logging for asset downloads, deletions, and API operations.
- Refactored SyncService for clearer repository and asset synchronization logic.
- Enhanced performance with async file streams and refined conditional checks.
2026-11-04 16:37:41 +03:30

41 lines
1.4 KiB
C#

using System.Text.Json;
using System.Text.Json.Serialization;
using ForgejoReleaseSync.DTOs;
using ForgejoReleaseSync.DTOs.Forgejo;
using Microsoft.Extensions.Logging;
namespace ForgejoReleaseSync.Services;
public class GithubService(HttpClient httpClient, ILogger<GithubService> logger)
{
public async Task<List<GithubReleaseResponseDto>> FetchRepoReleasesAsync(
string owner, string repo, CancellationToken token = default)
{
try
{
using var response = await httpClient.GetAsync(
new Uri($"https://api.github.com/repos/{owner}/{repo}/releases?per_page=3&page=1"),
token);
response.EnsureSuccessStatusCode();
await using var stream = await response.Content.ReadAsStreamAsync(token);
var releases = await JsonSerializer.DeserializeAsync(
stream, AppJsonSerializerContext.Default.ListGithubReleaseResponseDto, token);
return releases ?? [];
}
catch (Exception ex)
{
logger.LogError(ex, "Failed to fetch GitHub releases for {Owner}/{Repo}", owner, repo);
throw;
}
}
}
[JsonSerializable(typeof(List<GithubReleaseResponseDto>))]
[JsonSerializable(typeof(ForgejoCreateReleaseDto))]
[JsonSerializable(typeof(ForgejoReleaseResponseDto))]
[JsonSerializable(typeof(List<ForgejoReleaseResponseDto>))]
internal partial class AppJsonSerializerContext : JsonSerializerContext
{
}