refactor: web hook
This commit is contained in:
@@ -13,9 +13,11 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="OpenAI" Version="2.2.0-beta.2" />
|
||||||
<PackageReference Include="RabbitMQ.Client" Version="7.1.1" />
|
<PackageReference Include="RabbitMQ.Client" Version="7.1.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Target Name="GenerateNSwagClient" BeforeTargets="Build">
|
<Target Name="GenerateNSwagClient" BeforeTargets="BeforeBuild">
|
||||||
<Exec Command="$(NSwagExe_Net80) run nswag.json" />
|
<Exec Command="$(NSwagExe_Net80) run nswag.gitea.json" />
|
||||||
|
<Exec Command="$(NSwagExe_Net80) run nswag.youtrack.json" />
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
100
nswag.youtrack.json
Normal file
100
nswag.youtrack.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
using System.Net;
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Alchegos.Core.Services.Gitea;
|
namespace Alchegos.Core.Services.Gitea;
|
||||||
|
|
||||||
public partial class GiteaApiClient
|
public partial class GiteaApiClient
|
||||||
{
|
{
|
||||||
private GiteaApiOptions Options;
|
private GiteaApiOptions Options { get; set; }
|
||||||
|
|
||||||
public GiteaApiClient(HttpClient client, IOptions<GiteaApiOptions> options)
|
public GiteaApiClient(HttpClient client, IOptions<GiteaApiOptions> options)
|
||||||
{
|
{
|
||||||
|
|||||||
6
src/Services/RabbitMQ/IRabbitSubscriber.cs
Normal file
6
src/Services/RabbitMQ/IRabbitSubscriber.cs
Normal 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);
|
||||||
|
}
|
||||||
35
src/Services/RabbitMQ/RabbitSubscriber.cs
Normal file
35
src/Services/RabbitMQ/RabbitSubscriber.cs
Normal 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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/Services/Youtrack/YoutrackApiClient.Extension.cs
Normal file
16
src/Services/Youtrack/YoutrackApiClient.Extension.cs
Normal 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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
7
src/Services/Youtrack/YoutrackApiOptions.cs
Normal file
7
src/Services/Youtrack/YoutrackApiOptions.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Alchegos.Core.Services.Youtrack;
|
||||||
|
|
||||||
|
public class YoutrackApiOptions
|
||||||
|
{
|
||||||
|
public string BaseUrl { get; set; }
|
||||||
|
public string Token { get; set; }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user