* Change method name
This commit is contained in:
@@ -61,19 +61,17 @@ public class GiteaService : IGiteaService
|
|||||||
public async Task<(bool Status, string Response)> SendRequestAsync(GiteaConfiguration configuration,
|
public async Task<(bool Status, string Response)> SendRequestAsync(GiteaConfiguration configuration,
|
||||||
string endpoint, HttpContent content)
|
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 (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}";
|
var requestUrl = $"{configuration.Url}/{endpoint}";
|
||||||
using var request = new HttpRequestMessage(HttpMethod.Post, requestUrl)
|
using var request = new HttpRequestMessage(HttpMethod.Post, requestUrl);
|
||||||
{
|
request.Content = content;
|
||||||
Content = content
|
|
||||||
};
|
|
||||||
|
|
||||||
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("token", configuration.ApiToken);
|
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
|
try
|
||||||
{
|
{
|
||||||
var giteaResponse = await HttpClient.SendAsync(request);
|
var giteaResponse = await HttpClient.SendAsync(request);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace Services.Gitea;
|
|||||||
|
|
||||||
public interface IGiteaService
|
public interface IGiteaService
|
||||||
{
|
{
|
||||||
RepositoryApi CreateGiteaClientAsync(GiteaConfiguration configuration);
|
RepositoryApi CreateGiteaClient(GiteaConfiguration configuration);
|
||||||
Task<List<Commit>> GetLastCommitsAsync(RepositoryApi repositoryApi, GiteaConfiguration configuration, int limit);
|
Task<List<Commit>> GetLastCommitsAsync(RepositoryApi repositoryApi, GiteaConfiguration configuration, int limit);
|
||||||
|
|
||||||
Task<ContentsResponse> GetFileContentAsync(RepositoryApi repositoryApi, GiteaConfiguration configuration,
|
Task<ContentsResponse> GetFileContentAsync(RepositoryApi repositoryApi, GiteaConfiguration configuration,
|
||||||
|
|||||||
Reference in New Issue
Block a user