diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a40457b..5ea2fa1 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,18 +1,13 @@ -# This is a basic workflow to help you get started with Actions - name: CI -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch +# Controls when the action will run. Triggers the workflow when a release is published on: release: types: [published] # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" publish: - # The type of runner that the job will run on runs-on: windows-latest # Steps represent a sequence of tasks that will be executed as part of the job diff --git a/README.md b/README.md index ca82d52..2a108db 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,39 @@ This extension adds [commitizen](https://github.com/commitizen/) support to Visu - Nice page to format your comment using commitizen fashion. ![vs-commitizen_-_commitizen_view.png](images/commitizen-view.png) + +## Customizations + +The list of "Type of changes" can be customized, globally or per repository. + +The configuration is stored in a *.commitizen.json* file ([schema](./config-schema.json)) + +You can access the configuration file directly from VisualStudio menu (files will be generated if not existing yet) : + + +![menu.png](images/menu.png) + +#### Sample configuration + +```json +{ + "$schema": "https://github.com/MrLuje/vs-commitizen/config-schema.json", + "types": [ + { + "type": "feat", + "description": "A new feature" + }, + { + "type": "fix", + "description": "A bug fix" + }, + { + "type": "docs", + "description": "Documentation only changes" + }, + { + "type": "test", + "description": "Adding missing tests or correcting existing tests" + } +} +``` \ No newline at end of file diff --git a/ViewTest/App.config b/ViewTest/App.config index 8ff0282..9a4fc6e 100644 --- a/ViewTest/App.config +++ b/ViewTest/App.config @@ -4,11 +4,6 @@ - - True - - - True @@ -257,18 +252,13 @@ True - + True - - True - - - True diff --git a/ViewTest/MainWindow.xaml.cs b/ViewTest/MainWindow.xaml.cs index cdfc48e..e2e30f3 100644 --- a/ViewTest/MainWindow.xaml.cs +++ b/ViewTest/MainWindow.xaml.cs @@ -1,4 +1,6 @@ -using System.Windows; +using System.Collections.Generic; +using System.Threading.Tasks; +using System.Windows; using vs_commitizen.Settings; using vs_commitizen.vs.Settings; @@ -12,6 +14,7 @@ public partial class MainWindow : Window public MainWindow() { IoC.Container.Inject(new DummyUserSettings()); + IoC.Container.Inject(new DummyConfigFileProvider()); InitializeComponent(); } @@ -20,5 +23,18 @@ public class DummyUserSettings : IUserSettings { public int MaxLineLength { get; set; } = 80; } + + internal class DummyConfigFileProvider : IConfigFileProvider + { + public Task> GetCommitTypesAsync() where T : class + { + throw new System.NotImplementedException(); + } + + public Task TryGetLocalConfigAsync() + { + throw new System.NotImplementedException(); + } + } } } diff --git a/config-schema.json b/config-schema.json new file mode 100644 index 0000000..1aaba04 --- /dev/null +++ b/config-schema.json @@ -0,0 +1,29 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://github.com/MrLuje/vs-commitizen/config-schema.json", + "title": "Configuration", + "description": "Configuration file for vs-commitizen", + "type": "object", + "properties": { + "types": { + "description": "List of 'type of commit' available", + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "Name of the commit type" + }, + "description": { + "type": "string", + "description": "Optional description for the commit type" + } + }, + "required": [ + "name" + ] + } + } + } +} \ No newline at end of file diff --git a/images/menu.png b/images/menu.png new file mode 100644 index 0000000..822fbf0 Binary files /dev/null and b/images/menu.png differ diff --git a/paket.dependencies b/paket.dependencies index f5a645c..ff9a66e 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -3,15 +3,19 @@ framework: auto-detect nuget Microsoft.AspNet.WebApi.Core 5.2.2 nuget Microsoft.VisualStudio.SDK.Analyzers 15.8.36 -nuget Microsoft.VisualStudio.Services.InteractiveClient 15.112.1 -#nuget Microsoft.VSSDK.BuildTools ~> 14.3 #to debug 2015 exp +# nuget Microsoft.VisualStudio.Services.InteractiveClient 15.112.1 +# nuget Microsoft.VSSDK.BuildTools ~> 14.3 #to debug 2015 exp nuget Microsoft.VSSDK.BuildTools ~> 16.5.2044 #to debug 2017 exp -nuget Newtonsoft.Json 11.0.1 +nuget Microsoft.VisualStudio.Shell.Interop.12.0 ~> 12.0 +nuget Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime +nuget Microsoft.VisualStudio.Threading == 15.8.192 redirects: force, copy_local: false +nuget Newtonsoft.Json 12.0.3 nuget StructureMap 4.6.1 +# nuget System.Runtime 4.3.1 redirects: on nuget AutoFixture.Xunit2 ~> 4.1 nuget AutoFixture.AutoNSubstitute ~> 4.2 -nuget NSubstitute ~> 3.1 +nuget NSubstitute ~> 4.2 nuget Shouldly ~> 3.0 nuget xunit ~> 2.3.1 nuget xunit.runner.visualstudio ~> 2.3.1 version_in_path: true diff --git a/paket.lock b/paket.lock index c8a76be..bf3d423 100644 --- a/paket.lock +++ b/paket.lock @@ -15,64 +15,49 @@ NUGET Newtonsoft.Json (>= 6.0.4) Microsoft.AspNet.WebApi.Core (5.2.2) Microsoft.AspNet.WebApi.Client (>= 5.2.2) - Microsoft.Azure.Services.AppAuthentication (1.4) - Microsoft.IdentityModel.Clients.ActiveDirectory (>= 5.2) - Microsoft.IdentityModel.Clients.ActiveDirectory (5.2.7) - System.Net.Http (>= 4.3.4) - Microsoft.IdentityModel.JsonWebTokens (6.5) - Microsoft.IdentityModel.Tokens (>= 6.5) - Microsoft.IdentityModel.Logging (6.5) - Microsoft.IdentityModel.Tokens (6.5) - Microsoft.IdentityModel.Logging (>= 6.5) - Microsoft.Rest.ClientRuntime (2.3.21) - Newtonsoft.Json (>= 10.0.3) + Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime (14.3.26930) + Microsoft.VisualStudio.SDK.EmbedInteropTypes (>= 15.0.16) + Microsoft.VisualStudio.OLE.Interop (7.10.6071) Microsoft.VisualStudio.SDK.Analyzers (15.8.36) Microsoft.VisualStudio.Threading.Analyzers (>= 15.8.168) - Microsoft.VisualStudio.Services.Client (15.112.1) - Microsoft.AspNet.WebApi.Client (>= 5.2.2) - Newtonsoft.Json (>= 8.0.3) - Microsoft.VisualStudio.Services.InteractiveClient (15.112.1) - Microsoft.AspNet.WebApi.Client (>= 5.2.2) - Microsoft.IdentityModel.Clients.ActiveDirectory (>= 3.13.5) - Microsoft.VisualStudio.Services.Client (15.112.1) - Newtonsoft.Json (>= 8.0.3) - System.IdentityModel.Tokens.Jwt (>= 4.0.2.206221351) - WindowsAzure.ServiceBus (>= 3.3.2) - Microsoft.VisualStudio.Threading.Analyzers (16.6.13) + Microsoft.VisualStudio.SDK.EmbedInteropTypes (15.0.30) + Microsoft.VisualStudio.Shell.Interop (7.10.6072) + Microsoft.VisualStudio.TextManager.Interop (>= 7.10.6071) + Microsoft.VisualStudio.Shell.Interop.10.0 (10.0.30320) + Microsoft.VisualStudio.Shell.Interop.8.0 (>= 8.0.50728) + Microsoft.VisualStudio.Shell.Interop.11.0 (11.0.61031) + Microsoft.VisualStudio.Shell.Interop.10.0 (>= 10.0.30320) + Microsoft.VisualStudio.Shell.Interop.12.0 (12.0.30111) + Microsoft.VisualStudio.Shell.Interop.11.0 (>= 11.0.61031) + Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime (14.3.26929) + Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime (>= 14.3.26930) + Microsoft.VisualStudio.SDK.EmbedInteropTypes (>= 15.0.16) + Microsoft.VisualStudio.Shell.Interop.12.0 (>= 12.0.30111) + Microsoft.VisualStudio.Shell.Interop.8.0 (8.0.50728) + Microsoft.VisualStudio.Shell.Interop (>= 7.10.6072) + Microsoft.VisualStudio.TextManager.Interop.8.0 (>= 8.0.50728) + Microsoft.VisualStudio.TextManager.Interop (7.10.6071) + Microsoft.VisualStudio.OLE.Interop (>= 7.10.6071) + Microsoft.VisualStudio.TextManager.Interop.8.0 (8.0.50728) + Microsoft.VisualStudio.Shell.Interop (>= 7.10.6072) + Microsoft.VisualStudio.Threading (15.8.192) - copy_local: false, redirects: force + Microsoft.VisualStudio.Threading.Analyzers (>= 15.8.192) + Microsoft.VisualStudio.Validation (>= 15.3.15) + Microsoft.VisualStudio.Threading.Analyzers (16.6.13) - copy_local: false, redirects: force + Microsoft.VisualStudio.Validation (15.5.31) - copy_local: false, redirects: force Microsoft.VSSDK.BuildTools (16.5.2044) Microsoft.VisualStudio.SDK.Analyzers (>= 15.8.33) - Newtonsoft.Json (11.0.1) - NSubstitute (3.1) - Castle.Core (>= 4.2) + Newtonsoft.Json (12.0.3) + NSubstitute (4.2.1) + Castle.Core (>= 4.4) System.Threading.Tasks.Extensions (>= 4.3) Shouldly (3.0.2) StructureMap (4.6.1) System.Reflection.Emit.Lightweight (>= 4.3) - System.IdentityModel.Tokens.Jwt (6.5) - Microsoft.IdentityModel.JsonWebTokens (>= 6.5) - Microsoft.IdentityModel.Tokens (>= 6.5) - System.IO (4.3) - System.Net.Http (4.3.4) - System.Security.Cryptography.X509Certificates (>= 4.3) System.Reflection.Emit.Lightweight (4.7) - System.Runtime (4.3.1) System.Runtime.CompilerServices.Unsafe (4.7.1) - System.Security.Cryptography.Algorithms (4.3.1) - System.IO (>= 4.3) - System.Runtime (>= 4.3) - System.Security.Cryptography.Encoding (>= 4.3) - System.Security.Cryptography.Primitives (>= 4.3) - System.Security.Cryptography.Encoding (4.3) - System.Security.Cryptography.Primitives (4.3) - System.Security.Cryptography.X509Certificates (4.3.2) - System.Security.Cryptography.Algorithms (>= 4.3) - System.Security.Cryptography.Encoding (>= 4.3) System.Threading.Tasks.Extensions (4.5.4) System.Runtime.CompilerServices.Unsafe (>= 4.5.3) - WindowsAzure.ServiceBus (6.0.1) - Microsoft.Azure.Services.AppAuthentication (>= 1.0.3) - Microsoft.Rest.ClientRuntime (>= 2.3.20) - System.IdentityModel.Tokens.Jwt (>= 4.0.4.403061554) xunit (2.3.1) xunit.analyzers (>= 0.7) xunit.assert (2.3.1) @@ -262,12 +247,12 @@ NUGET Microsoft.VisualStudio.OLE.Interop (>= 7.10.6071) Microsoft.VisualStudio.TextManager.Interop.8.0 (8.0.50728) - copy_local: false Microsoft.VisualStudio.Shell.Interop (>= 7.10.6072) - Microsoft.VisualStudio.Threading (15.8.192) - redirects: force + Microsoft.VisualStudio.Threading (15.8.192) - copy_local: false, redirects: force Microsoft.VisualStudio.Threading.Analyzers (>= 15.8.192) Microsoft.VisualStudio.Validation (>= 15.3.15) - Microsoft.VisualStudio.Threading.Analyzers (16.6.13) - redirects: force + Microsoft.VisualStudio.Threading.Analyzers (16.6.13) - copy_local: false, redirects: force Microsoft.VisualStudio.Utilities (15.0.26607) - Microsoft.VisualStudio.Validation (15.5.31) - redirects: force + Microsoft.VisualStudio.Validation (15.5.31) - copy_local: false, redirects: force Newtonsoft.Json (12.0.3) - copy_local: false, redirects: force System.IdentityModel.Tokens.Jwt (6.5) - copy_local: false, redirects: force Microsoft.IdentityModel.JsonWebTokens (>= 6.5) @@ -427,15 +412,15 @@ NUGET Microsoft.VisualStudio.OLE.Interop (>= 7.10.6071) Microsoft.VisualStudio.TextManager.Interop.8.0 (8.0.50728) - copy_local: false Microsoft.VisualStudio.Shell.Interop (>= 7.10.6072) - Microsoft.VisualStudio.Threading (15.8.192) - redirects: force + Microsoft.VisualStudio.Threading (15.8.192) - copy_local: false, redirects: force Microsoft.VisualStudio.Threading.Analyzers (>= 15.8.192) Microsoft.VisualStudio.Validation (>= 15.3.15) - Microsoft.VisualStudio.Threading.Analyzers (16.6.13) - redirects: force + Microsoft.VisualStudio.Threading.Analyzers (16.6.13) - copy_local: false, redirects: force Microsoft.VisualStudio.Utilities (15.9.28307) Microsoft.VisualStudio.Threading (>= 15.6.31) StreamJsonRpc (>= 1.3.23) - Microsoft.VisualStudio.Validation (15.5.31) - redirects: force - Nerdbank.Streams (2.4.67) + Microsoft.VisualStudio.Validation (15.5.31) - copy_local: false, redirects: force + Nerdbank.Streams (2.4.73) Microsoft.VisualStudio.Threading (>= 16.4.33) Microsoft.VisualStudio.Validation (>= 15.5.31) System.Buffers (>= 4.5) @@ -444,14 +429,14 @@ NUGET System.Runtime.CompilerServices.Unsafe (>= 4.6) System.ValueTuple (>= 4.5) Newtonsoft.Json (12.0.3) - copy_local: false, redirects: force - StreamJsonRpc (2.3.103) + StreamJsonRpc (2.4.48) MessagePack (>= 2.1.90) Microsoft.Bcl.AsyncInterfaces (>= 1.0) - Microsoft.VisualStudio.Threading (>= 16.4.45) - Nerdbank.Streams (>= 2.4.60) + Microsoft.VisualStudio.Threading (>= 16.6.13) + Nerdbank.Streams (>= 2.4.73) Newtonsoft.Json (>= 12.0.2) System.Collections.Immutable (>= 1.5) - System.IO.Pipelines (>= 4.6) + System.IO.Pipelines (>= 4.7) System.Memory (>= 4.5.3) System.Net.Http (>= 4.3.4) System.Net.WebSockets (>= 4.3) @@ -637,17 +622,17 @@ NUGET Microsoft.VisualStudio.OLE.Interop (>= 7.10.6071) Microsoft.VisualStudio.TextManager.Interop.8.0 (8.0.50728) - copy_local: false Microsoft.VisualStudio.Shell.Interop (>= 7.10.6072) - Microsoft.VisualStudio.Threading (15.8.192) - redirects: force + Microsoft.VisualStudio.Threading (15.8.192) - copy_local: false, redirects: force Microsoft.VisualStudio.Threading.Analyzers (>= 15.8.192) Microsoft.VisualStudio.Validation (>= 15.3.15) - Microsoft.VisualStudio.Threading.Analyzers (16.6.13) - redirects: force + Microsoft.VisualStudio.Threading.Analyzers (16.6.13) - copy_local: false, redirects: force Microsoft.VisualStudio.Utilities (16.5.29903.186) - copy_local: false Microsoft.VisualStudio.Threading (>= 16.5.132) Newtonsoft.Json (>= 12.0.2) StreamJsonRpc (>= 2.3.99) System.Threading.Tasks.Dataflow (>= 4.9) - Microsoft.VisualStudio.Validation (15.5.31) - redirects: force - Nerdbank.Streams (2.4.67) - copy_local: false + Microsoft.VisualStudio.Validation (15.5.31) - copy_local: false, redirects: force + Nerdbank.Streams (2.4.73) - copy_local: false Microsoft.VisualStudio.Threading (>= 16.4.33) Microsoft.VisualStudio.Validation (>= 15.5.31) System.Buffers (>= 4.5) @@ -656,14 +641,14 @@ NUGET System.Runtime.CompilerServices.Unsafe (>= 4.6) System.ValueTuple (>= 4.5) Newtonsoft.Json (12.0.3) - copy_local: false, redirects: force - StreamJsonRpc (2.3.103) - copy_local: false + StreamJsonRpc (2.4.48) - copy_local: false MessagePack (>= 2.1.90) Microsoft.Bcl.AsyncInterfaces (>= 1.0) - Microsoft.VisualStudio.Threading (>= 16.4.45) - Nerdbank.Streams (>= 2.4.60) + Microsoft.VisualStudio.Threading (>= 16.6.13) + Nerdbank.Streams (>= 2.4.73) Newtonsoft.Json (>= 12.0.2) System.Collections.Immutable (>= 1.5) - System.IO.Pipelines (>= 4.6) + System.IO.Pipelines (>= 4.7) System.Memory (>= 4.5.3) System.Net.Http (>= 4.3.4) System.Net.WebSockets (>= 4.3) diff --git a/vs-commitizen.Settings/ExtensionRegistry.cs b/vs-commitizen.Settings/ExtensionRegistry.cs index fa2d8aa..91a7800 100644 --- a/vs-commitizen.Settings/ExtensionRegistry.cs +++ b/vs-commitizen.Settings/ExtensionRegistry.cs @@ -1,6 +1,8 @@ using Microsoft.VisualStudio.Shell; using StructureMap; using System; +using System.IO; +using System.Reflection; using vs_commitizen.vs.Settings; namespace vs_commitizen.Settings @@ -12,7 +14,9 @@ public ExtensionRegistry() this.Scan(i => { i.TheCallingAssembly(); + i.AssembliesFromPath(Path.GetDirectoryName(Assembly.GetCallingAssembly().Location)); i.WithDefaultConventions(); + i.LookForRegistries(); }); this.For().Use(); diff --git a/vs-commitizen.Settings/IConfigFileProvider.cs b/vs-commitizen.Settings/IConfigFileProvider.cs new file mode 100644 index 0000000..a25f45f --- /dev/null +++ b/vs-commitizen.Settings/IConfigFileProvider.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace vs_commitizen.Settings +{ + public interface IConfigFileProvider + { + Task> GetCommitTypesAsync() where T : class; + Task TryGetLocalConfigAsync(); + } +} \ No newline at end of file diff --git a/vs-commitizen.Settings/IRepository.cs b/vs-commitizen.Settings/IRepository.cs new file mode 100644 index 0000000..6a06294 --- /dev/null +++ b/vs-commitizen.Settings/IRepository.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace vs_commitizen.Settings +{ + public interface IRepository + { + string RepositoryPath { get; } + } +} diff --git a/vs-commitizen.Settings/vs-commitizen.Settings.csproj b/vs-commitizen.Settings/vs-commitizen.Settings.csproj index 818ff1a..77199c2 100644 --- a/vs-commitizen.Settings/vs-commitizen.Settings.csproj +++ b/vs-commitizen.Settings/vs-commitizen.Settings.csproj @@ -45,7 +45,9 @@ + + Component diff --git a/vs-commitizen.Tests/CommitizenViewModelTests.CustomCommitType.cs b/vs-commitizen.Tests/CommitizenViewModelTests.CustomCommitType.cs new file mode 100644 index 0000000..b686c67 --- /dev/null +++ b/vs-commitizen.Tests/CommitizenViewModelTests.CustomCommitType.cs @@ -0,0 +1,156 @@ +using AutoFixture; +using AutoFixture.AutoNSubstitute; +using AutoFixture.Xunit2; +using NSubstitute; +using NSubstitute.Extensions; +using Shouldly; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using vs_commitizen.Infrastructure; +using vs_commitizen.Settings; +using vs_commitizen.Tests.TestAttributes; +using vs_commitizen.vs.ViewModels; +using Xunit; + +namespace vs_commitizen.Tests +{ + public class CommitizenViewModelTests_CustomCommitType + { + CommitizenViewModel getSut(Fixture fixture, ConfigFileProvider configFileProvider, (bool, string) currentSolution) + { + configFileProvider.Configure().SubscribeToSolutionEventsAsync().Returns(Task.CompletedTask); + configFileProvider.Configure().GetLocalPathAsync().Returns(currentSolution); + fixture.Register(() => configFileProvider); + return fixture.Create(); + } + + private static void SetupConfigFileInUserProfile(IFileAccessor fileAccessor, string userProfileContent, string inRepoConfigContent = null) + { + fileAccessor.Exists(Arg.Any()).ReturnsForAnyArgs(inRepoConfigContent != null, true); + + if (string.IsNullOrWhiteSpace(inRepoConfigContent)) + fileAccessor.ReadFileAsync(Arg.Any()).ReturnsForAnyArgs(userProfileContent); + else + fileAccessor.ReadFileAsync(Arg.Any()).ReturnsForAnyArgs(inRepoConfigContent, userProfileContent); + fileAccessor.Configure().CreateText(Arg.Any()).ReturnsForAnyArgs(new StreamWriter(new MemoryStream())); + } + + private static void SetupNoConfigFiles(IFileAccessor fileAccessor) + { + fileAccessor.Exists(Arg.Any()).ReturnsForAnyArgs(false, false); + } + + private static void SetupConfigFileInRepo(IFileAccessor fileAccessor, string fileContent) + { + fileAccessor.Exists(Arg.Any()).ReturnsForAnyArgs(true); + fileAccessor.ReadFileAsync(Arg.Any()).ReturnsForAnyArgs(fileContent); + fileAccessor.Configure().CreateText(Arg.Any()).ReturnsForAnyArgs(new StreamWriter(new MemoryStream())); + } + + [Theory, TestConventions] + public void InRepo_Config_Should_Be_Used_First( + [Frozen]IFileAccessor fileAccessor, + [Frozen][Substitute] IPopupManager popupManager, + [Frozen][Substitute] ConfigFileProvider configFileProvider, + Fixture fixture + ) + { + SetupConfigFileInUserProfile(fileAccessor, + userProfileContent: "{\"types\": [{\"type\": \"feat\"}, {\"type\": \"nope\"}]}", + inRepoConfigContent: "{\"types\": [{\"type\": \"feat\"}, {\"type\": \"nope\"}, {\"type\": \"nope2\"}]}"); + + var sut = getSut(fixture, configFileProvider, (true, "here")); + + sut.CommitTypes.Count.ShouldBe(3); + popupManager.DidNotReceiveWithAnyArgs().Show(Arg.Any(), Arg.Any()); + } + + [Theory, TestConventions] + public void UserProfileConfig_Should_Be_Used_If_InRepo_Is_Not_Existing( + [Frozen]IFileAccessor fileAccessor, + [Frozen][Substitute] IPopupManager popupManager, + [Frozen][Substitute] ConfigFileProvider configFileProvider, + Fixture fixture + ) + { + SetupConfigFileInUserProfile(fileAccessor, + userProfileContent: "{\"types\": [{\"type\": \"feat\"}, {\"type\": \"nope\"}, {\"type\": \"nope2\"}]}"); + + var sut = getSut(fixture, configFileProvider, (true, "here")); + + sut.CommitTypes.Count.ShouldBe(3); + popupManager.DidNotReceiveWithAnyArgs().Show(Arg.Any(), Arg.Any()); + } + + [Theory, TestConventions] + public void Non_Parsable_Config_Should_Give_Default_CommitTypes_And_Warn_User( + [Frozen]IFileAccessor fileAccessor, + [Frozen][Substitute] IPopupManager popupManager, + [Frozen][Substitute] ConfigFileProvider configFileProvider, + Fixture fixture + ) + { + SetupConfigFileInRepo(fileAccessor, ">"); + + var sut = getSut(fixture, configFileProvider, (true, "here")); + + sut.CommitTypes.Count.ShouldBe(11); + popupManager.ReceivedWithAnyArgs().Show(Arg.Any(), Arg.Any()); + } + + [Theory, TestConventions] + public void UserProfileConfig_Should_Be_Generated_If_None_Are_Found( + [Frozen]IFileAccessor fileAccessor, + [Frozen][Substitute] IPopupManager popupManager, + [Frozen][Substitute] ConfigFileProvider configFileProvider, + Fixture fixture + ) + { + SetupNoConfigFiles(fileAccessor); + + var sut = getSut(fixture, configFileProvider, (false, null)); + + sut.CommitTypes.Count.ShouldBe(11); + popupManager.DidNotReceiveWithAnyArgs().Show(Arg.Any(), Arg.Any()); + fileAccessor.ReceivedWithAnyArgs().CreateText(Arg.Any()); + } + + [Theory, TestConventions] + public async Task MultipleCall_From_Same_Repository_Should_Use_Cached_Config( + [Frozen]IFileAccessor fileAccessor, + [Frozen][Substitute] ConfigFileProvider configFileProvider, + Fixture fixture + ) + { + SetupConfigFileInRepo(fileAccessor, "{\"types\": [{\"type\": \"feat\"}, {\"type\": \"nope\"}, {\"type\": \"nope2\"}]}"); + + var sut = getSut(fixture, configFileProvider, (true, "path_to_repo1")); + var sut2 = getSut(fixture, configFileProvider, (true, "path_to_repo1")); + + sut.CommitTypes.Count.ShouldBe(3); + sut2.CommitTypes.Count.ShouldBe(3); + await fileAccessor.ReceivedWithAnyArgs(1).ReadFileAsync(Arg.Any()); + } + + [Theory, TestConventions] + public async Task MultipleCall_From_Different_Repository_Shouldnt_Use_Cached_Config( + [Frozen]IFileAccessor fileAccessor, + [Frozen][Substitute] ConfigFileProvider configFileProvider, + Fixture fixture + ) + { + SetupConfigFileInRepo(fileAccessor, "{\"types\": [{\"type\": \"feat\"}, {\"type\": \"nope\"}, {\"type\": \"nope2\"}]}"); + + var sut = getSut(fixture, configFileProvider, (true, "path_to_repo1")); + var sut2 = getSut(fixture, configFileProvider, (true, "path_to_repo2")); + + sut.CommitTypes.Count.ShouldBe(3); + sut2.CommitTypes.Count.ShouldBe(3); + await fileAccessor.ReceivedWithAnyArgs(2).ReadFileAsync(Arg.Any()); + } + } +} diff --git a/vs-commitizen.Tests/CommitizenViewModelTests.cs b/vs-commitizen.Tests/CommitizenViewModelTests.cs index 726ec41..b45ca77 100644 --- a/vs-commitizen.Tests/CommitizenViewModelTests.cs +++ b/vs-commitizen.Tests/CommitizenViewModelTests.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using vs_commitizen.Settings; using vs_commitizen.Tests.TestAttributes; using vs_commitizen.vs.Settings; using vs_commitizen.vs.ViewModels; @@ -147,9 +148,12 @@ public void Proceed_Sets_Autocommit(string autoCommit, bool expected, Commitizen } [Theory, TestConventions] - public void GetComment_With_No_SelectedCommitType_ShouldBe_Empty(IUserSettings userSettings) + public void GetComment_With_No_SelectedCommitType_ShouldBe_Empty( + IUserSettings userSettings, + IConfigFileProvider configFileProvider + ) { - var sut = new CommitizenViewModel(userSettings); + var sut = new CommitizenViewModel(userSettings, configFileProvider); sut.SelectedCommitType = null; sut.GetComment().ShouldBeEmpty(); } @@ -211,11 +215,13 @@ public void GetComment_ShouldNot_Prefix_Issues_If_NotNumber(CommitizenViewModel } [Theory, TestConventions] - public void GetComment_ShouldNot_Take_Last_Space_If_Over_ChunkSize(IUserSettings userSettings) + public void GetComment_ShouldNot_Take_Last_Space_If_Over_ChunkSize( + IUserSettings userSettings, + IConfigFileProvider configFileProvider) { userSettings.MaxLineLength = 10; - var sut = new CommitizenViewModel(userSettings); + var sut = new CommitizenViewModel(userSettings, configFileProvider); sut.SelectedCommitType = sut.CommitTypes.First(f => f.Type.Contains("feat")); sut.Scope = "test"; sut.Body = "test"; diff --git a/vs-commitizen.Tests/MainWindow.xaml.cs b/vs-commitizen.Tests/MainWindow.xaml.cs index e0601b0..5531dc4 100644 --- a/vs-commitizen.Tests/MainWindow.xaml.cs +++ b/vs-commitizen.Tests/MainWindow.xaml.cs @@ -25,13 +25,27 @@ public partial class MainWindow : Window public MainWindow() { IoC.Container.Inject(new DummyUserSettings()); + IoC.Container.Inject(new DummyConfigFileProvider()); InitializeComponent(); } - public class DummyUserSettings : IUserSettings + internal class DummyUserSettings : IUserSettings { public int MaxLineLength { get; set; } = 80; } + + internal class DummyConfigFileProvider : IConfigFileProvider + { + public Task> GetCommitTypesAsync() where T : class + { + throw new NotImplementedException(); + } + + public Task TryGetLocalConfigAsync() + { + throw new NotImplementedException(); + } + } } } diff --git a/vs-commitizen.Tests/TestAttributes/TestConventionsAttribute.cs b/vs-commitizen.Tests/TestAttributes/TestConventionsAttribute.cs index a99f802..ee282d3 100644 --- a/vs-commitizen.Tests/TestAttributes/TestConventionsAttribute.cs +++ b/vs-commitizen.Tests/TestAttributes/TestConventionsAttribute.cs @@ -5,6 +5,8 @@ using NSubstitute; using System; using System.Reflection; +using vs_commitizen.Infrastructure; +using vs_commitizen.Settings; using vs_commitizen.vs.Settings; using vs_commitizen.vs.ViewModels; @@ -13,18 +15,18 @@ namespace vs_commitizen.Tests.TestAttributes [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public class TestConventionsAttribute : AutoDataAttribute { - public TestConventionsAttribute() : base(() => + public TestConventionsAttribute() : base(() => new Fixture() .Customize(new DomainCustomization()) .Customize(new AutoNSubstituteCustomization { - ConfigureMembers = true + ConfigureMembers = true, + GenerateDelegates = true }) ) { } - private class DomainCustomization : ICustomization { public void Customize(IFixture fixture) @@ -33,6 +35,7 @@ public void Customize(IFixture fixture) .Without(c => c.CommitTypes) .With(c => c.HighlighBreakingChanges, () => false)); + fixture.Register(() => fixture.Create()); fixture.Register(() => { var sut = Substitute.For(); diff --git a/vs-commitizen.Tests/app.config b/vs-commitizen.Tests/app.config new file mode 100644 index 0000000..996bcf8 --- /dev/null +++ b/vs-commitizen.Tests/app.config @@ -0,0 +1,344 @@ + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + + True + + + + \ No newline at end of file diff --git a/vs-commitizen.Tests/paket.references b/vs-commitizen.Tests/paket.references index 5d64b3f..af5c9ce 100644 --- a/vs-commitizen.Tests/paket.references +++ b/vs-commitizen.Tests/paket.references @@ -6,7 +6,9 @@ xunit xunit.runner.visualstudio Xunit.StaFact -group vs15 - Microsoft.TeamFoundationServer.ExtendedClient copy_local: true +group vs16 + Microsoft.TeamFoundationServer.ExtendedClient copy_local: true, redirects: force Microsoft.VisualStudio.Shell.14.0 copy_local: true - Microsoft.VisualStudio.Shell.Interop.12.0 \ No newline at end of file + Microsoft.VisualStudio.Shell.15.0 copy_local: true + Microsoft.VisualStudio.Shell.Interop.12.0 + Microsoft.VisualStudio.Threading copy_local: true, redirects: on \ No newline at end of file diff --git a/vs-commitizen.Tests/vs-commitizen.Tests.csproj b/vs-commitizen.Tests/vs-commitizen.Tests.csproj index f7c45dd..66b85c8 100644 --- a/vs-commitizen.Tests/vs-commitizen.Tests.csproj +++ b/vs-commitizen.Tests/vs-commitizen.Tests.csproj @@ -1,5 +1,6 @@  + Debug @@ -20,6 +21,7 @@ + true true @@ -39,6 +41,18 @@ 4 + + False + + + False + + + False + + + False + ..\lib\vs2017\Microsoft.TeamFoundation.Controls.dll @@ -49,6 +63,8 @@ + + MainWindow.xaml @@ -81,6 +97,10 @@ {93748016-5aa8-4d74-887e-64959d8d2496} vs-commitizen.vs2017 + + {8382bf18-b8bc-4c54-9826-8d9d20cd868d} + vs-commitizen + @@ -279,8 +299,8 @@ - - ..\packages\vs15\MessagePack\lib\netstandard2.0\MessagePack.dll + + ..\packages\vs16\Ben.Demystifier\lib\net45\Ben.Demystifier.dll True True @@ -290,8 +310,8 @@ - - ..\packages\vs15\MessagePack.Annotations\lib\netstandard2.0\MessagePack.Annotations.dll + + ..\packages\vs16\MessagePack\lib\netstandard2.0\MessagePack.dll True True @@ -301,8 +321,8 @@ - - ..\packages\vs15\Microsoft.AspNet.WebApi.Client\lib\net45\System.Net.Http.Formatting.dll + + ..\packages\vs16\MessagePack.Annotations\lib\netstandard2.0\MessagePack.Annotations.dll True True @@ -312,8 +332,8 @@ - - ..\packages\vs15\Microsoft.AspNet.WebApi.Core\lib\net45\System.Web.Http.dll + + ..\packages\vs16\Microsoft.AspNet.WebApi.Client\lib\net45\System.Net.Http.Formatting.dll True True @@ -323,26 +343,8 @@ - - True - - - True - - - True - - - True - - - True - - - True - - - ..\packages\vs15\Microsoft.Azure.Services.AppAuthentication\lib\net472\Microsoft.Azure.Services.AppAuthentication.dll + + ..\packages\vs16\Microsoft.AspNet.WebApi.Core\lib\net45\System.Web.Http.dll True True @@ -353,13 +355,100 @@ - ..\packages\vs15\Microsoft.Bcl.AsyncInterfaces\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll + ..\packages\vs16\Microsoft.Bcl.AsyncInterfaces\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll True True + + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + @@ -382,7 +471,7 @@ True - ..\packages\vs15\Microsoft.IdentityModel.Clients.ActiveDirectory\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + ..\packages\vs16\Microsoft.IdentityModel.Clients.ActiveDirectory\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll True True @@ -393,7 +482,7 @@ - ..\packages\vs15\Microsoft.IdentityModel.JsonWebTokens\lib\net461\Microsoft.IdentityModel.JsonWebTokens.dll + ..\packages\vs16\Microsoft.IdentityModel.JsonWebTokens\lib\net461\Microsoft.IdentityModel.JsonWebTokens.dll True True @@ -404,7 +493,7 @@ - ..\packages\vs15\Microsoft.IdentityModel.Logging\lib\net461\Microsoft.IdentityModel.Logging.dll + ..\packages\vs16\Microsoft.IdentityModel.Logging\lib\net461\Microsoft.IdentityModel.Logging.dll True True @@ -415,27 +504,7 @@ - ..\packages\vs15\Microsoft.IdentityModel.Tokens\lib\net461\Microsoft.IdentityModel.Tokens.dll - True - True - - - - - - - - - True - - - True - - - True - - - ..\packages\vs15\Microsoft.Rest.ClientRuntime\lib\net461\Microsoft.Rest.ClientRuntime.dll + ..\packages\vs16\Microsoft.IdentityModel.Tokens\lib\net461\Microsoft.IdentityModel.Tokens.dll True True @@ -446,7 +515,7 @@ - ..\packages\vs15\Microsoft.TeamFoundation.DistributedTask.Common\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + ..\packages\vs16\Microsoft.TeamFoundation.DistributedTask.Common.Contracts\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll True True @@ -457,52 +526,67 @@ - ..\packages\vs15\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - True - True - - - ..\packages\vs15\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + True + True + + + ..\packages\vs16\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.Wiki.WebApi.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + True + True + + + ..\packages\vs16\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Process.WebApi.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + True + True + + + ..\packages\vs16\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.VisualStudio.Services.TestManagement.TestPlanning.WebApi.dll + True + True + + + ..\packages\vs16\Microsoft.TeamFoundationServer.Client\lib\net45\Microsoft.VisualStudio.Services.TestResults.WebApi.dll True True @@ -513,122 +597,122 @@ - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Build.Client.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Build.Client.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Build.Common.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Build.Common.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Client.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Client.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.DeleteTeamProject.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.DeleteTeamProject.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Diff.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Diff.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Discussion.Client.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Discussion.Client.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Git.Client.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Git.Client.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Lab.Client.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Lab.Client.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Lab.Common.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Lab.Common.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Lab.TestIntegration.Client.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Lab.TestIntegration.Client.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Lab.WorkflowIntegration.Client.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.Lab.WorkflowIntegration.Client.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.ProjectManagement.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.ProjectManagement.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.SharePointReporting.Integration.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.SharePointReporting.Integration.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.TestImpact.Client.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.TestImpact.Client.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.TestManagement.Client.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.TestManagement.Client.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.TestManagement.Common.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.TestManagement.Common.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.VersionControl.Client.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.VersionControl.Client.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.VersionControl.Common.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.VersionControl.Common.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.VersionControl.Common.Integration.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.VersionControl.Common.Integration.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Client.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Client.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Client.QueryLanguage.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Client.QueryLanguage.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Common.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Common.dll True True - ..\packages\vs15\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Proxy.dll + ..\packages\vs16\Microsoft.TeamFoundationServer.ExtendedClient\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Proxy.dll True True @@ -638,8 +722,11 @@ - - ..\packages\vs15\Microsoft.Tpl.Dataflow\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll + + True + + + ..\packages\vs16\Microsoft.VisualStudio.CoreUtility\lib\net472\Microsoft.VisualStudio.CoreUtility.dll True True @@ -649,11 +736,8 @@ - - True - - - ..\packages\vs15\Microsoft.VisualStudio.CoreUtility\lib\net46\Microsoft.VisualStudio.CoreUtility.dll + + ..\packages\vs16\Microsoft.VisualStudio.ImageCatalog\lib\net45\Microsoft.VisualStudio.ImageCatalog.dll True True @@ -663,8 +747,8 @@ - - ..\packages\vs15\Microsoft.VisualStudio.ImageCatalog\lib\net45\Microsoft.VisualStudio.ImageCatalog.dll + + ..\packages\vs16\Microsoft.VisualStudio.Imaging\lib\net472\Microsoft.VisualStudio.Imaging.dll True True @@ -674,8 +758,8 @@ - - ..\packages\vs15\Microsoft.VisualStudio.Imaging\lib\net45\Microsoft.VisualStudio.Imaging.dll + + ..\packages\vs16\Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime\lib\net20\Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.dll True True @@ -686,28 +770,38 @@ - ..\packages\vs15\Microsoft.VisualStudio.OLE.Interop\lib\Microsoft.VisualStudio.OLE.Interop.dll + ..\packages\vs16\Microsoft.VisualStudio.OLE.Interop\lib\Microsoft.VisualStudio.OLE.Interop.dll True True + + + + + True + + + True + + - ..\packages\vs15\Microsoft.VisualStudio.Services.Client\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\vs16\Microsoft.VisualStudio.Services.Client\lib\net45\Microsoft.TeamFoundation.Common.dll True True - ..\packages\vs15\Microsoft.VisualStudio.Services.Client\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\vs16\Microsoft.VisualStudio.Services.Client\lib\net45\Microsoft.VisualStudio.Services.Common.dll True True - ..\packages\vs15\Microsoft.VisualStudio.Services.Client\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\vs16\Microsoft.VisualStudio.Services.Client\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll True True @@ -718,7 +812,7 @@ - ..\packages\vs15\Microsoft.VisualStudio.Services.InteractiveClient\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + ..\packages\vs16\Microsoft.VisualStudio.Services.InteractiveClient\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll True True @@ -729,7 +823,18 @@ - ..\packages\vs15\Microsoft.VisualStudio.Shell.14.0\lib\Microsoft.VisualStudio.Shell.14.0.dll + ..\packages\vs16\Microsoft.VisualStudio.Shell.14.0\lib\Microsoft.VisualStudio.Shell.14.0.dll + True + True + + + + + + + + + ..\packages\vs16\Microsoft.VisualStudio.Shell.15.0\lib\net45\Microsoft.VisualStudio.Shell.15.0.dll True True @@ -740,7 +845,7 @@ - ..\packages\vs15\Microsoft.VisualStudio.Shell.Framework\lib\net45\Microsoft.VisualStudio.Shell.Framework.dll + ..\packages\vs16\Microsoft.VisualStudio.Shell.Framework\lib\net472\Microsoft.VisualStudio.Shell.Framework.dll True True @@ -751,7 +856,7 @@ - ..\packages\vs15\Microsoft.VisualStudio.Shell.Immutable.10.0\lib\net45\Microsoft.VisualStudio.Shell.Immutable.10.0.dll + ..\packages\vs16\Microsoft.VisualStudio.Shell.Immutable.10.0\lib\net45\Microsoft.VisualStudio.Shell.Immutable.10.0.dll True True @@ -762,7 +867,7 @@ - ..\packages\vs15\Microsoft.VisualStudio.Shell.Immutable.11.0\lib\net45\Microsoft.VisualStudio.Shell.Immutable.11.0.dll + ..\packages\vs16\Microsoft.VisualStudio.Shell.Immutable.11.0\lib\net45\Microsoft.VisualStudio.Shell.Immutable.11.0.dll True True @@ -773,7 +878,7 @@ - ..\packages\vs15\Microsoft.VisualStudio.Shell.Immutable.12.0\lib\net45\Microsoft.VisualStudio.Shell.Immutable.12.0.dll + ..\packages\vs16\Microsoft.VisualStudio.Shell.Immutable.12.0\lib\net45\Microsoft.VisualStudio.Shell.Immutable.12.0.dll True True @@ -784,7 +889,7 @@ - ..\packages\vs15\Microsoft.VisualStudio.Shell.Immutable.14.0\lib\net45\Microsoft.VisualStudio.Shell.Immutable.14.0.dll + ..\packages\vs16\Microsoft.VisualStudio.Shell.Immutable.14.0\lib\net45\Microsoft.VisualStudio.Shell.Immutable.14.0.dll True True @@ -795,7 +900,7 @@ - ..\packages\vs15\Microsoft.VisualStudio.Shell.Interop\lib\net11\Microsoft.VisualStudio.Shell.Interop.dll + ..\packages\vs16\Microsoft.VisualStudio.Shell.Interop\lib\net11\Microsoft.VisualStudio.Shell.Interop.dll True True @@ -806,7 +911,7 @@ - ..\packages\vs15\Microsoft.VisualStudio.Shell.Interop.10.0\lib\net20\Microsoft.VisualStudio.Shell.Interop.10.0.dll + ..\packages\vs16\Microsoft.VisualStudio.Shell.Interop.10.0\lib\net20\Microsoft.VisualStudio.Shell.Interop.10.0.dll True True @@ -817,7 +922,7 @@ - ..\packages\vs15\Microsoft.VisualStudio.Shell.Interop.11.0\lib\net20\Microsoft.VisualStudio.Shell.Interop.11.0.dll + ..\packages\vs16\Microsoft.VisualStudio.Shell.Interop.11.0\lib\net20\Microsoft.VisualStudio.Shell.Interop.11.0.dll True True @@ -828,7 +933,40 @@ - ..\packages\vs15\Microsoft.VisualStudio.Shell.Interop.12.0\lib\net20\Microsoft.VisualStudio.Shell.Interop.12.0.dll + ..\packages\vs16\Microsoft.VisualStudio.Shell.Interop.12.0\lib\net20\Microsoft.VisualStudio.Shell.Interop.12.0.dll + True + True + + + + + + + + + ..\packages\vs16\Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime\lib\net20\Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime.dll + True + True + + + + + + + + + ..\packages\vs16\Microsoft.VisualStudio.Shell.Interop.15.3.DesignTime\lib\net20\Microsoft.VisualStudio.Shell.Interop.15.3.DesignTime.dll + True + True + + + + + + + + + ..\packages\vs16\Microsoft.VisualStudio.Shell.Interop.15.6.DesignTime\lib\net20\Microsoft.VisualStudio.Shell.Interop.15.6.DesignTime.dll True True @@ -839,7 +977,7 @@ - ..\packages\vs15\Microsoft.VisualStudio.Shell.Interop.8.0\lib\net11\Microsoft.VisualStudio.Shell.Interop.8.0.dll + ..\packages\vs16\Microsoft.VisualStudio.Shell.Interop.8.0\lib\net11\Microsoft.VisualStudio.Shell.Interop.8.0.dll True True @@ -850,7 +988,18 @@ - ..\packages\vs15\Microsoft.VisualStudio.Shell.Interop.9.0\lib\net11\Microsoft.VisualStudio.Shell.Interop.9.0.dll + ..\packages\vs16\Microsoft.VisualStudio.Shell.Interop.9.0\lib\net11\Microsoft.VisualStudio.Shell.Interop.9.0.dll + True + True + + + + + + + + + ..\packages\vs16\Microsoft.VisualStudio.Text.Data\lib\net472\Microsoft.VisualStudio.Text.Data.dll True True @@ -861,7 +1010,7 @@ - ..\packages\vs15\Microsoft.VisualStudio.TextManager.Interop\lib\net11\Microsoft.VisualStudio.TextManager.Interop.dll + ..\packages\vs16\Microsoft.VisualStudio.TextManager.Interop\lib\net11\Microsoft.VisualStudio.TextManager.Interop.dll True True @@ -872,7 +1021,7 @@ - ..\packages\vs15\Microsoft.VisualStudio.TextManager.Interop.8.0\lib\net11\Microsoft.VisualStudio.TextManager.Interop.8.0.dll + ..\packages\vs16\Microsoft.VisualStudio.TextManager.Interop.8.0\lib\net11\Microsoft.VisualStudio.TextManager.Interop.8.0.dll True True @@ -883,60 +1032,59 @@ - ..\packages\vs15\Microsoft.VisualStudio.Threading\lib\net46\Microsoft.VisualStudio.Threading.dll + ..\packages\vs16\Microsoft.VisualStudio.Threading\lib\net46\Microsoft.VisualStudio.Threading.dll True True - - - + + - + True - + True - + True - + True - + True - + True - + True - + True - + True - + True - + True - + True - + True - + True - + True @@ -944,7 +1092,7 @@ - ..\packages\vs15\Microsoft.VisualStudio.Utilities\lib\net46\Microsoft.VisualStudio.Utilities.dll + ..\packages\vs16\Microsoft.VisualStudio.Utilities\lib\net46\Microsoft.VisualStudio.Utilities.dll True True @@ -955,7 +1103,7 @@ - ..\packages\vs15\Microsoft.VisualStudio.Validation\lib\netstandard2.0\Microsoft.VisualStudio.Validation.dll + ..\packages\vs16\Microsoft.VisualStudio.Validation\lib\netstandard2.0\Microsoft.VisualStudio.Validation.dll True True @@ -966,7 +1114,7 @@ - ..\packages\vs15\Nerdbank.Streams\lib\netstandard2.0\Nerdbank.Streams.dll + ..\packages\vs16\Nerdbank.Streams\lib\netstandard2.0\Nerdbank.Streams.dll True True @@ -977,7 +1125,7 @@ - ..\packages\vs15\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll + ..\packages\vs16\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll True True @@ -988,7 +1136,7 @@ - ..\packages\vs15\StreamJsonRpc\lib\netstandard2.0\StreamJsonRpc.dll + ..\packages\vs16\StreamJsonRpc\lib\netstandard2.0\StreamJsonRpc.dll True True @@ -999,7 +1147,7 @@ - ..\packages\vs15\System.Buffers\lib\net461\System.Buffers.dll + ..\packages\vs16\System.Buffers\lib\net461\System.Buffers.dll True True @@ -1010,7 +1158,7 @@ - ..\packages\vs15\System.Collections.Immutable\lib\netstandard2.0\System.Collections.Immutable.dll + ..\packages\vs16\System.Collections.Immutable\lib\netstandard2.0\System.Collections.Immutable.dll True True @@ -1021,7 +1169,7 @@ - ..\packages\vs15\System.IdentityModel.Tokens.Jwt\lib\net461\System.IdentityModel.Tokens.Jwt.dll + ..\packages\vs16\System.IdentityModel.Tokens.Jwt\lib\net461\System.IdentityModel.Tokens.Jwt.dll True True @@ -1032,7 +1180,7 @@ - ..\packages\vs15\System.IO\lib\net462\System.IO.dll + ..\packages\vs16\System.IO\lib\net462\System.IO.dll True True @@ -1043,7 +1191,7 @@ - ..\packages\vs15\System.IO.Pipelines\lib\netstandard2.0\System.IO.Pipelines.dll + ..\packages\vs16\System.IO.Pipelines\lib\netstandard2.0\System.IO.Pipelines.dll True True @@ -1054,7 +1202,7 @@ - ..\packages\vs15\System.Memory\lib\net461\System.Memory.dll + ..\packages\vs16\System.Memory\lib\net461\System.Memory.dll True True @@ -1065,7 +1213,7 @@ - ..\packages\vs15\System.Net.Http\lib\net46\System.Net.Http.dll + ..\packages\vs16\System.Net.Http\lib\net46\System.Net.Http.dll True True @@ -1076,7 +1224,7 @@ - ..\packages\vs15\System.Net.WebSockets\lib\net46\System.Net.WebSockets.dll + ..\packages\vs16\System.Net.WebSockets\lib\net46\System.Net.WebSockets.dll True True @@ -1090,7 +1238,7 @@ True - ..\packages\vs15\System.Numerics.Vectors\lib\net46\System.Numerics.Vectors.dll + ..\packages\vs16\System.Numerics.Vectors\lib\net46\System.Numerics.Vectors.dll True True @@ -1100,8 +1248,8 @@ - - ..\packages\vs15\System.Runtime\lib\net462\System.Runtime.dll + + ..\packages\vs16\System.Reflection.Metadata\lib\netstandard2.0\System.Reflection.Metadata.dll True True @@ -1111,8 +1259,8 @@ - - ..\packages\vs15\System.Security.Cryptography.Algorithms\lib\net463\System.Security.Cryptography.Algorithms.dll + + ..\packages\vs16\System.Runtime\lib\net462\System.Runtime.dll True True @@ -1122,8 +1270,8 @@ - - ..\packages\vs15\System.Security.Cryptography.Encoding\lib\net46\System.Security.Cryptography.Encoding.dll + + ..\packages\vs16\System.Security.Cryptography.Algorithms\lib\net463\System.Security.Cryptography.Algorithms.dll True True @@ -1133,8 +1281,8 @@ - - ..\packages\vs15\System.Security.Cryptography.Primitives\lib\net46\System.Security.Cryptography.Primitives.dll + + ..\packages\vs16\System.Security.Cryptography.Encoding\lib\net46\System.Security.Cryptography.Encoding.dll True True @@ -1144,8 +1292,8 @@ - - ..\packages\vs15\System.Security.Cryptography.X509Certificates\lib\net461\System.Security.Cryptography.X509Certificates.dll + + ..\packages\vs16\System.Security.Cryptography.Primitives\lib\net46\System.Security.Cryptography.Primitives.dll True True @@ -1155,8 +1303,8 @@ - - ..\packages\vs15\System.Threading.Tasks.Dataflow\lib\netstandard2.0\System.Threading.Tasks.Dataflow.dll + + ..\packages\vs16\System.Security.Cryptography.X509Certificates\lib\net461\System.Security.Cryptography.X509Certificates.dll True True @@ -1166,8 +1314,8 @@ - - ..\packages\vs15\System.ValueTuple\lib\net47\System.ValueTuple.dll + + ..\packages\vs16\System.Threading.Tasks.Dataflow\lib\netstandard2.0\System.Threading.Tasks.Dataflow.dll True True @@ -1177,11 +1325,8 @@ - - True - - - ..\packages\vs15\WindowsAzure.ServiceBus\lib\net462\Microsoft.ServiceBus.dll + + ..\packages\vs16\System.ValueTuple\lib\net47\System.ValueTuple.dll True True diff --git a/vs-commitizen.vs2015/Models/CommitType.cs b/vs-commitizen.vs2015/Models/CommitType.cs index ea3cdd3..4d3480a 100644 --- a/vs-commitizen.vs2015/Models/CommitType.cs +++ b/vs-commitizen.vs2015/Models/CommitType.cs @@ -11,6 +11,6 @@ public CommitType(string type, string description) public string Type { get; } public string Description { get; } - public string DisplayString => $"{this.Type} - {this.Description}"; + public string DisplayString => string.IsNullOrEmpty(Description) ? $"{this.Type}" : $"{this.Type} - {this.Description}"; } } \ No newline at end of file diff --git a/vs-commitizen.vs2015/Repository.cs b/vs-commitizen.vs2015/Repository.cs new file mode 100644 index 0000000..e1ed43c --- /dev/null +++ b/vs-commitizen.vs2015/Repository.cs @@ -0,0 +1,14 @@ +using vs_commitizen.Settings; + +namespace vs_commitizen.vs +{ + public class Repository : IRepository + { + public string RepositoryPath { get; } + + public Repository(string repositoryPath) + { + this.RepositoryPath = repositoryPath; + } + } +} diff --git a/vs-commitizen.vs2015/ViewModels/CommitizenViewModel.cs b/vs-commitizen.vs2015/ViewModels/CommitizenViewModel.cs index a1608f8..4d30e6a 100644 --- a/vs-commitizen.vs2015/ViewModels/CommitizenViewModel.cs +++ b/vs-commitizen.vs2015/ViewModels/CommitizenViewModel.cs @@ -3,10 +3,13 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Linq; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; +using System.Threading.Tasks; using System.Windows.Input; using System.Windows.Media; +using vs_commitizen.Settings; using vs_commitizen.vs.Extensions; using vs_commitizen.vs.Interfaces; using vs_commitizen.vs.Models; @@ -18,7 +21,7 @@ public class CommitizenViewModel : INotifyPropertyChanged, ICommentBuilder { #region Bound properties - private List _commitTypes; + private List _commitTypes = new List(); public List CommitTypes { get => _commitTypes; @@ -146,22 +149,10 @@ public bool HasGitPendingChanges } #endregion - public CommitizenViewModel(IUserSettings userSettings) + public CommitizenViewModel(IUserSettings userSettings, IConfigFileProvider configFileProvider) { - this.CommitTypes = new List - { - new CommitType("feat", "A new feature"), - new CommitType("fix", "A bug fix"), - new CommitType("docs", "Documentation only changes"), - new CommitType("style", "Changes that do not affect the meaning of the code (formatting, etc)"), - new CommitType("refactor", "A code change that neither fixes a bug nor adds a feature"), - new CommitType("perf", "A code change that improves performance"), - new CommitType("test", "Adding missing tests or correcting existing tests"), - new CommitType("build", "Changes that affect the build system or external dependencies (example scopes: gulp, etc)"), - new CommitType("ci", "Changes to our CI configuration files and scripts (example scopes: Travis, etc)"), - new CommitType("chore", "Other changes that don't modify src or test files"), - new CommitType("revert", "Reverts a previous commit") - }; + _ = LoadCommitTypesAsync(configFileProvider); + this.OnProceed = new RelayCommand(Proceed, CanProceed); this.HasGitPendingChanges = true; //TODO: Correct way to bind this this.HighlighBreakingChanges = false; @@ -169,6 +160,31 @@ public CommitizenViewModel(IUserSettings userSettings) this.LineLength = this._userSettings.MaxLineLength; } + private async Task LoadCommitTypesAsync(IConfigFileProvider configFileProvider) + { + try + { + this.CommitTypes = (await configFileProvider.GetCommitTypesAsync()).ToList(); + } + catch + { + this.CommitTypes = new List + { + new CommitType("feat", "A new feature"), + new CommitType("fix", "A bug fix"), + new CommitType("docs", "Documentation only changes"), + new CommitType("style", "Changes that do not affect the meaning of the code (formatting, etc)"), + new CommitType("refactor", "A code change that neither fixes a bug nor adds a feature"), + new CommitType("perf", "A code change that improves performance"), + new CommitType("test", "Adding missing tests or correcting existing tests"), + new CommitType("build", "Changes that affect the build system or external dependencies (example scopes: gulp, etc)"), + new CommitType("ci", "Changes to our CI configuration files and scripts (example scopes: Travis, etc)"), + new CommitType("chore", "Other changes that don't modify src or test files"), + new CommitType("revert", "Reverts a previous commit") + }; + } + } + private void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); diff --git a/vs-commitizen.vs2015/VsCommitizenNavigationItem.cs b/vs-commitizen.vs2015/VsCommitizenNavigationItem.cs index eb46d43..2f07e9c 100644 --- a/vs-commitizen.vs2015/VsCommitizenNavigationItem.cs +++ b/vs-commitizen.vs2015/VsCommitizenNavigationItem.cs @@ -6,6 +6,7 @@ using System.ComponentModel.Composition; using System.Drawing; using System.Threading.Tasks; +using vs_commitizen.Settings; using vs_commitizen.vs; namespace vs_commitizen.vs2015 @@ -30,16 +31,20 @@ public VsCommitizenNavigationItem([Import(typeof(SVsServiceProvider))] IServiceP this.IsVisible = gitService.ActiveRepositories.Count > 0; } - private async void GitService_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + private void GitService_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { - await this.UpdateIsVisibleAsync(); + _ = this.UpdateIsVisibleAsync(); } private async System.Threading.Tasks.Task UpdateIsVisibleAsync() { - await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); - this.IsVisible = this.gitService?.ActiveRepositories.Count > 0; - await TaskScheduler.Default; + try + { + await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); + this.IsVisible = this.gitService?.ActiveRepositories.Count > 0; + await TaskScheduler.Default; + } + catch { } } public override void Execute() diff --git a/vs-commitizen.vs2015/VsCommitizenSection.cs b/vs-commitizen.vs2015/VsCommitizenSection.cs index 0bc8a9e..603793a 100644 --- a/vs-commitizen.vs2015/VsCommitizenSection.cs +++ b/vs-commitizen.vs2015/VsCommitizenSection.cs @@ -38,7 +38,6 @@ private Boolean IsPackageLoaded() { var package = IoC.TryGetInstance(); return package != null; - } private void ExecuteOpenSettings() diff --git a/vs-commitizen.vs2015/VsRegistry.cs b/vs-commitizen.vs2015/VsRegistry.cs new file mode 100644 index 0000000..33cb9f1 --- /dev/null +++ b/vs-commitizen.vs2015/VsRegistry.cs @@ -0,0 +1,20 @@ +using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; +using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility; +using StructureMap; +using System.Linq; +using vs_commitizen.Settings; + +namespace vs_commitizen.vs +{ + public class VsRegistry : Registry + { + public VsRegistry() + { + For().Use("repositoryPath", () => { + var gitExt = ServiceProvider.GlobalProvider.GetService(typeof(IGitExt)) as IGitExt; + return new Repository(gitExt?.ActiveRepositories.FirstOrDefault()?.RepositoryPath); + }); + } + } +} diff --git a/vs-commitizen.vs2015/app.config b/vs-commitizen.vs2015/app.config index a1efa0e..d60bd4c 100644 --- a/vs-commitizen.vs2015/app.config +++ b/vs-commitizen.vs2015/app.config @@ -255,7 +255,7 @@ True - + True diff --git a/vs-commitizen.vs2015/paket.references b/vs-commitizen.vs2015/paket.references index 8d2abfb..f378750 100644 --- a/vs-commitizen.vs2015/paket.references +++ b/vs-commitizen.vs2015/paket.references @@ -1,3 +1,5 @@ +StructureMap + group vs14 Microsoft.TeamFoundationServer.ExtendedClient Microsoft.VisualStudio.Shell.14.0 diff --git a/vs-commitizen.vs2015/vs-commitizen.vs2015.csproj b/vs-commitizen.vs2015/vs-commitizen.vs2015.csproj index 84dbbde..022e285 100644 --- a/vs-commitizen.vs2015/vs-commitizen.vs2015.csproj +++ b/vs-commitizen.vs2015/vs-commitizen.vs2015.csproj @@ -91,6 +91,7 @@ + @@ -104,6 +105,7 @@ True VSPackage.resx + @@ -134,6 +136,17 @@ vs-commitizen.Settings + + + + + ..\packages\StructureMap\lib\net45\StructureMap.dll + True + True + + + + diff --git a/vs-commitizen.vs2017/app.config b/vs-commitizen.vs2017/app.config index 23144e8..d0a002f 100644 --- a/vs-commitizen.vs2017/app.config +++ b/vs-commitizen.vs2017/app.config @@ -265,7 +265,7 @@ True - + True diff --git a/vs-commitizen.vs2017/paket.references b/vs-commitizen.vs2017/paket.references index 1b01c3f..c85c8fc 100644 --- a/vs-commitizen.vs2017/paket.references +++ b/vs-commitizen.vs2017/paket.references @@ -1,3 +1,5 @@ +StructureMap + group vs15 Microsoft.TeamFoundationServer.ExtendedClient Microsoft.VisualStudio.Shell.14.0 diff --git a/vs-commitizen.vs2017/vs-commitizen.vs2017.csproj b/vs-commitizen.vs2017/vs-commitizen.vs2017.csproj index 6c9fd59..e7bc8bb 100644 --- a/vs-commitizen.vs2017/vs-commitizen.vs2017.csproj +++ b/vs-commitizen.vs2017/vs-commitizen.vs2017.csproj @@ -104,6 +104,9 @@ Models\NavigationDataType.cs + + Repository.cs + ViewModels\CommitizenViewModel.cs @@ -126,6 +129,9 @@ True VSPackage.resx + + VsRegistry.cs + @@ -160,6 +166,17 @@ vs-commitizen.Settings + + + + + ..\packages\StructureMap\lib\net45\StructureMap.dll + True + True + + + + diff --git a/vs-commitizen.vs2019/app.config b/vs-commitizen.vs2019/app.config index fba5eb2..c33a53b 100644 --- a/vs-commitizen.vs2019/app.config +++ b/vs-commitizen.vs2019/app.config @@ -270,7 +270,7 @@ True - + True diff --git a/vs-commitizen.vs2019/paket.references b/vs-commitizen.vs2019/paket.references index 6469ca5..84eb827 100644 --- a/vs-commitizen.vs2019/paket.references +++ b/vs-commitizen.vs2019/paket.references @@ -1,3 +1,4 @@ +StructureMap group vs16 Microsoft.TeamFoundationServer.ExtendedClient diff --git a/vs-commitizen.vs2019/vs-commitizen.vs2019.csproj b/vs-commitizen.vs2019/vs-commitizen.vs2019.csproj index f5e9629..bb0409d 100644 --- a/vs-commitizen.vs2019/vs-commitizen.vs2019.csproj +++ b/vs-commitizen.vs2019/vs-commitizen.vs2019.csproj @@ -105,6 +105,9 @@ Models\NavigationDataType.cs + + Repository.cs + ViewModels\CommitizenViewModel.cs @@ -127,6 +130,9 @@ True VSPackage.resx + + VsRegistry.cs + @@ -161,6 +167,17 @@ vs-commitizen.Settings + + + + + ..\packages\StructureMap\lib\net45\StructureMap.dll + True + True + + + + diff --git a/vs-commitizen/Commands/OpenGenerateLocalConfig.cs b/vs-commitizen/Commands/OpenGenerateLocalConfig.cs new file mode 100644 index 0000000..d13c086 --- /dev/null +++ b/vs-commitizen/Commands/OpenGenerateLocalConfig.cs @@ -0,0 +1,165 @@ +using System; +using System.ComponentModel.Design; +using System.IO; +using EnvDTE80; +using Microsoft; +using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; +using vs_commitizen.Infrastructure; +using vs_commitizen.Settings; +using Task = System.Threading.Tasks.Task; + +namespace vs_commitizen.Commands +{ + /// + /// Command handler + /// + internal sealed class OpenGenerateLocalConfig + { + /// + /// Command ID. + /// + public const int CommandId = 257; + + /// + /// Command menu group (command set GUID). + /// + public static readonly Guid CommandSet = PackageGuids.OpenGenerateLocalConfigCmdSet; + + /// + /// VS Package that provides this command, not null. + /// + private readonly AsyncPackage package; + + /// + /// Initializes a new instance of the class. + /// Adds our command handlers for menu (commands must exist in the command table file) + /// + /// Owner package, not null. + /// Command service to add command to, not null. + private OpenGenerateLocalConfig(AsyncPackage package, OleMenuCommandService commandService) + { + this.package = package ?? throw new ArgumentNullException(nameof(package)); + commandService = commandService ?? throw new ArgumentNullException(nameof(commandService)); + + var menuCommandID = new CommandID(CommandSet, CommandId); + var menuItem = new OleMenuCommand(Execute, menuCommandID); + menuItem.BeforeQueryStatus += MenuItem_BeforeQueryStatus; + commandService.AddCommand(menuItem); + } + + private void MenuItem_BeforeQueryStatus(object sender, EventArgs e) + { + _ = HandleIsCommandVisibleAsync(sender); + + } + + private static async Task HandleIsCommandVisibleAsync(object sender) + { + try + { + OleMenuCommand menuCommand = sender as OleMenuCommand; + + switch (menuCommand.CommandID.ID) + { + case (int)PackageIds.OpenGenerateLocalConfigCmd: + var configFileProvider = IoC.GetInstance(); + var fileAccessor = IoC.GetInstance(); + + var localConfigPath = await configFileProvider.TryGetLocalConfigAsync(); + menuCommand.Enabled = !string.IsNullOrWhiteSpace(localConfigPath); + break; + } + } + catch + { + } + } + + /// + /// Gets the instance of the command. + /// + public static OpenGenerateLocalConfig Instance + { + get; + private set; + } + + /// + /// Gets the service provider from the owner package. + /// + private Microsoft.VisualStudio.Shell.IAsyncServiceProvider ServiceProvider + { + get + { + return package; + } + } + + /// + /// Initializes the singleton instance of the command. + /// + /// Owner package, not null. + public static async Task InitializeAsync(AsyncPackage package) + { + // Switch to the main thread - the call to AddCommand in Command1's constructor requires + // the UI thread. + await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken); + + OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; + Instance = new OpenGenerateLocalConfig(package, commandService); + } + + /// + /// This function is the callback used to execute the command when the menu item is clicked. + /// See the constructor to see how the menu item is associated with this function using + /// OleMenuCommandService service and MenuCommand class. + /// + /// Event sender. + /// Event args. + private void Execute(object sender, EventArgs e) + { + _ = ProcessAsync(); + } + + private async Task ProcessAsync() + { + var popupManager = IoC.GetInstance(); + + try + { + var configFileProvider = IoC.GetInstance(); + var fileAccessor = IoC.GetInstance(); + + var localConfigPath = await configFileProvider.TryGetLocalConfigAsync(); + if (string.IsNullOrWhiteSpace(localConfigPath)) return; + + if (!fileAccessor.Exists(localConfigPath)) + { + if (popupManager.Confirm("There is no local configuration file yet, do you want to create it for this repository ?", "Init local config file")) + { + fileAccessor.CopyFile(ConfigFileProvider.ConfigPathUserProfile, localConfigPath); + } + } + + await OpenFileInEditorAsync(localConfigPath); + } + catch (Exception ex) + { + popupManager.Show(ex.ToString(), "An error occured"); + } + } + + private async Task OpenFileInEditorAsync(string localConfigPath) + { + await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); + + var dte = await this.ServiceProvider.GetServiceAsync(typeof(SDTE)) as DTE2; + if (dte == null) return; + + dte.MainWindow.Activate(); + var newWindow = dte.ItemOperations.OpenFile(localConfigPath); + newWindow.Activate(); + } + } +} \ No newline at end of file diff --git a/vs-commitizen/Commands/OpenGenerateUserProfileConfig.cs b/vs-commitizen/Commands/OpenGenerateUserProfileConfig.cs new file mode 100644 index 0000000..5b84770 --- /dev/null +++ b/vs-commitizen/Commands/OpenGenerateUserProfileConfig.cs @@ -0,0 +1,111 @@ +using System; +using System.ComponentModel.Design; +using System.IO; +using EnvDTE80; +using Microsoft.VisualStudio.Shell; +using vs_commitizen.Infrastructure; +using Task = System.Threading.Tasks.Task; + +namespace vs_commitizen.Commands +{ + /// + /// Command handler + /// + internal sealed class OpenGenerateUserProfileConfig + { + /// + /// Command ID. + /// + public const int CommandId = 256; + + /// + /// Command menu group (command set GUID). + /// + public static readonly Guid CommandSet = PackageGuids.OpenGenerateUserProfileConfigCmdSet; + + /// + /// VS Package that provides this command, not null. + /// + private readonly AsyncPackage package; + + /// + /// Initializes a new instance of the class. + /// Adds our command handlers for menu (commands must exist in the command table file) + /// + /// Owner package, not null. + /// Command service to add command to, not null. + private OpenGenerateUserProfileConfig(AsyncPackage package, OleMenuCommandService commandService) + { + this.package = package ?? throw new ArgumentNullException(nameof(package)); + commandService = commandService ?? throw new ArgumentNullException(nameof(commandService)); + + var menuCommandID = new CommandID(CommandSet, CommandId); + var menuItem = new MenuCommand(Execute, menuCommandID); + commandService.AddCommand(menuItem); + } + + /// + /// Gets the instance of the command. + /// + public static OpenGenerateUserProfileConfig Instance + { + get; + private set; + } + + /// + /// Gets the service provider from the owner package. + /// + private IAsyncServiceProvider ServiceProvider + { + get + { + return package; + } + } + + /// + /// Initializes the singleton instance of the command. + /// + /// Owner package, not null. + public static async Task InitializeAsync(AsyncPackage package) + { + // Switch to the main thread - the call to AddCommand in Command1's constructor requires + // the UI thread. + await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken); + + OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; + Instance = new OpenGenerateUserProfileConfig(package, commandService); + } + + /// + /// This function is the callback used to execute the command when the menu item is clicked. + /// See the constructor to see how the menu item is associated with this function using + /// OleMenuCommandService service and MenuCommand class. + /// + /// Event sender. + /// Event args. + private void Execute(object sender, EventArgs e) + { + _ = ProcessAsync(); + + } + + private async Task ProcessAsync() + { + await OpenFileInEditorAsync(ConfigFileProvider.ConfigPathUserProfile); + } + + private async Task OpenFileInEditorAsync(string localConfigPath) + { + await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); + + var dte = await this.ServiceProvider.GetServiceAsync(typeof(Microsoft.VisualStudio.Shell.Interop.SDTE)) as DTE2; + if (dte == null) return; + + dte.MainWindow.Activate(); + var newWindow = dte.ItemOperations.OpenFile(localConfigPath); + newWindow.Activate(); + } + } +} \ No newline at end of file diff --git a/vs-commitizen/Infrastructure/ConfigFileProvider.cs b/vs-commitizen/Infrastructure/ConfigFileProvider.cs new file mode 100644 index 0000000..12db0cf --- /dev/null +++ b/vs-commitizen/Infrastructure/ConfigFileProvider.cs @@ -0,0 +1,192 @@ +using EnvDTE; +using EnvDTE80; +using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.Caching; +using System.Threading.Tasks; +using vs_commitizen.Settings; +using IAsyncServiceProvider = Microsoft.VisualStudio.Shell.IAsyncServiceProvider; + +namespace vs_commitizen.Infrastructure +{ + public class ConfigFileProvider : IConfigFileProvider + { + private readonly IFileAccessor fileAccessor; + private const string CONFIGFILE_NAME = ".commitizen.json"; + private const string EXTENSION_FOLDER_NAME = "vs-commitizen"; + private readonly IServiceProvider serviceProvider; + private readonly IPopupManager popupManager; + + private SolutionEvents solutionEvents; + private bool init; + private static readonly Object @lock = new Object(); + private MemoryCache cache = new MemoryCache("commitTypes"); + + public static string ConfigPathUserProfile => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), EXTENSION_FOLDER_NAME, CONFIGFILE_NAME); + + public ConfigFileProvider(IServiceProvider serviceProvider, IFileAccessor fileAccessor, IPopupManager popupManager) + { + this.fileAccessor = fileAccessor; + this.serviceProvider = serviceProvider; + this.popupManager = popupManager; + } + + public async Task> GetCommitTypesAsync() where T : class + { + string cacheKey = await GetCacheKeyAsync(); + lock (@lock) + { + var commitTypes = cache.GetCacheItem(cacheKey); + if (commitTypes != null) return (IList)commitTypes.Value; + } + + try + { + var configStr = await GetConfigAsync(); + T[] commitTypes = JsonConvert.DeserializeObject(configStr).Where(c => !string.IsNullOrEmpty(c.ToString())).ToArray(); + lock (@lock) + { + cache.Set(cacheKey, commitTypes, new CacheItemPolicy()); + } + return commitTypes; + } + catch (InvalidConfigurationFileException ex) + { + popupManager.Show($"Failed to read configuration file, using default values.{Environment.NewLine}{Environment.NewLine}{ex}", "Error"); + throw; + } + } + + private async Task GetCacheKeyAsync() + { + var (ok, path) = await this.GetLocalPathAsync(); + if (ok) + return string.Concat("commitTypes-", path.Normalize()); + return "commitTypes"; + } + + private async Task<(bool isValid, string content)> TryGetValidConfigFileAsync(string path) + { + var content = await fileAccessor.ReadFileAsync(path); + + try + { + string types = JObject.Parse(content).SelectToken("types").ToString(); + return (true, types); + } + catch (JsonReaderException) + { + throw new InvalidConfigurationFileException(path); + } + catch (Exception) + { + return (false, null); + } + } + + internal protected virtual async Task<(bool isLoaded, string path)> GetCurrentSolutionAsync() + { + var asyncServiceProvider = serviceProvider.GetService(typeof(SAsyncServiceProvider)) as IAsyncServiceProvider; + var dte = await asyncServiceProvider?.GetServiceAsync(typeof(SDTE)) as DTE2; + + await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); + + return ((dte?.Solution?.IsOpen).GetValueOrDefault(false), dte?.Solution.FullName); + } + + internal protected virtual async Task<(bool isLoaded, string path)> GetLocalPathAsync() + { + var repository = IoC.GetInstance(); + return (repository != null, repository?.RepositoryPath); + } + + public async Task TryGetLocalConfigAsync() + { + var (isRepositoryLoaded, repositoryPath) = await GetLocalPathAsync(); // await GetCurrentSolutionAsync(); + if (isRepositoryLoaded) + { + var localConfigPath = Path.Combine(repositoryPath, CONFIGFILE_NAME); + + if (this.fileAccessor.Exists(localConfigPath)) + return localConfigPath; + } + + return string.Empty; + } + + async Task GetConfigAsync() + { + await SubscribeToSolutionEventsAsync(); + + var localConfig = await TryGetLocalConfigAsync(); + + if (!string.IsNullOrWhiteSpace(localConfig)) + { + if (fileAccessor.Exists(localConfig)) + { + var (isValid, content) = await TryGetValidConfigFileAsync(localConfig); + if (isValid) + return content; + } + } + + var pathToFolder = Path.GetDirectoryName(ConfigPathUserProfile); + Directory.CreateDirectory(pathToFolder); + + if (fileAccessor.Exists(ConfigPathUserProfile)) + { + var (isValid, content) = await TryGetValidConfigFileAsync(ConfigPathUserProfile); + if (isValid) + return content; + } + + return await GenerateDefaultConfigFileAsync(ConfigPathUserProfile); + } + + internal protected virtual async System.Threading.Tasks.Task SubscribeToSolutionEventsAsync() + { + if (!this.init) + { + await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); + var asyncServiceProvider = serviceProvider.GetService(typeof(SAsyncServiceProvider)) as IAsyncServiceProvider; + var dte = await asyncServiceProvider?.GetServiceAsync(typeof(SDTE)) as DTE2; + + this.solutionEvents = dte.Events.SolutionEvents; + this.solutionEvents.BeforeClosing += () => + { + lock (@lock) + { + this.cache = new MemoryCache("commitTypes"); + } + }; + + this.init = true; + } + } + + private async Task GenerateDefaultConfigFileAsync(string configFileInUserSettings) + { + using (var fileStream = fileAccessor.CreateText(configFileInUserSettings)) + { + var assembly = Assembly.GetExecutingAssembly(); + var resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith("defaultConfigFile.json")); + + using (Stream stream = assembly.GetManifestResourceStream(resourceName)) + using (StreamReader reader = new StreamReader(stream)) + { + var defaultConfigFileContent = await reader.ReadToEndAsync(); + await fileStream.WriteAsync(defaultConfigFileContent); + + return defaultConfigFileContent; + } + } + } + } +} diff --git a/vs-commitizen/Infrastructure/FileAccessor.cs b/vs-commitizen/Infrastructure/FileAccessor.cs new file mode 100644 index 0000000..3eb6cab --- /dev/null +++ b/vs-commitizen/Infrastructure/FileAccessor.cs @@ -0,0 +1,110 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace vs_commitizen.Infrastructure +{ + public interface IFileAccessor + { + string ReadFile(string filePath); + string[] ReadFileLines(string filePath); + Task ReadFileAsync(string filePath); + void WriteFile(string filePath, string content); + Task WriteFileAsync(string filePath, string content); + FileAttributes GetAttributes(string filePath); + void SetAttributes(string filePath, FileAttributes attributes); + bool Exists(string filePath); + IEnumerable EnumerateDirectories(string folderPath); + IEnumerable GetDirectories(string folderPath); + bool DirectoryExists(string path); + string GetTempFileName(); + StreamWriter CreateText(string filePath); + void CopyFile(string src, string dest); + } + + public class FileAccessor : IFileAccessor + { + public virtual void CopyFile(string src, string dest) + { + File.Copy(src, dest); + } + + public virtual StreamWriter CreateText(string filePath) + { + return File.CreateText(filePath); + } + + public virtual string ReadFile(string filePath) + { + return File.ReadAllText(filePath); + } + + public virtual string[] ReadFileLines(string filePath) + { + return File.ReadAllLines(filePath); + } + + public virtual async Task ReadFileAsync(string filePath) + { + using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true)) + { + var buff = new byte[file.Length]; + await file.ReadAsync(buff, 0, (int)file.Length); + return Encoding.Default.GetString(buff); + } + } + + public virtual async Task WriteFileAsync(string filePath, string content) + { + var encodedText = Encoding.Default.GetBytes(content); + + using (var sourceStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, 4096, true)) + { + await sourceStream.WriteAsync(encodedText, 0, encodedText.Length); + }; + + } + + public virtual void WriteFile(string filePath, string content) + { + File.WriteAllText(filePath, content); + } + + public virtual FileAttributes GetAttributes(string filePath) + { + return File.GetAttributes(filePath); + } + + public virtual void SetAttributes(string filePath, FileAttributes attributes) + { + File.SetAttributes(filePath, attributes); + } + + public virtual bool Exists(string filePath) + { + return File.Exists(filePath); + } + + public virtual bool DirectoryExists(string path) + { + return Directory.Exists(path); + } + + public virtual IEnumerable EnumerateDirectories(string folderPath) + { + return Directory.EnumerateDirectories(folderPath).Select(d => new DirectoryInfo(d).Name); + } + + public virtual IEnumerable GetDirectories(string folderPath) + { + return Directory.GetDirectories(folderPath); + } + + public virtual string GetTempFileName() + { + return Path.GetTempFileName(); + } + } +} diff --git a/vs-commitizen/Infrastructure/InvalidConfigurationFileException.cs b/vs-commitizen/Infrastructure/InvalidConfigurationFileException.cs new file mode 100644 index 0000000..4c84a03 --- /dev/null +++ b/vs-commitizen/Infrastructure/InvalidConfigurationFileException.cs @@ -0,0 +1,25 @@ +using System; +using System.Runtime.Serialization; + +namespace vs_commitizen.Infrastructure +{ + [Serializable] + internal class InvalidConfigurationFileException : Exception + { + public InvalidConfigurationFileException() + { + } + + public InvalidConfigurationFileException(string message) : base(message) + { + } + + public InvalidConfigurationFileException(string message, Exception innerException) : base(message, innerException) + { + } + + protected InvalidConfigurationFileException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } +} \ No newline at end of file diff --git a/vs-commitizen/Infrastructure/PopupManager.cs b/vs-commitizen/Infrastructure/PopupManager.cs new file mode 100644 index 0000000..66a3820 --- /dev/null +++ b/vs-commitizen/Infrastructure/PopupManager.cs @@ -0,0 +1,41 @@ +using Microsoft.VisualStudio; +using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; +using System; + +namespace vs_commitizen.Infrastructure +{ + + public interface IPopupManager + { + void Show(string message); + void Show(string message, string title); + bool Confirm(string message, string title); + } + + public class PopupManager : IPopupManager + { + private readonly IServiceProvider serviceProvider; + + public PopupManager(IServiceProvider serviceProvider) + { + this.serviceProvider = serviceProvider; + } + + public virtual void Show(string message) + { + VsShellUtilities.ShowMessageBox(serviceProvider, message, string.Empty, OLEMSGICON.OLEMSGICON_WARNING, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); + } + + public virtual void Show(string message, string title) + { + VsShellUtilities.ShowMessageBox(serviceProvider, message, title, OLEMSGICON.OLEMSGICON_WARNING, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); + } + + public virtual bool Confirm(string message, string title) + { + var res = VsShellUtilities.ShowMessageBox(serviceProvider, message, title, OLEMSGICON.OLEMSGICON_QUERY, OLEMSGBUTTON.OLEMSGBUTTON_YESNO, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); + return res == (int)VSConstants.MessageBoxResult.IDYES; + } + } +} diff --git a/vs-commitizen/PackageRegistry.cs b/vs-commitizen/PackageRegistry.cs new file mode 100644 index 0000000..667b200 --- /dev/null +++ b/vs-commitizen/PackageRegistry.cs @@ -0,0 +1,15 @@ +using StructureMap; +using vs_commitizen.Infrastructure; +using vs_commitizen.Settings; + +namespace vs_commitizen +{ + public class PackageRegistry : Registry + { + public PackageRegistry() + { + this.For().Use().Singleton(); + this.For().Use().Singleton(); + } + } +} diff --git a/vs-commitizen/Properties/AssemblyInfo.cs b/vs-commitizen/Properties/AssemblyInfo.cs index bfad292..90d0342 100644 --- a/vs-commitizen/Properties/AssemblyInfo.cs +++ b/vs-commitizen/Properties/AssemblyInfo.cs @@ -31,3 +31,4 @@ // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: InternalsVisibleTo("vs-commitizen.Tests")] \ No newline at end of file diff --git a/vs-commitizen/Resources/Open_6529.png b/vs-commitizen/Resources/Open_6529.png new file mode 100644 index 0000000..4935155 Binary files /dev/null and b/vs-commitizen/Resources/Open_6529.png differ diff --git a/vs-commitizen/VsCommitizenIds.cs b/vs-commitizen/VsCommitizenIds.cs index d232058..faa9551 100644 --- a/vs-commitizen/VsCommitizenIds.cs +++ b/vs-commitizen/VsCommitizenIds.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------ // -// This file was generated by Extensibility Tools v1.10.198 +// This file was generated by VSIX Synchronizer // // ------------------------------------------------------------------------------ namespace vs_commitizen @@ -13,23 +13,41 @@ namespace vs_commitizen internal sealed partial class PackageGuids { public const string guidVsCommitizenPackageString = "c4809955-ac8e-41bf-8d86-faa98b6678ad"; - public const string guidVsCommitizenPackageCmdSetString = "c71925e2-e9ca-4214-9a36-44c8ab847862"; - public const string guidImagesString = "4817493b-b1c9-44a5-af4b-a39633f0f4e1"; public static Guid guidVsCommitizenPackage = new Guid(guidVsCommitizenPackageString); + + public const string UIContextGuidString = "d08d84f8-03d8-418e-a03a-1015add01a6f"; + public static Guid UIContextGuid = new Guid(UIContextGuidString); + + public const string guidVsCommitizenPackageCmdSetString = "c71925e2-e9ca-4214-9a36-44c8ab847862"; public static Guid guidVsCommitizenPackageCmdSet = new Guid(guidVsCommitizenPackageCmdSetString); + + public const string OpenGenerateUserProfileConfigCmdSetString = "a4975378-1743-4009-a4d5-1654a683e957"; + public static Guid OpenGenerateUserProfileConfigCmdSet = new Guid(OpenGenerateUserProfileConfigCmdSetString); + + public const string OpenGenerateLocalConfigCmdSetString = "a4975378-1743-4009-a4d5-1654a683e958"; + public static Guid OpenGenerateLocalConfigCmdSet = new Guid(OpenGenerateLocalConfigCmdSetString); + + public const string guidImagesString = "4817493b-b1c9-44a5-af4b-a39633f0f4e1"; public static Guid guidImages = new Guid(guidImagesString); + + public const string guidImages2String = "b8ba0b3c-2fca-4a93-9fda-70276a399b8f"; + public static Guid guidImages2 = new Guid(guidImages2String); } /// /// Helper class that encapsulates all CommandIDs uses across VS Package. /// internal sealed partial class PackageIds { - public const int ToolWindow1CommandId = 0x0100; + public const int TopLevelMenu = 0x1021; + public const int MyMenuGroup = 0x1020; + public const int OpenGenerateUserProfileConfigCmd = 0x0100; + public const int OpenGenerateLocalConfigCmd = 0x0101; public const int bmpPic1 = 0x0001; public const int bmpPic2 = 0x0002; public const int bmpPicSearch = 0x0003; public const int bmpPicX = 0x0004; public const int bmpPicArrows = 0x0005; public const int bmpPicStrikethrough = 0x0006; + public const int bmpOpen = 0x0001; } -} +} \ No newline at end of file diff --git a/vs-commitizen/VsCommitizenPackage.cs b/vs-commitizen/VsCommitizenPackage.cs index b1c62b8..ecd1767 100644 --- a/vs-commitizen/VsCommitizenPackage.cs +++ b/vs-commitizen/VsCommitizenPackage.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.VisualStudio; using Microsoft.VisualStudio.Shell; +using vs_commitizen.Commands; using vs_commitizen.Settings; using vs_commitizen.vs.Settings; @@ -32,11 +33,24 @@ namespace vs_commitizen [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About [Guid(PackageGuids.guidVsCommitizenPackageString)] + [ProvideMenuResource("Menus.ctmenu", 1)] [ProvideOptionPage(typeof(SettingsGeneral), "vs-commitizen", "General", 101, 106, true)] - [ProvideAutoLoad(VSConstants.UICONTEXT.RepositoryOpen_string, PackageAutoLoadFlags.BackgroundLoad)] + +#pragma warning disable VSSDK004 // Use BackgroundLoad flag in ProvideAutoLoad attribute for asynchronous auto load. + [ProvideAutoLoad(UIContextGuid, PackageAutoLoadFlags.BackgroundLoad)] +#pragma warning restore VSSDK004 // Use BackgroundLoad flag in ProvideAutoLoad attribute for asynchronous auto load. + [ProvideUIContextRule(UIContextGuid, + name: "Test auto load", + expression: "(RepositoryOpen | SingleProject | MultipleProjects)", + termNames: new[] { "RepositoryOpen", "SingleProject", "MultipleProjects" }, + termValues: new[] { VSConstants.UICONTEXT.RepositoryOpen_string, VSConstants.UICONTEXT.SolutionHasSingleProject_string, VSConstants.UICONTEXT.SolutionHasMultipleProjects_string })] + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")] public sealed class VsCommitizenPackage : AsyncPackage { + public const string UIContextGuid = "D08D84F8-03D8-418E-A03A-1015ADD01A6F"; + + /// /// Initializes a new instance of the class. /// @@ -52,11 +66,13 @@ public VsCommitizenPackage() #region Package Members - protected override System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress progress) + protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress progress) { Bootstrap.InitExtension(this); - return base.InitializeAsync(cancellationToken, progress); + await OpenGenerateUserProfileConfig.InitializeAsync(this); + await OpenGenerateLocalConfig.InitializeAsync(this); + await base.InitializeAsync(cancellationToken, progress); } #endregion diff --git a/vs-commitizen/VsCommitizenPackage.vsct b/vs-commitizen/VsCommitizenPackage.vsct index 876ebba..c11c126 100644 --- a/vs-commitizen/VsCommitizenPackage.vsct +++ b/vs-commitizen/VsCommitizenPackage.vsct @@ -15,10 +15,10 @@ defining some of the constants that we will use inside the file. --> - + - + @@ -42,11 +42,20 @@ DefaultInvisible DynamicVisibility If you do not want an image next to your command, remove the Icon node /> --> - + @@ -58,20 +67,47 @@ bitmap strip containing the bitmaps and then there are the numeric ids of the elements used inside a button definition. An important aspect of this declaration is that the element id must be the actual index (1-based) of the bitmap inside the bitmap strip. --> - + + + + + + + vs-commitizen + vs-commitizen + + + + + + + + + + + + + - + + + + + + + + - + @@ -79,5 +115,8 @@ + + + diff --git a/vs-commitizen/app.config b/vs-commitizen/app.config index 93b0347..2fb6cc1 100644 --- a/vs-commitizen/app.config +++ b/vs-commitizen/app.config @@ -23,6 +23,16 @@ + + True + + + + + True + + + True @@ -243,16 +253,6 @@ - - True - - - - - True - - - True @@ -271,7 +271,7 @@ True - + True diff --git a/vs-commitizen/defaultConfigFile.json b/vs-commitizen/defaultConfigFile.json new file mode 100644 index 0000000..9112816 --- /dev/null +++ b/vs-commitizen/defaultConfigFile.json @@ -0,0 +1,49 @@ +{ + "$schema": "https://github.com/MrLuje/vs-commitizen/config-schema.json", + "types": [ + { + "type": "feat", + "description": "A new feature" + }, + { + "type": "fix", + "description": "A bug fix" + }, + { + "type": "docs", + "description": "Documentation only changes" + }, + { + "type": "style", + "description": "Changes that do not affect the meaning of the code (formatting, etc)" + }, + { + "type": "refactor", + "description": "A code change that neither fixes a bug nor adds a feature" + }, + { + "type": "perf", + "description": "A code change that improves performance" + }, + { + "type": "test", + "description": "Adding missing tests or correcting existing tests" + }, + { + "type": "build", + "description": "Changes that affect the build system or external dependencies (example scopes: gulp, etc)" + }, + { + "type": "ci", + "description": "Changes to our CI configuration files and scripts (example scopes: Travis, etc)" + }, + { + "type": "chore", + "description": "Other changes that don't modify src or test files" + }, + { + "type": "revert", + "description": "Reverts a previous commit" + } + ] +} \ No newline at end of file diff --git a/vs-commitizen/paket.references b/vs-commitizen/paket.references index c269401..1a52684 100644 --- a/vs-commitizen/paket.references +++ b/vs-commitizen/paket.references @@ -1,6 +1,9 @@ Microsoft.VSSDK.BuildTools +Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime +Microsoft.VisualStudio.Threading redirects: force, copy_local: false +Newtonsoft.Json copy_local: true +StructureMap group vs14 Microsoft.VisualStudio.Shell.14.0 - Microsoft.VisualStudio.Shell.Interop.12.0 - Microsoft.VisualStudio.Threading redirects: force, copy_local: false \ No newline at end of file + Microsoft.VisualStudio.Shell.Interop.12.0 \ No newline at end of file diff --git a/vs-commitizen/vs-commitizen.csproj b/vs-commitizen/vs-commitizen.csproj index a801fc2..1a3894d 100644 --- a/vs-commitizen/vs-commitizen.csproj +++ b/vs-commitizen/vs-commitizen.csproj @@ -56,18 +56,28 @@ 4 + + + + + + + - True True VsCommitizenPackage.vsct + Designer + + PreserveNewest + Designer @@ -75,9 +85,10 @@ - Always + PreserveNewest true + @@ -115,6 +126,7 @@ + @@ -162,66 +174,40 @@ --> + + + + + ..\packages\Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime\lib\net20\Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.dll + True + True + + + + + + + + + ..\packages\Microsoft.VisualStudio.OLE.Interop\lib\Microsoft.VisualStudio.OLE.Interop.dll + True + True + + + + True - - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - - ..\packages\vs14\Microsoft.VisualStudio.CoreUtility\lib\net45\Microsoft.VisualStudio.CoreUtility.dll - False + + ..\packages\Microsoft.VisualStudio.Shell.Interop\lib\net11\Microsoft.VisualStudio.Shell.Interop.dll + True True @@ -230,9 +216,9 @@ - - ..\packages\vs14\Microsoft.VisualStudio.ImageCatalog\lib\net45\Microsoft.VisualStudio.ImageCatalog.dll - False + + ..\packages\Microsoft.VisualStudio.Shell.Interop.10.0\lib\net20\Microsoft.VisualStudio.Shell.Interop.10.0.dll + True True @@ -241,9 +227,9 @@ - - ..\packages\vs14\Microsoft.VisualStudio.Imaging\lib\net45\Microsoft.VisualStudio.Imaging.dll - False + + ..\packages\Microsoft.VisualStudio.Shell.Interop.11.0\lib\net20\Microsoft.VisualStudio.Shell.Interop.11.0.dll + True True @@ -252,9 +238,9 @@ - - ..\packages\vs14\Microsoft.VisualStudio.OLE.Interop\lib\Microsoft.VisualStudio.OLE.Interop.dll - False + + ..\packages\Microsoft.VisualStudio.Shell.Interop.12.0\lib\net20\Microsoft.VisualStudio.Shell.Interop.12.0.dll + True True @@ -263,9 +249,9 @@ - - ..\packages\vs14\Microsoft.VisualStudio.Shell.14.0\lib\Microsoft.VisualStudio.Shell.14.0.dll - False + + ..\packages\Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime\lib\net20\Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime.dll + True True @@ -274,9 +260,9 @@ - - ..\packages\vs14\Microsoft.VisualStudio.Shell.Immutable.10.0\lib\net40\Microsoft.VisualStudio.Shell.Immutable.10.0.dll - False + + ..\packages\Microsoft.VisualStudio.Shell.Interop.8.0\lib\net11\Microsoft.VisualStudio.Shell.Interop.8.0.dll + True True @@ -285,9 +271,9 @@ - - ..\packages\vs14\Microsoft.VisualStudio.Shell.Immutable.11.0\lib\net45\Microsoft.VisualStudio.Shell.Immutable.11.0.dll - False + + ..\packages\Microsoft.VisualStudio.TextManager.Interop\lib\net11\Microsoft.VisualStudio.TextManager.Interop.dll + True True @@ -296,9 +282,9 @@ - - ..\packages\vs14\Microsoft.VisualStudio.Shell.Immutable.12.0\lib\net45\Microsoft.VisualStudio.Shell.Immutable.12.0.dll - False + + ..\packages\Microsoft.VisualStudio.TextManager.Interop.8.0\lib\net11\Microsoft.VisualStudio.TextManager.Interop.8.0.dll + True True @@ -307,19 +293,68 @@ - - ..\packages\vs14\Microsoft.VisualStudio.Shell.Immutable.14.0\lib\net45\Microsoft.VisualStudio.Shell.Immutable.14.0.dll + + ..\packages\Microsoft.VisualStudio.Threading\lib\net46\Microsoft.VisualStudio.Threading.dll False True + + + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + - - ..\packages\vs14\Microsoft.VisualStudio.Shell.Interop\lib\net11\Microsoft.VisualStudio.Shell.Interop.dll + + ..\packages\Microsoft.VisualStudio.Validation\lib\netstandard2.0\Microsoft.VisualStudio.Validation.dll False True @@ -329,8 +364,8 @@ - - ..\packages\vs14\Microsoft.VisualStudio.Shell.Interop.10.0\lib\net20\Microsoft.VisualStudio.Shell.Interop.10.0.dll + + ..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll True True @@ -340,8 +375,8 @@ - - ..\packages\vs14\Microsoft.VisualStudio.Shell.Interop.11.0\lib\net20\Microsoft.VisualStudio.Shell.Interop.11.0.dll + + ..\packages\StructureMap\lib\net45\StructureMap.dll True True @@ -351,9 +386,9 @@ - - ..\packages\vs14\Microsoft.VisualStudio.Shell.Interop.12.0\lib\net20\Microsoft.VisualStudio.Shell.Interop.12.0.dll - True + + ..\packages\vs14\Microsoft.VisualStudio.CoreUtility\lib\net45\Microsoft.VisualStudio.CoreUtility.dll + False True @@ -362,8 +397,8 @@ - - ..\packages\vs14\Microsoft.VisualStudio.Shell.Interop.8.0\lib\net11\Microsoft.VisualStudio.Shell.Interop.8.0.dll + + ..\packages\vs14\Microsoft.VisualStudio.ImageCatalog\lib\net45\Microsoft.VisualStudio.ImageCatalog.dll False True @@ -373,8 +408,8 @@ - - ..\packages\vs14\Microsoft.VisualStudio.Shell.Interop.9.0\lib\net11\Microsoft.VisualStudio.Shell.Interop.9.0.dll + + ..\packages\vs14\Microsoft.VisualStudio.Imaging\lib\net45\Microsoft.VisualStudio.Imaging.dll False True @@ -384,8 +419,8 @@ - - ..\packages\vs14\Microsoft.VisualStudio.TextManager.Interop\lib\net11\Microsoft.VisualStudio.TextManager.Interop.dll + + ..\packages\vs14\Microsoft.VisualStudio.Shell.14.0\lib\Microsoft.VisualStudio.Shell.14.0.dll False True @@ -395,8 +430,8 @@ - - ..\packages\vs14\Microsoft.VisualStudio.TextManager.Interop.8.0\lib\net11\Microsoft.VisualStudio.TextManager.Interop.8.0.dll + + ..\packages\vs14\Microsoft.VisualStudio.Shell.Immutable.10.0\lib\net40\Microsoft.VisualStudio.Shell.Immutable.10.0.dll False True @@ -406,8 +441,8 @@ - - ..\packages\vs14\Microsoft.VisualStudio.Threading\lib\net46\Microsoft.VisualStudio.Threading.dll + + ..\packages\vs14\Microsoft.VisualStudio.Shell.Immutable.11.0\lib\net45\Microsoft.VisualStudio.Shell.Immutable.11.0.dll False True @@ -417,8 +452,8 @@ - - ..\packages\vs14\Microsoft.VisualStudio.Utilities\lib\net46\Microsoft.VisualStudio.Utilities.dll + + ..\packages\vs14\Microsoft.VisualStudio.Shell.Immutable.12.0\lib\net45\Microsoft.VisualStudio.Shell.Immutable.12.0.dll False True @@ -428,8 +463,30 @@ - - ..\packages\vs14\Microsoft.VisualStudio.Validation\lib\netstandard2.0\Microsoft.VisualStudio.Validation.dll + + ..\packages\vs14\Microsoft.VisualStudio.Shell.Immutable.14.0\lib\net45\Microsoft.VisualStudio.Shell.Immutable.14.0.dll + False + True + + + + + + + + + ..\packages\vs14\Microsoft.VisualStudio.Shell.Interop.9.0\lib\net11\Microsoft.VisualStudio.Shell.Interop.9.0.dll + False + True + + + + + + + + + ..\packages\vs14\Microsoft.VisualStudio.Utilities\lib\net46\Microsoft.VisualStudio.Utilities.dll False True