Merge pull request '* Code refactoring' (#73) from DelforSender into master

Reviewed-on: #73
This commit was merged in pull request #73.
This commit is contained in:
2026-01-23 11:00:04 +00:00
2 changed files with 7 additions and 9 deletions

View File

@@ -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);

View File

@@ -5,7 +5,7 @@ namespace Services.Gitea;
public interface IGiteaService
{
RepositoryApi CreateGiteaClientAsync(GiteaConfiguration configuration);
RepositoryApi CreateGiteaClient(GiteaConfiguration configuration);
Task<List<Commit>> GetLastCommitsAsync(RepositoryApi repositoryApi, GiteaConfiguration configuration, int limit);
Task<ContentsResponse> GetFileContentAsync(RepositoryApi repositoryApi, GiteaConfiguration configuration,