Skip to content

Commit

Permalink
Test lower dotnet
Browse files Browse the repository at this point in the history
  • Loading branch information
gizdatullin committed Nov 14, 2024
1 parent c9819fa commit 08f73ef
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 36 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ dotnet_diagnostic.IDE0130.severity = none
# IDE0220 'foreach' statement implicitly converts 'object' to '{1}'. Add an explicit cast to make intent clearer, as it may fail at runtime
dotnet_diagnostic.IDE0220.severity = none

# JSON002 Enable json support
# IDE0220 Use range operator
dotnet_diagnostic.IDE0057.severity = none

# IDE0057 Enable json support
dotnet_diagnostic.JSON002.severity = none

# Naming convention - Private and internal fields should start with _ and be camelCased
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Authors>Mindbox</Authors>
<Copyright>Copyright 2024 © Mindbox</Copyright>
Expand Down
16 changes: 8 additions & 8 deletions Mindbox.YandexTracker.Abstractions/Dtos/CustomFieldDtos.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2024 Mindbox Ltd
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -31,13 +31,13 @@ public record CustomFieldsRequest
/// </remarks>
public bool TryGetCustomField<T>(string customFieldId, out T? value)
{
ArgumentException.ThrowIfNullOrWhiteSpace(customFieldId);
ArgumentException.ThrowIfNullOrEmpty(customFieldId);
return CustomFieldsHelper.TryGetCustomField(Fields, customFieldId, out value);
}

public T GetCustomField<T>(string customFieldId)
{
ArgumentException.ThrowIfNullOrWhiteSpace(customFieldId);
ArgumentException.ThrowIfNullOrEmpty(customFieldId);
return CustomFieldsHelper.GetCustomField<T>(Fields, customFieldId);
}

Expand All @@ -47,7 +47,7 @@ public T GetCustomField<T>(string customFieldId)
/// </remarks>
public void SetCustomField<T>(string customFieldId, T value)
{
ArgumentException.ThrowIfNullOrWhiteSpace(customFieldId);
ArgumentException.ThrowIfNullOrEmpty(customFieldId);
CustomFieldsHelper.SetCustomField(Fields, customFieldId, value);
}
}
Expand All @@ -64,13 +64,13 @@ public record CustomFieldsResponse
/// </remarks>
public bool TryGetCustomField<T>(string customFieldId, out T? value)
{
ArgumentException.ThrowIfNullOrWhiteSpace(customFieldId);
ArgumentException.ThrowIfNullOrEmpty(customFieldId);
return CustomFieldsHelper.TryGetCustomField(Fields, customFieldId, out value);
}

