Skip to content

Commit

Permalink
Remove obsolete config
Browse files Browse the repository at this point in the history
  • Loading branch information
coenm committed Aug 12, 2023
1 parent 29322b9 commit a7890eb
Show file tree
Hide file tree
Showing 10 changed files with 2 additions and 280 deletions.
23 changes: 0 additions & 23 deletions src/RepoM.Api/Common/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,6 @@ public sealed class AppSettings
[UiConfigured]
public List<string> EnabledSearchProviders { get; set; } = new();

/// <summary>
/// SonarCloud PAT.
/// </summary>
[Obsolete("This is done using plugin.")]
public string? SonarCloudPersonalAccessToken { get; set; } = string.Empty;

/// <summary>
/// Azure DevOps config.
/// </summary>
[Obsolete("This is done using plugin.")]
public AzureDevOpsOptions? AzureDevOps { get; set; } = AzureDevOpsOptions.Default;

/// <summary>
/// List of plugins.
/// </summary>
Expand All @@ -82,8 +70,6 @@ public sealed class AppSettings
MenuSize = Size.Default,
ReposRootDirectories = new(),
EnabledSearchProviders = new List<string>(1),
SonarCloudPersonalAccessToken = null,
AzureDevOps = AzureDevOpsOptions.Default,
Plugins = new List<PluginOptions>(),
};
}
Expand All @@ -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; }
Expand Down
120 changes: 0 additions & 120 deletions src/RepoM.Api/Common/FileAppSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,126 +235,6 @@ public List<string> 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<PluginSettings> Plugins
{
get => _plugins ??= Convert(Settings.Plugins);
Expand Down
9 changes: 0 additions & 9 deletions src/RepoM.Api/Common/IAppSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ public interface IAppSettingsService

List<string> 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; }
Expand Down
31 changes: 1 addition & 30 deletions src/RepoM.Plugin.AzureDevOps/AzureDevOpsPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IAzureDevopsConfiguration>(() =>
{
IAppSettingsService appSettingsService = container.GetInstance<IAppSettingsService>();
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<IAzureDevopsConfiguration>(() =>
{
IAppSettingsService appSettingsService = container.GetInstance<IAppSettingsService>();
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<IAzureDevopsConfiguration>(new AzureDevopsConfiguration(config.BaseUrl, config.PersonalAccessToken));
}

private static void RegisterServices(Container container)
Expand Down
28 changes: 1 addition & 27 deletions src/RepoM.Plugin.SonarCloud/SonarCloudPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ISonarCloudConfiguration>(() =>
{
IAppSettingsService appSettingsService = container.GetInstance<IAppSettingsService>();
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<ISonarCloudConfiguration>(() =>
{
IAppSettingsService appSettingsService = container.GetInstance<IAppSettingsService>();
appSettingsService.SonarCloudPersonalAccessToken = "This value has been copied to the new configuration file for this module.";
return new SonarCloudConfiguration(config.BaseUrl, config.PersonalAccessToken);
});
}
container.RegisterSingleton<ISonarCloudConfiguration>(() => new SonarCloudConfiguration(config.BaseUrl, config.PersonalAccessToken));
}

private static void RegisterServices(Container container)
Expand Down
29 changes: 0 additions & 29 deletions tests/RepoM.Plugin.AzureDevOps.Tests/AzureDevOpsPackageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public AzureDevOpsPackageTests()
A.CallTo(() => _packageConfiguration.GetConfigurationVersionAsync()).Returns(Task.FromResult(1 as int?));
A.CallTo(() => _packageConfiguration.LoadConfigurationAsync<AzureDevopsConfigV1>()).ReturnsLazily(() => azureDevopsConfigV1);
A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A<AzureDevopsConfigV1>._, 1)).Returns(Task.CompletedTask);

A.CallTo(() => _appSettingsService.AzureDevOpsBaseUrl).Returns("https://dev.azure.com/MyOrg123ABC");
A.CallTo(() => _appSettingsService.AzureDevOpsPersonalAccessToken).Returns("MY_TEST_PAT");
}

[Fact]
Expand Down Expand Up @@ -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<AzureDevopsConfigV1>._, 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<AzureDevopsConfigV1>._, 1)).MustHaveHappenedOnceExactly();
await Verifier.Verify(persistedConfig).IgnoreParametersForVerified(nameof(version));
}

[Fact]
public async Task RegisterServices_ShouldFail_WhenExternalDependenciesAreNotRegistered()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. (<span style="color: red;">Obsolete, moved to plugin config</span>)
- `AzureDevOps`: Azure DevOps config. (<span style="color: red;">Obsolete, moved to plugin config</span>)
- `Plugins`: List of plugins. (optional, UI configured)
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ This is the default configuration.
},
"ReposRootDirectories": [],
"EnabledSearchProviders": [],
"SonarCloudPersonalAccessToken": null,
"AzureDevOps": null,
"Plugins": []
}
```
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
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;
using Microsoft.Extensions.Logging;
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
Expand All @@ -41,9 +34,6 @@ public DocsAppSettingsTests()
_fileBasedPackageConfiguration = new FileAppSettingsService(_appDataPathProvider, _fileSystem, _logger);
}

// FileAppSettingsService


[Fact]
public async Task AppSettingsJsonFileGeneration()
{
Expand Down
Loading

0 comments on commit a7890eb

Please sign in to comment.