refactor: web hook

This commit is contained in:
h z
2025-03-13 11:00:11 +00:00
parent 8b5d4ff5f7
commit e94a27823c
8 changed files with 169 additions and 4 deletions

View File

@@ -13,9 +13,11 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OpenAI" Version="2.2.0-beta.2" />
<PackageReference Include="RabbitMQ.Client" Version="7.1.1" />
</ItemGroup>
<Target Name="GenerateNSwagClient" BeforeTargets="Build">
<Exec Command="$(NSwagExe_Net80) run nswag.json" />
<Target Name="GenerateNSwagClient" BeforeTargets="BeforeBuild">
<Exec Command="$(NSwagExe_Net80) run nswag.gitea.json" />
<Exec Command="$(NSwagExe_Net80) run nswag.youtrack.json" />
</Target>
</Project>

100
nswag.youtrack.json Normal file
View File

@@ -0,0 +1,100 @@
{
"runtime": "Net80",
"defaultVariables": null,
"documentGenerator": {
"fromDocument": {
"url": "http://localhost:18891/api/openapi.json",
"output": null,
"newLineBehavior": "Auto"
}
},
"codeGenerators": {
"openApiToCSharpClient": {
"clientBaseClass": null,
"configurationClass": null,
"generateClientClasses": true,
"suppressClientClassesOutput": false,
"generateClientInterfaces": false,
"suppressClientInterfacesOutput": false,
"clientBaseInterface": null,
"injectHttpClient": true,
"disposeHttpClient": true,
"protectedMethods": [],
"generateExceptionClasses": true,
"exceptionClass": "ApiException",
"wrapDtoExceptions": true,
"useHttpClientCreationMethod": false,
"httpClientType": "System.Net.Http.HttpClient",
"useHttpRequestMessageCreationMethod": false,
"useBaseUrl": true,
"generateBaseUrlProperty": true,
"generateSyncMethods": false,
"generatePrepareRequestAndProcessResponseAsAsyncMethods": false,
"exposeJsonSerializerSettings": false,
"clientClassAccessModifier": "public",
"typeAccessModifier": "public",
"propertySetterAccessModifier": "",
"generateNativeRecords": false,
"generateContractsOutput": false,
"contractsNamespace": null,
"contractsOutputFilePath": null,
"parameterDateTimeFormat": "s",
"parameterDateFormat": "yyyy-MM-dd",
"generateUpdateJsonSerializerSettingsMethod": true,
"useRequestAndResponseSerializationSettings": false,
"serializeTypeInformation": false,
"queryNullValue": "",
"className": "YoutrackApiClient",
"operationGenerationMode": "MultipleClientsFromOperationId",
"additionalNamespaceUsages": [],
"additionalContractNamespaceUsages": [],
"generateOptionalParameters": false,
"generateJsonMethods": false,
"enforceFlagEnums": false,
"parameterArrayType": "System.Collections.Generic.IEnumerable",
"parameterDictionaryType": "System.Collections.Generic.IDictionary",
"responseArrayType": "System.Collections.Generic.ICollection",
"responseDictionaryType": "System.Collections.Generic.IDictionary",
"wrapResponses": false,
"wrapResponseMethods": [],
"generateResponseClasses": true,
"responseClass": "SwaggerResponse",
"namespace": "Alchegos.Core.Services.Youtrack",
"requiredPropertiesMustBeDefined": true,
"dateType": "System.DateTimeOffset",
"jsonConverters": null,
"anyType": "object",
"dateTimeType": "System.DateTimeOffset",
"timeType": "System.TimeSpan",
"timeSpanType": "System.TimeSpan",
"arrayType": "System.Collections.Generic.ICollection",
"arrayInstanceType": "System.Collections.ObjectModel.Collection",
"dictionaryType": "System.Collections.Generic.IDictionary",
"dictionaryInstanceType": "System.Collections.Generic.Dictionary",
"arrayBaseType": "System.Collections.ObjectModel.Collection",
"dictionaryBaseType": "System.Collections.Generic.Dictionary",
"classStyle": "Poco",
"jsonLibrary": "NewtonsoftJson",
"generateDefaultValues": true,
"generateDataAnnotations": true,
"excludedTypeNames": [],
"excludedParameterNames": [],
"handleReferences": false,
"generateImmutableArrayProperties": false,
"generateImmutableDictionaryProperties": false,
"jsonSerializerSettingsTransformationMethod": null,
"inlineNamedArrays": false,
"inlineNamedDictionaries": false,
"inlineNamedTuples": true,
"inlineNamedAny": false,
"generateDtoTypes": true,
"generateOptionalPropertiesAsNullable": false,
"generateNullableReferenceTypes": false,
"templateDirectory": null,
"serviceHost": null,
"serviceSchemes": null,
"output": "src/Services/Youtrack/YoutrackApiClient.cs",
"newLineBehavior": "Auto"
}
}
}

View File

@@ -1,11 +1,10 @@
using System.Net;
using Microsoft.Extensions.Options;
namespace Alchegos.Core.Services.Gitea;
public partial class GiteaApiClient
{
private GiteaApiOptions Options;
private GiteaApiOptions Options { get; set; }
public GiteaApiClient(HttpClient client, IOptions<GiteaApiOptions> options)
{

View File

@@ -0,0 +1,6 @@
namespace Alchegos.Core.Services.RabbitMQ;
public interface IRabbitSubscriber
{
Task SubscribeAsync(string exchange, string queueName, IEnumerable<string> routingKeys, Func<string, Task> messageHandler);
}

View File

@@ -0,0 +1,35 @@
using System.Text;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
namespace Alchegos.Core.Services.RabbitMQ;
public class RabbitSubscriber : IRabbitSubscriber
{
public RabbitSubscriber(IRabbitService rabbitService)
{
RabbitService = rabbitService;
}
private IRabbitService RabbitService { get; set; }
public async Task SubscribeAsync(string exchange, string queueName, IEnumerable<string> routingKeys, Func<string, Task> messageHandler)
{
IChannel channel = await RabbitService.GetChannelAsync();
AsyncEventingBasicConsumer consumer = new AsyncEventingBasicConsumer(channel);
consumer.ReceivedAsync += async (sender, args) =>
{
try
{
ReadOnlyMemory<byte> body = args.Body;
var message = Encoding.UTF8.GetString(body.ToArray());
await messageHandler(message);
await channel.BasicAckAsync(args.DeliveryTag, false);
}
catch (Exception ex)
{
await channel.BasicNackAsync(args.DeliveryTag, false, true);
}
};
}
}

View File

@@ -0,0 +1,16 @@
using Microsoft.Extensions.Options;
namespace Alchegos.Core.Services.Youtrack;
public partial class YoutrackApiClient
{
private YoutrackApiOptions Options { get; set; }
public YoutrackApiClient(HttpClient client, IOptions<YoutrackApiOptions> options)
{
_httpClient = client;
Options = options.Value;
BaseUrl = Options.BaseUrl;
_httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {Options.Token}");
}
}

View File

@@ -0,0 +1,7 @@
namespace Alchegos.Core.Services.Youtrack;
public class YoutrackApiOptions
{
public string BaseUrl { get; set; }
public string Token { get; set; }
}