30 lines
1.2 KiB
C#
30 lines
1.2 KiB
C#
namespace w4c_workflows.Services;
|
|
|
|
// Forgejo admin-API half of the workflow repo service: a single authenticated
|
|
// JSON call against the Forgejo REST API using the pooled named client.
|
|
|
|
public sealed partial class ForgejoWorkflowRepoService
|
|
{
|
|
private async Task<HttpResponseMessage> SendAdminAsync(
|
|
HttpMethod method, string path, object? body, CancellationToken ct)
|
|
{
|
|
using var request = new HttpRequestMessage(method, $"{_forgejoBase}/api/v1{path}");
|
|
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(
|
|
"Bearer", _forgejoAdminToken);
|
|
|
|
if (body != null)
|
|
{
|
|
request.Content = new StringContent(
|
|
System.Text.Json.JsonSerializer.Serialize(body, new System.Text.Json.JsonSerializerOptions
|
|
{
|
|
PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.SnakeCaseLower,
|
|
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull,
|
|
}),
|
|
System.Text.Encoding.UTF8,
|
|
"application/json");
|
|
}
|
|
|
|
return await _adminHttp.SendAsync(request, ct);
|
|
}
|
|
}
|