From a7890ebdcc10d2a9cfc7692fde322c335311927b Mon Sep 17 00:00:00 2001 From: Coen van den Munckhof Date: Sat, 12 Aug 2023 21:37:53 +0200 Subject: [PATCH] Remove obsolete config --- src/RepoM.Api/Common/AppSettings.cs | 23 ---- .../Common/FileAppSettingsService.cs | 120 ------------------ src/RepoM.Api/Common/IAppSettingsService.cs | 9 -- .../AzureDevOpsPackage.cs | 31 +---- .../SonarCloudPackage.cs | 28 +--- .../AzureDevOpsPackageTests.cs | 29 ----- ...entationGeneration_AppSettings.verified.md | 2 - ....AppSettingsJsonFileGeneration.verified.md | 2 - .../Configuration/DocsAppSettingsTests.cs | 10 -- .../SonarCloudPackageTest.cs | 28 ---- 10 files changed, 2 insertions(+), 280 deletions(-) diff --git a/src/RepoM.Api/Common/AppSettings.cs b/src/RepoM.Api/Common/AppSettings.cs index da02207e..64d6e3e7 100644 --- a/src/RepoM.Api/Common/AppSettings.cs +++ b/src/RepoM.Api/Common/AppSettings.cs @@ -57,18 +57,6 @@ public sealed class AppSettings [UiConfigured] public List EnabledSearchProviders { get; set; } = new(); - /// - /// SonarCloud PAT. - /// - [Obsolete("This is done using plugin.")] - public string? SonarCloudPersonalAccessToken { get; set; } = string.Empty; - - /// - /// Azure DevOps config. - /// - [Obsolete("This is done using plugin.")] - public AzureDevOpsOptions? AzureDevOps { get; set; } = AzureDevOpsOptions.Default; - /// /// List of plugins. /// @@ -82,8 +70,6 @@ public sealed class AppSettings MenuSize = Size.Default, ReposRootDirectories = new(), EnabledSearchProviders = new List(1), - SonarCloudPersonalAccessToken = null, - AzureDevOps = AzureDevOpsOptions.Default, Plugins = new List(), }; } @@ -94,15 +80,6 @@ public sealed class UiConfiguredAttribute : Attribute { } [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] public sealed class ManualConfiguredAttribute : Attribute { } -public class AzureDevOpsOptions -{ - public string? PersonalAccessToken { get; set; } = string.Empty; - - public string? BaseUrl { get; set; } = string.Empty; - - public static AzureDevOpsOptions? Default => null; -} - public class Size { public double Height { get; set; } diff --git a/src/RepoM.Api/Common/FileAppSettingsService.cs b/src/RepoM.Api/Common/FileAppSettingsService.cs index a64c1d6e..149bda62 100644 --- a/src/RepoM.Api/Common/FileAppSettingsService.cs +++ b/src/RepoM.Api/Common/FileAppSettingsService.cs @@ -235,126 +235,6 @@ public List EnabledSearchProviders } } - [Obsolete("Will be removed in next big version")] - public string SonarCloudPersonalAccessToken - { - get => Settings.SonarCloudPersonalAccessToken ?? string.Empty; - set - { - if (string.IsNullOrWhiteSpace(value)) - { - if (Settings.SonarCloudPersonalAccessToken == null) - { - return; - } - - Settings.SonarCloudPersonalAccessToken = null; - } - else - { - if (value.Equals(Settings.SonarCloudPersonalAccessToken, StringComparison.InvariantCulture)) - { - return; - } - - Settings.SonarCloudPersonalAccessToken = value; - } - - NotifyChange(); - Save(); - } - } - - [Obsolete("Will be removed in next big version")] - public string AzureDevOpsPersonalAccessToken - { - get => Settings.AzureDevOps?.PersonalAccessToken ?? string.Empty; - set - { - if (string.IsNullOrWhiteSpace(value)) - { - if (Settings.AzureDevOps == null) - { - return; - } - - if (string.IsNullOrWhiteSpace(Settings.AzureDevOps.PersonalAccessToken)) - { - return; - } - - Settings.AzureDevOps.PersonalAccessToken = null; - - if (Settings.AzureDevOps.BaseUrl == null) - { - Settings.AzureDevOps = null; - } - } - else - { - if (Settings.AzureDevOps == null) - { - Settings.AzureDevOps = new AzureDevOpsOptions { PersonalAccessToken = value, }; - } - else - { - if (value.Equals(Settings.AzureDevOps.PersonalAccessToken, StringComparison.InvariantCulture)) - { - return; - } - } - } - - NotifyChange(); - Save(); - } - } - - [Obsolete("Will be removed in next big version")] - public string AzureDevOpsBaseUrl - { - get => Settings.AzureDevOps?.BaseUrl ?? string.Empty; - set - { - if (string.IsNullOrWhiteSpace(value)) - { - if (Settings.AzureDevOps == null) - { - return; - } - - if (string.IsNullOrWhiteSpace(Settings.AzureDevOps.BaseUrl)) - { - return; - } - - Settings.AzureDevOps.BaseUrl = null; - - if (Settings.AzureDevOps.PersonalAccessToken == null) - { - Settings.AzureDevOps = null; - } - } - else - { - if (Settings.AzureDevOps == null) - { - Settings.AzureDevOps = new AzureDevOpsOptions { BaseUrl = value, }; - } - else - { - if (value.Equals(Settings.AzureDevOps.BaseUrl, StringComparison.InvariantCulture)) - { - return; - } - } - } - - NotifyChange(); - Save(); - } - } - public List Plugins { get => _plugins ??= Convert(Settings.Plugins); diff --git a/src/RepoM.Api/Common/IAppSettingsService.cs b/src/RepoM.Api/Common/IAppSettingsService.cs index 82b31647..6b6fd51c 100644 --- a/src/RepoM.Api/Common/IAppSettingsService.cs +++ b/src/RepoM.Api/Common/IAppSettingsService.cs @@ -30,15 +30,6 @@ public interface IAppSettingsService List EnabledSearchProviders { get; set; } - [Obsolete("Will be removed in next big version")] - string SonarCloudPersonalAccessToken { get; set; } - - [Obsolete("Will be removed in next big version")] - string AzureDevOpsPersonalAccessToken { get; set; } - - [Obsolete("Will be removed in next big version")] - string AzureDevOpsBaseUrl { get; set; } - string SortKey { get; set; } string QueryParserKey { get; set; } diff --git a/src/RepoM.Plugin.AzureDevOps/AzureDevOpsPackage.cs b/src/RepoM.Plugin.AzureDevOps/AzureDevOpsPackage.cs index 725d54e7..d34457ea 100644 --- a/src/RepoM.Plugin.AzureDevOps/AzureDevOpsPackage.cs +++ b/src/RepoM.Plugin.AzureDevOps/AzureDevOpsPackage.cs @@ -2,7 +2,6 @@ namespace RepoM.Plugin.AzureDevOps; using System.Threading.Tasks; using JetBrains.Annotations; -using RepoM.Api.Common; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; using RepoM.Core.Plugin; @@ -40,35 +39,7 @@ private async Task ExtractAndRegisterConfiguration(Container container, IPackage config = await PersistDefaultConfigAsync(packageConfiguration).ConfigureAwait(false); } - // this is temporarly to support the old way of storing the configuration - if (string.IsNullOrWhiteSpace(config.BaseUrl) && string.IsNullOrWhiteSpace(config.PersonalAccessToken)) - { - container.RegisterSingleton(() => - { - IAppSettingsService appSettingsService = container.GetInstance(); - - var c = new AzureDevopsConfigV1 - { - PersonalAccessToken = appSettingsService.AzureDevOpsPersonalAccessToken, - BaseUrl = appSettingsService.AzureDevOpsBaseUrl, - }; - _ = packageConfiguration.PersistConfigurationAsync(c, CurrentConfigVersion.VERSION); // do not await - - return new AzureDevopsConfiguration(c.BaseUrl, c.PersonalAccessToken); - }); - } - else - { - container.RegisterSingleton(() => - { - IAppSettingsService appSettingsService = container.GetInstance(); - - appSettingsService.AzureDevOpsBaseUrl = "This value has been copied to the new configuration file for this module."; - appSettingsService.AzureDevOpsPersonalAccessToken = "This value has been copied to the new configuration file for this module."; - - return new AzureDevopsConfiguration(config.BaseUrl, config.PersonalAccessToken); - }); - } + container.RegisterInstance(new AzureDevopsConfiguration(config.BaseUrl, config.PersonalAccessToken)); } private static void RegisterServices(Container container) diff --git a/src/RepoM.Plugin.SonarCloud/SonarCloudPackage.cs b/src/RepoM.Plugin.SonarCloud/SonarCloudPackage.cs index 794bdbcc..a3a6164f 100644 --- a/src/RepoM.Plugin.SonarCloud/SonarCloudPackage.cs +++ b/src/RepoM.Plugin.SonarCloud/SonarCloudPackage.cs @@ -3,7 +3,6 @@ namespace RepoM.Plugin.SonarCloud; using System.Threading.Tasks; using ExpressionStringEvaluator.Methods; using JetBrains.Annotations; -using RepoM.Api.Common; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider; using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; using RepoM.Core.Plugin; @@ -36,32 +35,7 @@ private static async Task ExtractAndRegisterConfiguration(Container container, I config = await PersistDefaultConfigAsync(packageConfiguration).ConfigureAwait(false); } - // this is temporarly to support the old way of storing the configuration - if (string.IsNullOrWhiteSpace(config.PersonalAccessToken)) - { - container.RegisterSingleton(() => - { - IAppSettingsService appSettingsService = container.GetInstance(); - - var c = new SonarCloudConfigV1 - { - PersonalAccessToken = appSettingsService.SonarCloudPersonalAccessToken, - BaseUrl = config.BaseUrl, - }; - _ = packageConfiguration.PersistConfigurationAsync(c, CurrentConfigVersion.VERSION); // fire and forget ;-) - - return new SonarCloudConfiguration(c.BaseUrl, c.PersonalAccessToken); - }); - } - else - { - container.RegisterSingleton(() => - { - IAppSettingsService appSettingsService = container.GetInstance(); - appSettingsService.SonarCloudPersonalAccessToken = "This value has been copied to the new configuration file for this module."; - return new SonarCloudConfiguration(config.BaseUrl, config.PersonalAccessToken); - }); - } + container.RegisterSingleton(() => new SonarCloudConfiguration(config.BaseUrl, config.PersonalAccessToken)); } private static void RegisterServices(Container container) diff --git a/tests/RepoM.Plugin.AzureDevOps.Tests/AzureDevOpsPackageTests.cs b/tests/RepoM.Plugin.AzureDevOps.Tests/AzureDevOpsPackageTests.cs index baf336f8..54c6aa4e 100644 --- a/tests/RepoM.Plugin.AzureDevOps.Tests/AzureDevOpsPackageTests.cs +++ b/tests/RepoM.Plugin.AzureDevOps.Tests/AzureDevOpsPackageTests.cs @@ -34,9 +34,6 @@ public AzureDevOpsPackageTests() A.CallTo(() => _packageConfiguration.GetConfigurationVersionAsync()).Returns(Task.FromResult(1 as int?)); A.CallTo(() => _packageConfiguration.LoadConfigurationAsync()).ReturnsLazily(() => azureDevopsConfigV1); A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A._, 1)).Returns(Task.CompletedTask); - - A.CallTo(() => _appSettingsService.AzureDevOpsBaseUrl).Returns("https://dev.azure.com/MyOrg123ABC"); - A.CallTo(() => _appSettingsService.AzureDevOpsPersonalAccessToken).Returns("MY_TEST_PAT"); } [Fact] @@ -75,32 +72,6 @@ public async Task RegisterServices_ShouldPersistNewConfig_WhenVersionIsNotCorrec _container.Verify(VerificationOption.VerifyAndDiagnose); } - [Theory] - [InlineData(null)] - [InlineData(2)] - [InlineData(10)] - public async Task RegisterServices_ShouldCopyExistingAppSettingsConfig_WhenNoCurrentCorrectConfig(int? version) - { - // arrange - AzureDevopsConfigV1? persistedConfig = null; - A.CallTo(() => _packageConfiguration.GetConfigurationVersionAsync()).Returns(Task.FromResult(version)); - RegisterExternals(_container); - var sut = new AzureDevOpsPackage(); - await sut.RegisterServicesAsync(_container, _packageConfiguration); - - Fake.ClearRecordedCalls(_packageConfiguration); - A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A._, 1)) - .Invokes(call => persistedConfig = call.Arguments[0] as AzureDevopsConfigV1); - - // act - // make sure everyting is resolved. This will trigger the copy of the config. - _container.Verify(VerificationOption.VerifyAndDiagnose); - - // assert - A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A._, 1)).MustHaveHappenedOnceExactly(); - await Verifier.Verify(persistedConfig).IgnoreParametersForVerified(nameof(version)); - } - [Fact] public async Task RegisterServices_ShouldFail_WhenExternalDependenciesAreNotRegistered() { diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.AppSettingsDocumentationGeneration_AppSettings.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.AppSettingsDocumentationGeneration_AppSettings.verified.md index a46ee51b..c847436d 100644 --- a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.AppSettingsDocumentationGeneration_AppSettings.verified.md +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.AppSettingsDocumentationGeneration_AppSettings.verified.md @@ -8,6 +8,4 @@ - `MenuSize`: The menu size of RepoM. This is set when the window is resized. (optional, UI configured) - `ReposRootDirectories`: List of root directories where RepoM will search for git repositories. If null or empty, all fixed drives will be searched from the root. (optional, Manual configured) - `EnabledSearchProviders`: List of search providers. Search providers can be added by plugins. (optional, UI configured) -- `SonarCloudPersonalAccessToken`: SonarCloud PAT. (Obsolete, moved to plugin config) -- `AzureDevOps`: Azure DevOps config. (Obsolete, moved to plugin config) - `Plugins`: List of plugins. (optional, UI configured) diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.AppSettingsJsonFileGeneration.verified.md b/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.AppSettingsJsonFileGeneration.verified.md index 3b39b05a..d49b23d4 100644 --- a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.AppSettingsJsonFileGeneration.verified.md +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.AppSettingsJsonFileGeneration.verified.md @@ -15,8 +15,6 @@ This is the default configuration. }, "ReposRootDirectories": [], "EnabledSearchProviders": [], - "SonarCloudPersonalAccessToken": null, - "AzureDevOps": null, "Plugins": [] } ``` diff --git a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.cs b/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.cs index 1a15dedc..f21ac8b6 100644 --- a/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.cs +++ b/tests/RepoM.Plugin.Misc.Tests/Configuration/DocsAppSettingsTests.cs @@ -1,9 +1,6 @@ namespace RepoM.Plugin.Misc.Tests.Configuration; -using System; -using System.Collections.Generic; using System.IO.Abstractions.TestingHelpers; -using System.Reflection; using System.Text; using System.Threading.Tasks; using FakeItEasy; @@ -11,15 +8,11 @@ namespace RepoM.Plugin.Misc.Tests.Configuration; using Microsoft.Extensions.Logging.Abstractions; using NuDoq; using RepoM.Api.Common; -using RepoM.Api.Plugins; -using RepoM.Core.Plugin; using RepoM.Core.Plugin.Common; -using RepoM.Plugin.Misc.Tests.TestFramework.AssemblyAndTypeHelpers; using RepoM.Plugin.Misc.Tests.TestFramework.NuDoc; using VerifyTests; using VerifyXunit; using Xunit; -using YamlDotNet.Serialization; [UsesVerify] public class DocsAppSettingsTests @@ -41,9 +34,6 @@ public DocsAppSettingsTests() _fileBasedPackageConfiguration = new FileAppSettingsService(_appDataPathProvider, _fileSystem, _logger); } - // FileAppSettingsService - - [Fact] public async Task AppSettingsJsonFileGeneration() { diff --git a/tests/RepoM.Plugin.SonarCloud.Tests/SonarCloudPackageTest.cs b/tests/RepoM.Plugin.SonarCloud.Tests/SonarCloudPackageTest.cs index fa8da3af..a539a730 100644 --- a/tests/RepoM.Plugin.SonarCloud.Tests/SonarCloudPackageTest.cs +++ b/tests/RepoM.Plugin.SonarCloud.Tests/SonarCloudPackageTest.cs @@ -32,8 +32,6 @@ public SonarCloudPackageTest() A.CallTo(() => _packageConfiguration.GetConfigurationVersionAsync()).Returns(Task.FromResult(1 as int?)); A.CallTo(() => _packageConfiguration.LoadConfigurationAsync()).ReturnsLazily(() => sonarCloudConfigV1); A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A._, 1)).Returns(Task.CompletedTask); - - A.CallTo(() => _appSettingsService.SonarCloudPersonalAccessToken).Returns("MY_TEST_PAT_SONAR"); } [Fact] @@ -72,32 +70,6 @@ public async Task RegisterServices_ShouldPersistNewConfig_WhenVersionIsNotCorrec _container.Verify(VerificationOption.VerifyAndDiagnose); } - [Theory] - [InlineData(null)] - [InlineData(2)] - [InlineData(10)] - public async Task RegisterServices_ShouldCopyExistingAppSettingsConfig_WhenNoCurrentCorrectConfig(int? version) - { - // arrange - SonarCloudConfigV1? persistedConfig = null; - A.CallTo(() => _packageConfiguration.GetConfigurationVersionAsync()).Returns(Task.FromResult(version)); - RegisterExternals(_container); - var sut = new SonarCloudPackage(); - await sut.RegisterServicesAsync(_container, _packageConfiguration); - - Fake.ClearRecordedCalls(_packageConfiguration); - A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A._, 1)) - .Invokes(call => persistedConfig = call.Arguments[0] as SonarCloudConfigV1); - - // act - // make sure everyting is resolved. This will trigger the copy of the config. - _container.Verify(VerificationOption.VerifyAndDiagnose); - - // assert - A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A._, 1)).MustHaveHappenedOnceExactly(); - await Verifier.Verify(persistedConfig).IgnoreParametersForVerified(nameof(version)); - } - [Fact] public async Task RegisterServices_ShouldFail_WhenExternalDependenciesAreNotRegistered() {