public T GetCustomField<T>(string customFieldId)
{
ArgumentException.ThrowIfNullOrWhiteSpace(customFieldId);
ArgumentException.ThrowIfNullOrEmpty(customFieldId);
return CustomFieldsHelper.GetCustomField<T>(Fields, customFieldId);
}
}
10 changes: 5 additions & 5 deletions Mindbox.YandexTracker.Abstractions/Dtos/CustomFieldsHelper.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2024 Mindbox Ltd
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -25,7 +25,7 @@ public static bool TryGetCustomField<T>(
string customFieldId,
out T? customField)
{
ArgumentException.ThrowIfNullOrWhiteSpace(customFieldId);
ArgumentException.ThrowIfNullOrEmpty(customFieldId);

customField = default;
if (fields.TryGetValue(customFieldId, out var value))
Expand All @@ -49,7 +49,7 @@ public static T GetCustomField<T>(IDictionary<string, JsonElement> fields, strin

public static void SetCustomField<T>(IDictionary<string, JsonElement> fields, string customFieldId, T value)
{
ArgumentException.ThrowIfNullOrWhiteSpace(customFieldId);
ArgumentException.ThrowIfNullOrEmpty(customFieldId);

fields[customFieldId] = JsonSerializer.SerializeToElement(value);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
Expand Down
1 change: 0 additions & 1 deletion Mindbox.YandexTracker/Mindbox.YandexTracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
</ItemGroup>
Expand Down
80 changes: 60 additions & 20 deletions Mindbox.YandexTracker/YandexTrackerClient.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2024 Mindbox Ltd
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -21,11 +21,11 @@
using System.Net.Http.Headers;
using System.Reflection;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Options;
using Mindbox.YandexTracker.JsonConverters;

Expand Down Expand Up @@ -96,7 +96,7 @@ public async Task<GetQueuesResponse> GetQueueAsync(
QueueExpandData? expand = null,
CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(queueKey);
ArgumentException.ThrowIfNullOrEmpty(queueKey);

var parameters = new Dictionary<string, string>();

Expand Down Expand Up @@ -140,7 +140,7 @@ public async Task<GetIssueResponse> GetIssueAsync(
IssueExpandData? expand = null,
CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(issueKey);
ArgumentException.ThrowIfNullOrEmpty(issueKey);

var parameters = new Dictionary<string, string>();

Expand All @@ -164,7 +164,7 @@ public async Task<YandexTrackerCollectionResponse<GetIssueResponse>> GetIssuesFr
PaginationSettings? paginationSettings = null,
CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(queueKey);
ArgumentException.ThrowIfNullOrEmpty(queueKey);

var parameters = new Dictionary<string, string>();

Expand Down Expand Up @@ -249,7 +249,7 @@ public async Task<YandexTrackerCollectionResponse<GetIssueResponse>> GetIssuesBy
PaginationSettings? paginationSettings = null,
CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(query);
ArgumentException.ThrowIfNullOrEmpty(query);

var parameters = new Dictionary<string, string>();

Expand Down Expand Up @@ -320,7 +320,7 @@ public async Task<YandexTrackerCollectionResponse<GetCommentsResponse>> GetComme
PaginationSettings? paginationSettings = null,
CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(issueKey);
ArgumentException.ThrowIfNullOrEmpty(issueKey);

var parameters = new Dictionary<string, string>();

Expand All @@ -344,7 +344,7 @@ public async Task<CreateCommentResponse> CreateCommentAsync(
bool? addAuthorToFollowers = null,
CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(issueKey);
ArgumentException.ThrowIfNullOrEmpty(issueKey);
ArgumentNullException.ThrowIfNull(request);

var parameters = new Dictionary<string, string>();
Expand All @@ -368,7 +368,7 @@ public async Task<YandexTrackerCollectionResponse<GetAttachmentResponse>> GetAtt
PaginationSettings? paginationSettings = null,
CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(issueKey);
ArgumentException.ThrowIfNullOrEmpty(issueKey);

return await ExecuteYandexTrackerCollectionRequestAsync<GetAttachmentResponse>(
$"issues/{issueKey}/attachments",
Expand All @@ -384,7 +384,7 @@ public async Task<CreateAttachmentResponse> CreateAttachmentAsync(
string? newFileName = null,
CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(issueKey);
ArgumentException.ThrowIfNullOrEmpty(issueKey);
ArgumentNullException.ThrowIfNull(fileStream);

var parameters = new Dictionary<string, string>();
Expand Down Expand Up @@ -429,7 +429,7 @@ public async Task<YandexTrackerCollectionResponse<string>> GetTagsAsync(
PaginationSettings? paginationSettings = null,
CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(queueKey);
ArgumentException.ThrowIfNullOrEmpty(queueKey);

return await ExecuteYandexTrackerCollectionRequestAsync<string>(
$"queues/{queueKey}/tags",
Expand Down Expand Up @@ -527,7 +527,7 @@ public async Task<YandexTrackerCollectionResponse<GetIssueFieldsResponse>> GetLo
PaginationSettings? paginationSettings = null,
CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(queueKey);
ArgumentException.ThrowIfNullOrEmpty(queueKey);

return await ExecuteYandexTrackerCollectionRequestAsync<GetIssueFieldsResponse>(
$"queues/{queueKey}/localFields",
Expand Down Expand Up @@ -624,7 +624,7 @@ public async Task<CreateQueueLocalFieldResponse> CreateLocalFieldInQueueAsync(
CreateQueueLocalFieldRequest request,
CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(queueKey);
ArgumentException.ThrowIfNullOrEmpty(queueKey);
ArgumentNullException.ThrowIfNull(request);

return await ExecuteYandexTrackerApiRequestAsync<CreateQueueLocalFieldResponse>(
Expand Down Expand Up @@ -663,7 +663,7 @@ public async Task<CreateQueueResponse> CreateQueueAsync(
/// <inheritdoc />
public async Task DeleteQueueAsync(string queueKey, CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(queueKey);
ArgumentException.ThrowIfNullOrEmpty(queueKey);

await ExecuteYandexTrackerApiRequestAsync(
$"queues/{queueKey}",
Expand All @@ -678,7 +678,7 @@ public async Task DeleteCommentAsync(
int commentId,
CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(issueKey);
ArgumentException.ThrowIfNullOrEmpty(issueKey);

await ExecuteYandexTrackerApiRequestAsync(
$"issues/{issueKey}/comments/{commentId}",
Expand All @@ -690,8 +690,8 @@ await ExecuteYandexTrackerApiRequestAsync(
/// <inheritdoc />
public async Task DeleteAttachmentAsync(string issueKey, string attachmentKey, CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(issueKey);
ArgumentException.ThrowIfNullOrWhiteSpace(attachmentKey);
ArgumentException.ThrowIfNullOrEmpty(issueKey);
ArgumentException.ThrowIfNullOrEmpty(attachmentKey);

await ExecuteYandexTrackerApiRequestAsync(
$"issues/{issueKey}/attachments/{attachmentKey}",
Expand Down Expand Up @@ -756,7 +756,7 @@ private async Task<HttpResponseMessage> ExecuteYandexTrackerApiRawRequestAsync(
var requestUri = new Uri(baseAddress, effectivePath);
if (parameters is not null)
{
requestUri = new Uri(QueryHelpers.AddQueryString(requestUri.ToString(), parameters!));
requestUri = new Uri(AddQueryString(requestUri.ToString(), parameters!));
}

using var request = new HttpRequestMessage(method, requestUri);
Expand Down Expand Up @@ -879,6 +879,46 @@ private async Task ExecuteYandexTrackerApiRequestAsync(
cancellationToken);
}

private static string AddQueryString(
string uri,
IEnumerable<KeyValuePair<string, string?>> queryString)
{
ArgumentNullException.ThrowIfNull(uri);
ArgumentNullException.ThrowIfNull(queryString);

var anchorIndex = uri.IndexOf('#', StringComparison.Ordinal);
var uriToBeAppended = uri.AsSpan();
var anchorText = ReadOnlySpan<char>.Empty;
// If there is an anchor, then the query string must be inserted before its first occurrence.
if (anchorIndex != -1)
{
anchorText = uriToBeAppended.Slice(anchorIndex);
uriToBeAppended = uriToBeAppended.Slice(0, anchorIndex);
}

var queryIndex = uriToBeAppended.IndexOf('?');
var hasQuery = queryIndex != -1;

var sb = new StringBuilder();
sb.Append(uriToBeAppended);
foreach (var parameter in queryString)
{
if (parameter.Value == null)
{
continue;
}

sb.Append(hasQuery ? '&' : '?');
sb.Append(UrlEncoder.Default.Encode(parameter.Key));
sb.Append('=');
sb.Append(UrlEncoder.Default.Encode(parameter.Value));
hasQuery = true;
}

sb.Append(anchorText);
return sb.ToString();
}

public void Dispose()
{
_httpClient.Dispose();
Expand Down

0 comments on commit 08f73ef

Please sign in to comment.