Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
KuraiAndras committed Aug 31, 2020
2 parents 887532a + 09bed2f commit 27ab225
Show file tree
Hide file tree
Showing 77 changed files with 274 additions and 169 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
<RepositoryUrl>https://github.com/NuKeeperDotNet/NuKeeper.git</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0" PrivateAssets="All" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace NuKeeper.Abstractions.Tests.Configuration
[TestFixture]
public class FileSettingsReaderTests
{
private string _uniqueTemporaryFolder = null;
private string _uniqueTemporaryFolder;

[SetUp]
public void Setup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions NuKeeper.Abstractions/Configuration/FileSettingsCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ namespace NuKeeper.Abstractions.Configuration
{
public class FileSettingsCache : IFileSettingsCache
{
private readonly FileSettingsReader _reader;
private readonly IFileSettingsReader _reader;
private FileSettings _settings;

public FileSettingsCache(FileSettingsReader reader)
public FileSettingsCache(IFileSettingsReader reader)
{
_reader = reader;
}
Expand Down
2 changes: 1 addition & 1 deletion NuKeeper.Abstractions/Configuration/FileSettingsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace NuKeeper.Abstractions.Configuration
{
public class FileSettingsReader
public class FileSettingsReader : IFileSettingsReader
{
private readonly INuKeeperLogger _logger;

Expand Down
7 changes: 7 additions & 0 deletions NuKeeper.Abstractions/Configuration/IFileSettingsReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace NuKeeper.Abstractions.Configuration
{
public interface IFileSettingsReader
{
FileSettings Read(string folder);
}
}
3 changes: 2 additions & 1 deletion NuKeeper.Abstractions/NuKeeper.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

<ItemGroup>
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="3.0.0" />
<PackageReference Include="NuGet.Protocol" Version="5.6.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.7" />
<PackageReference Include="NuGet.Protocol" Version="5.7.0" />
</ItemGroup>

</Project>
7 changes: 5 additions & 2 deletions NuKeeper.AzureDevOps/AzureDevOpsRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ public class AzureDevOpsRestClient
private readonly HttpClient _client;
private readonly INuKeeperLogger _logger;

public AzureDevOpsRestClient(HttpClient client, INuKeeperLogger logger, string personalAccessToken)
public AzureDevOpsRestClient(IHttpClientFactory clientFactory, INuKeeperLogger logger,
string personalAccessToken, Uri apiBaseAddress)
{
_client = client ?? throw new ArgumentNullException(nameof(client));
_logger = logger;

_client = clientFactory.CreateClient();
_client.BaseAddress = apiBaseAddress;
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
_client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{string.Empty}:{personalAccessToken}")));
Expand Down
10 changes: 4 additions & 6 deletions NuKeeper.AzureDevOps/AzureDevopsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ namespace NuKeeper.AzureDevOps
public class AzureDevOpsPlatform : ICollaborationPlatform
{
private readonly INuKeeperLogger _logger;
private readonly IHttpClientFactory _clientFactory;
private AzureDevOpsRestClient _client;

public AzureDevOpsPlatform(INuKeeperLogger logger)
public AzureDevOpsPlatform(INuKeeperLogger logger, IHttpClientFactory clientFactory)
{
_logger = logger;
_clientFactory = clientFactory;
}

public void Initialise(AuthSettings settings)
Expand All @@ -27,11 +29,7 @@ public void Initialise(AuthSettings settings)
throw new ArgumentNullException(nameof(settings));
}

var httpClient = new HttpClient
{
BaseAddress = settings.ApiBase
};
_client = new AzureDevOpsRestClient(httpClient, _logger, settings.Token);
_client = new AzureDevOpsRestClient(_clientFactory, _logger, settings.Token, settings.ApiBase);
}

public Task<User> GetCurrentUser()
Expand Down
10 changes: 4 additions & 6 deletions NuKeeper.BitBucket/BitbucketPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@ namespace NuKeeper.BitBucket
public class BitbucketPlatform : ICollaborationPlatform
{
private readonly INuKeeperLogger _logger;
private readonly IHttpClientFactory _clientFactory;
private BitbucketRestClient _client;
private AuthSettings _settings;

public BitbucketPlatform(INuKeeperLogger logger)
public BitbucketPlatform(INuKeeperLogger logger, IHttpClientFactory clientFactory)
{
_logger = logger;
_clientFactory = clientFactory;
}

public void Initialise(AuthSettings settings)
{
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
var httpClient = new HttpClient
{
BaseAddress = settings.ApiBase
};
_client = new BitbucketRestClient(httpClient, _logger, settings.Username, settings.Token);
_client = new BitbucketRestClient(_clientFactory, _logger, settings.Username, settings.Token, settings.ApiBase);
}

public Task<User> GetCurrentUser()
Expand Down
6 changes: 4 additions & 2 deletions NuKeeper.BitBucket/BitbucketRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ public class BitbucketRestClient
private readonly HttpClient _client;
private readonly INuKeeperLogger _logger;

public BitbucketRestClient(HttpClient client, INuKeeperLogger logger, string username, string appPassword)
public BitbucketRestClient(IHttpClientFactory clientFactory, INuKeeperLogger logger, string username,
string appPassword, Uri apiBaseAddress)
{
_client = client ?? throw new ArgumentNullException(nameof(client));
_logger = logger;

_client = clientFactory.CreateClient();
_client.BaseAddress = apiBaseAddress;
var byteArray = Encoding.ASCII.GetBytes($"{username}:{appPassword}");
_client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
Expand Down
1 change: 0 additions & 1 deletion NuKeeper.Git.Tests/GitCmdDiscoveryDriverTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NuKeeper.Abstractions.Logging;
using NuKeeper.Git;
using NuKeeper.Inspection.Files;
using NuKeeper.Inspection.Logging;
using NUnit.Framework;
Expand Down
2 changes: 0 additions & 2 deletions NuKeeper.Git.Tests/GitCmdDriverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
using NuKeeper.Inspection.Logging;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

Expand Down
6 changes: 3 additions & 3 deletions NuKeeper.Git.Tests/NuKeeper.Git.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
1 change: 0 additions & 1 deletion NuKeeper.Git/GitCmdDiscoveryDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

Expand Down
1 change: 0 additions & 1 deletion NuKeeper.Git/GitCmdDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using NuKeeper.Abstractions.CollaborationModels;
using NuKeeper.Abstractions.Git;
using NuKeeper.Abstractions.Inspections.Files;
using NuKeeper.Abstractions.Logging;
Expand Down
1 change: 0 additions & 1 deletion NuKeeper.Git/LibGit2SharpDiscoveryDriver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using LibGit2Sharp;
Expand Down
1 change: 0 additions & 1 deletion NuKeeper.Git/LibGit2SharpDriver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using LibGit2Sharp;
Expand Down
2 changes: 1 addition & 1 deletion NuKeeper.Git/NuKeeper.Git.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LibGit2Sharp" Version="0.26.2" />
<PackageReference Include="LibGit2Sharp" Version="0.27.0-preview-0034" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions NuKeeper.GitHub.Tests/NuKeeper.GitHub.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
6 changes: 4 additions & 2 deletions NuKeeper.Gitea.Tests/GiteaSettingsReaderTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using NSubstitute;
using NuKeeper.Abstractions.CollaborationPlatform;
using NuKeeper.Abstractions.Configuration;
using NuKeeper.Abstractions.Git;
using NuKeeper.Gitea;
using NUnit.Framework;

namespace NuKeeper.Gitea.Tests
Expand All @@ -21,7 +21,9 @@ public void Setup()
{
_environmentVariablesProvider = Substitute.For<IEnvironmentVariablesProvider>();
_gitDiscovery = Substitute.For<IGitDiscoveryDriver>();
_giteaSettingsReader = new GiteaSettingsReader(_gitDiscovery, _environmentVariablesProvider);
var httpClientFactory = Substitute.For<IHttpClientFactory>();
httpClientFactory.CreateClient().Returns(new HttpClient());
_giteaSettingsReader = new GiteaSettingsReader(_gitDiscovery, _environmentVariablesProvider, httpClientFactory);
}

[Test]
Expand Down
6 changes: 3 additions & 3 deletions NuKeeper.Gitea.Tests/NuKeeper.Gitea.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
11 changes: 4 additions & 7 deletions NuKeeper.Gitea/GiteaPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ namespace NuKeeper.Gitea
public class GiteaPlatform : ICollaborationPlatform
{
private readonly INuKeeperLogger _logger;
private readonly IHttpClientFactory _clientFactory;
private GiteaRestClient _client;

public GiteaPlatform(INuKeeperLogger logger)
public GiteaPlatform(INuKeeperLogger logger, IHttpClientFactory clientFactory)
{
_logger = logger;
_clientFactory = clientFactory;
}

public void Initialise(AuthSettings settings)
Expand All @@ -28,12 +30,7 @@ public void Initialise(AuthSettings settings)
throw new ArgumentNullException(nameof(settings));
}

var httpClient = new HttpClient
{
BaseAddress = settings.ApiBase
};

_client = new GiteaRestClient(httpClient, settings.Token, _logger);
_client = new GiteaRestClient(_clientFactory, settings.Token, _logger, settings.ApiBase);
}

public async Task<User> GetCurrentUser()
Expand Down
6 changes: 4 additions & 2 deletions NuKeeper.Gitea/GiteaRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ public class GiteaRestClient
private readonly HttpClient _client;
private readonly INuKeeperLogger _logger;

public GiteaRestClient(HttpClient client, string token, INuKeeperLogger logger)
public GiteaRestClient(IHttpClientFactory clientFactory, string token, INuKeeperLogger logger,
Uri apiBaseAddress)
{
_client = client ?? throw new ArgumentNullException(nameof(client));
_logger = logger;

_client = clientFactory.CreateClient();
_client.BaseAddress = apiBaseAddress;
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("token", token);
}
Expand Down
12 changes: 6 additions & 6 deletions NuKeeper.Gitea/GiteaSettingsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ public class GiteaSettingsReader : ISettingsReader
private const string UrlPattern = "https://yourgiteaserver/{owner}/{repo}.git";
private const string ApiBaseAdress = "api/v1/";
private readonly IGitDiscoveryDriver _gitDriver;
private readonly IHttpClientFactory _clientFactory;

public GiteaSettingsReader(IGitDiscoveryDriver gitDiscoveryDriver, IEnvironmentVariablesProvider environmentVariablesProvider)
public GiteaSettingsReader(IGitDiscoveryDriver gitDiscoveryDriver, IEnvironmentVariablesProvider environmentVariablesProvider,
IHttpClientFactory clientFactory)
{
_environmentVariablesProvider = environmentVariablesProvider;
_clientFactory = clientFactory;
_gitDriver = gitDiscoveryDriver;
}

Expand All @@ -34,11 +37,8 @@ public async Task<bool> CanRead(Uri repositoryUri)
try
{
// There is no real identifier for gitea repos so try to get the gitea swagger json
var client = new HttpClient()
{
BaseAddress = GetBaseAddress(repositoryUri)
};

var client = _clientFactory.CreateClient();
client.BaseAddress = GetBaseAddress(repositoryUri);
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));

Expand Down
1 change: 0 additions & 1 deletion NuKeeper.Gitea/Model/PullRequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;

namespace NuKeeper.Gitea.Model
Expand Down
6 changes: 3 additions & 3 deletions NuKeeper.Gitlab.Tests/NuKeeper.Gitlab.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit 27ab225

Please sign in to comment.