From 58277268e3775d623e4a2ca1615eada65899671c Mon Sep 17 00:00:00 2001 From: Piotr Kus Date: Fri, 23 Jan 2026 11:59:30 +0100 Subject: [PATCH] * Code refactoring * Change method name --- Services/Gitea/GiteaService.cs | 14 ++++++-------- Services/Gitea/IGiteaService.cs | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Services/Gitea/GiteaService.cs b/Services/Gitea/GiteaService.cs index b312d04..7977b99 100644 --- a/Services/Gitea/GiteaService.cs +++ b/Services/Gitea/GiteaService.cs @@ -61,19 +61,17 @@ public class GiteaService : IGiteaService public async Task<(bool Status, string Response)> SendRequestAsync(GiteaConfiguration configuration, string endpoint, HttpContent content) { - if (configuration == null) throw new ArgumentNullException(nameof(configuration)); + ArgumentNullException.ThrowIfNull(configuration); + ArgumentNullException.ThrowIfNull(content); + if (string.IsNullOrEmpty(endpoint)) throw new ArgumentException("Endpoint cannot be null or empty.", nameof(endpoint)); - if (content == null) throw new ArgumentNullException(nameof(content)); var requestUrl = $"{configuration.Url}/{endpoint}"; - using var request = new HttpRequestMessage(HttpMethod.Post, requestUrl) - { - Content = content - }; + using var request = new HttpRequestMessage(HttpMethod.Post, requestUrl); + request.Content = content; request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("token", configuration.ApiToken); - // Content-Type header should be set by the HttpContent automatically, avoid setting it manually here. - + try { var giteaResponse = await HttpClient.SendAsync(request); diff --git a/Services/Gitea/IGiteaService.cs b/Services/Gitea/IGiteaService.cs index eca2a5e..9ac7eac 100644 --- a/Services/Gitea/IGiteaService.cs +++ b/Services/Gitea/IGiteaService.cs @@ -5,7 +5,7 @@ namespace Services.Gitea; public interface IGiteaService { - RepositoryApi CreateGiteaClientAsync(GiteaConfiguration configuration); + RepositoryApi CreateGiteaClient(GiteaConfiguration configuration); Task> GetLastCommitsAsync(RepositoryApi repositoryApi, GiteaConfiguration configuration, int limit); Task GetFileContentAsync(RepositoryApi repositoryApi, GiteaConfiguration configuration,