diff --git a/docs_new/Tags.md b/docs_new/Tags.md index 8670edf6..3a821acc 100644 --- a/docs_new/Tags.md +++ b/docs_new/Tags.md @@ -19,12 +19,6 @@ The following `TagsV2.yaml` file defines three different tags (work, private, gi context: - type: evaluate-script@1 content: |- - # at this moment, you must leave this function intact - # todo, make sure this is not required anymore. - func translate(input) - ret input - end - func remotes_contain_inner(remotes, url_part) urls = remotes | array.map "url" filtered = array.filter(urls, do diff --git a/src/RepoM.ActionMenu.Core/Model/ActionMenuGenerationContext.cs b/src/RepoM.ActionMenu.Core/Model/ActionMenuGenerationContext.cs index f385ab32..c42ee95c 100644 --- a/src/RepoM.ActionMenu.Core/Model/ActionMenuGenerationContext.cs +++ b/src/RepoM.ActionMenu.Core/Model/ActionMenuGenerationContext.cs @@ -15,6 +15,7 @@ namespace RepoM.ActionMenu.Core.Model; using RepoM.ActionMenu.Interface.YamlModel; using RepoM.ActionMenu.Interface.YamlModel.ActionMenus; using Scriban; +using Scriban.Runtime; using FileFunctions = RepoM.ActionMenu.Core.ActionMenu.Context.FileFunctions; using IRepository = RepoM.Core.Plugin.Repository.IRepository; using RepositoryFunctions = RepoM.ActionMenu.Core.ActionMenu.Context.RepositoryFunctions; @@ -131,6 +132,8 @@ private static RepoMScriptObject CreateAndInitRepoMScriptObject(IRepository repo { var scriptObj = new RepoMScriptObject(); + scriptObj.Import(typeof(InitialFunctions)); + scriptObj.SetValue("file", new FileFunctions(), true); scriptObj.SetValue("repository", new RepositoryFunctions(repository), true); diff --git a/src/RepoM.ActionMenu.Core/Model/InitialialFunctions.cs b/src/RepoM.ActionMenu.Core/Model/InitialialFunctions.cs new file mode 100644 index 00000000..2196cf0a --- /dev/null +++ b/src/RepoM.ActionMenu.Core/Model/InitialialFunctions.cs @@ -0,0 +1,9 @@ +namespace RepoM.ActionMenu.Core.Model; + +internal static class InitialFunctions +{ + public static string? Translate(string? input) + { + return input; + } +} \ No newline at end of file diff --git a/src/RepoM.Api/Resources/RepositoryActionsV2.yaml b/src/RepoM.Api/Resources/RepositoryActionsV2.yaml index 3c3915b2..f3890467 100644 --- a/src/RepoM.Api/Resources/RepositoryActionsV2.yaml +++ b/src/RepoM.Api/Resources/RepositoryActionsV2.yaml @@ -1,11 +1,6 @@ context: - type: evaluate-script@1 content: |- - # at this moment, you must leave this function intact - func translate(input) - ret input - end - func is_null(input) ret input == null end diff --git a/src/RepoM.Api/Resources/TagsV2.yaml b/src/RepoM.Api/Resources/TagsV2.yaml index 08ca669c..9570cc93 100644 --- a/src/RepoM.Api/Resources/TagsV2.yaml +++ b/src/RepoM.Api/Resources/TagsV2.yaml @@ -1,11 +1,6 @@ context: - type: evaluate-script@1 content: |- - # at this moment, you must leave this function intact - func translate(input) - ret input - end - func remotes_contain_inner(remotes, url_part) urls = remotes | array.map "url" filtered = array.filter(urls, do diff --git a/tests/RepoM.ActionMenu.Core.Tests/ScribanActionMenuTests.cs b/tests/RepoM.ActionMenu.Core.Tests/ScribanActionMenuTests.cs index 28b12bca..a4825020 100644 --- a/tests/RepoM.ActionMenu.Core.Tests/ScribanActionMenuTests.cs +++ b/tests/RepoM.ActionMenu.Core.Tests/ScribanActionMenuTests.cs @@ -51,12 +51,6 @@ public class ScribanActionMenuTests private const string TAGS = """ context: - - type: evaluate-script@1 - content: |- - func translate(input) - ret 'translate says:' + input; - end - - name: coenm - name1: coenm1 @@ -123,12 +117,6 @@ func sonar_url(project_id) private const string ACTION_MENU = """ context: - - type: evaluate-script@1 - content: |- - func translate(input) - ret 'translate says:' + input; - end - - name: coenm - name1: coenm1 diff --git a/tests/RepoM.Plugin.Heidi.Tests/Internal/HeidiConfigurationServiceTests.cs b/tests/RepoM.Plugin.Heidi.Tests/Internal/HeidiConfigurationServiceTests.cs index 9b42e645..c2de0379 100644 --- a/tests/RepoM.Plugin.Heidi.Tests/Internal/HeidiConfigurationServiceTests.cs +++ b/tests/RepoM.Plugin.Heidi.Tests/Internal/HeidiConfigurationServiceTests.cs @@ -24,6 +24,8 @@ public class HeidiConfigurationServiceTests { private const string FILENAME = "heidi.portable.txt"; private const string PATH = "C:\\heidi\\"; + private readonly string _fullFilename = Path.Combine(PATH, FILENAME); + private readonly TimeSpan _initTimeout = TimeSpan.FromSeconds(30); private readonly IFileSystem _fileSystem; private readonly IHeidiPortableConfigReader _configReader; @@ -55,7 +57,7 @@ public HeidiConfigurationServiceTests() A.CallTo(() => _fileSystem.FileSystemWatcher.New(A._, A._)).Returns(_fileWatcher); A.CallTo(() => _heidiSettings.ConfigFilename).Returns(FILENAME); A.CallTo(() => _heidiSettings.ConfigPath).Returns(PATH); - A.CallTo(() => _fileSystem.File.Exists(Path.Combine(PATH, FILENAME))).Returns(true); + A.CallTo(() => _fileSystem.File.Exists(_fullFilename)).Returns(true); A.CallTo(() => _repository.Remotes) .Returns(new List @@ -123,11 +125,11 @@ public static IEnumerable CtorNullArguments var hre = A.Dummy(); var hs = A.Dummy(); - yield return new object[] { l, fs, hpcr, hre, null!, }; - yield return new object[] { l, fs, hpcr, null!, hs, }; - yield return new object[] { l, fs, null!, hre, hs, }; - yield return new object[] { l, null!, hpcr, hre, hs, }; - yield return new object[] { null!, fs, hpcr, hre, hs, }; + yield return [l, fs, hpcr, hre, null!,]; + yield return [l, fs, hpcr, null!, hs,]; + yield return [l, fs, null!, hre, hs,]; + yield return [l, null!, hpcr, hre, hs,]; + yield return [null!, fs, hpcr, hre, hs,]; } } @@ -153,13 +155,13 @@ internal void Ctor_ShouldThrow_WhenArgumentIsNull( public async Task GetAllDatabases_ShouldReturnDatabases_WhenInitializedCompleted() { // arrange - A.CallTo(() => _configReader.ParseAsync(Path.Combine(PATH, FILENAME))) + A.CallTo(() => _configReader.ParseAsync(_fullFilename)) .Returns(Task.FromResult(_heidiConfigurationResult)); var mre = new ManualResetEvent(false); _sut.ConfigurationUpdated += (_, _) => mre.Set(); await _sut.InitializeAsync(); - mre.WaitOne(); + mre.WaitOne(_initTimeout); // act ImmutableArray result = _sut.GetAllDatabases(); @@ -174,8 +176,8 @@ public async Task GetByRepository_ShouldReturnDatabasesForSpecificRepository_Whe // arrange var mre = new ManualResetEvent(false); _sut.ConfigurationUpdated += (_, _) => mre.Set(); - A.CallTo(() => _fileSystem.File.Exists(Path.Combine(PATH, FILENAME))).Returns(true); - A.CallTo(() => _configReader.ParseAsync(Path.Combine(PATH, FILENAME))) + A.CallTo(() => _fileSystem.File.Exists(_fullFilename)).Returns(true); + A.CallTo(() => _configReader.ParseAsync(_fullFilename)) .Returns(Task.FromResult(_heidiConfigurationResult)); RepoHeidi? aRef; @@ -191,17 +193,17 @@ public async Task GetByRepository_ShouldReturnDatabasesForSpecificRepository_Whe }) .AssignsOutAndRefParametersLazily((HeidiSingleDatabaseConfiguration config, RepoHeidi? output) => { - var matches = _heidis.Where(x => x.HeidiKey.Equals(config.Key)).ToArray(); + RepoHeidi[] matches = _heidis.Where(x => x.HeidiKey.Equals(config.Key)).ToArray(); if (matches.Length > 0) { - return new object[] { matches.First(), }; + return [matches.First(),]; } - return new object[] { null!, }; + return [null!,]; }); await _sut.InitializeAsync(); - mre.WaitOne(TimeSpan.FromSeconds(2)); + mre.WaitOne(_initTimeout); // act IEnumerable result = _sut.GetByRepository(_repository); @@ -217,20 +219,20 @@ public async Task GetByRepository_ShouldReturnEmpty_WhenInitializationIsFinished { // arrange A.CallTo(() => _repository.Remotes) - .Returns(new List - { + .Returns( + [ new("bb", "http://github.com/a/b.git"), new(originKey, "http://github.com/coenm/Abcd.git"), - }); + ]); var mre = new ManualResetEvent(false); _sut.ConfigurationUpdated += (_, _) => mre.Set(); - A.CallTo(() => _fileSystem.File.Exists(Path.Combine(PATH, FILENAME))).Returns(true); - A.CallTo(() => _configReader.ParseAsync(Path.Combine(PATH, FILENAME))) + A.CallTo(() => _fileSystem.File.Exists(_fullFilename)).Returns(true); + A.CallTo(() => _configReader.ParseAsync(_fullFilename)) .Returns(Task.FromResult(_heidiConfigurationResult)); await _sut.InitializeAsync(); - mre.WaitOne(TimeSpan.FromSeconds(2)); + mre.WaitOne(_initTimeout); // act IEnumerable result = _sut.GetByRepository(_repository); @@ -249,12 +251,12 @@ public async Task GetByKey_ShouldReturnEmpty_WhenKeyIsNullOrEmpty(string? key) // arrange var mre = new ManualResetEvent(false); _sut.ConfigurationUpdated += (_, _) => mre.Set(); - A.CallTo(() => _fileSystem.File.Exists(Path.Combine(PATH, FILENAME))).Returns(true); - A.CallTo(() => _configReader.ParseAsync(Path.Combine(PATH, FILENAME))) + A.CallTo(() => _fileSystem.File.Exists(_fullFilename)).Returns(true); + A.CallTo(() => _configReader.ParseAsync(_fullFilename)) .Returns(Task.FromResult(_heidiConfigurationResult)); await _sut.InitializeAsync(); - mre.WaitOne(TimeSpan.FromSeconds(2)); + mre.WaitOne(_initTimeout); // act IEnumerable result = _sut.GetByKey(key!); @@ -268,17 +270,18 @@ public async Task InitializeAsync_ShouldReadHeidiFile_WhenFileExists() { var mre = new ManualResetEvent(false); _sut.ConfigurationUpdated += (_, _) => mre.Set(); - A.CallTo(() => _fileSystem.File.Exists(Path.Combine(PATH, FILENAME))).Returns(true); - A.CallTo(() => _configReader.ParseAsync(Path.Combine(PATH, FILENAME))) + A.CallTo(() => _fileSystem.File.Exists(_fullFilename)).Returns(true); + A.CallTo(() => _configReader.ParseAsync(_fullFilename)) .Returns(Task.FromResult(_heidiConfigurationResult)); // act await _sut.InitializeAsync(); - mre.WaitOne(TimeSpan.FromSeconds(2)); + var updated = mre.WaitOne(_initTimeout); // assert + updated.Should().BeTrue("we expect an event to happen."); A.CallTo(() => _fileSystem.FileSystemWatcher.New(A._, A._)).MustHaveHappened(); - A.CallTo(() => _configReader.ParseAsync(Path.Combine(PATH, FILENAME))).MustHaveHappenedOnceExactly(); + A.CallTo(() => _configReader.ParseAsync(_fullFilename)).MustHaveHappenedOnceExactly(); } [Fact] @@ -322,13 +325,12 @@ public async Task Events_ShouldNotBeProcessed_WhenWrongFilename() // act _changeEventDummyFileSystemWatcher.Change(PATH, FILENAME + "dummy"); - await Task.Delay(5000); + await Task.Delay(TimeSpan.FromSeconds(10)); // assert - A.CallTo(() => _configReader.ParseAsync(Path.Combine(PATH, FILENAME))).MustNotHaveHappened(); + A.CallTo(() => _configReader.ParseAsync(_fullFilename)).MustNotHaveHappened(); } - // fragille test, failed once on build server [Fact] public async Task Events_ShouldBeBundled_WhenHappeningWithinWindow() { @@ -341,7 +343,7 @@ public async Task Events_ShouldBeBundled_WhenHappeningWithinWindow() Task.FromResult(_heidiConfigurationResult)); await _sut.InitializeAsync(); - mre.WaitOne(TimeSpan.FromSeconds(1)); + mre.WaitOne(_initTimeout); Fake.ClearRecordedCalls(_configReader); // act @@ -351,10 +353,10 @@ public async Task Events_ShouldBeBundled_WhenHappeningWithinWindow() await Task.Delay(100); _changeEventDummyFileSystemWatcher.Change(PATH, FILENAME); - await Task.Delay(5000); + await Task.Delay(TimeSpan.FromSeconds(10)); // assert - A.CallTo(() => _configReader.ParseAsync(Path.Combine(PATH, FILENAME))).MustHaveHappenedOnceExactly(); + A.CallTo(() => _configReader.ParseAsync(_fullFilename)).MustHaveHappenedOnceExactly(); } [Fact] @@ -367,7 +369,7 @@ public async Task Dispose_ShouldRemoveSubscription() .Returns(Task.FromResult(new List())); await _sut.InitializeAsync(); - mre.WaitOne(TimeSpan.FromSeconds(1)); + mre.WaitOne(_initTimeout); Fake.ClearRecordedCalls(_configReader); @@ -375,10 +377,10 @@ public async Task Dispose_ShouldRemoveSubscription() _sut.Dispose(); _changeEventDummyFileSystemWatcher.Change(PATH, FILENAME); - await Task.Delay(5000); + await Task.Delay(TimeSpan.FromSeconds(10)); // assert - A.CallTo(() => _configReader.ParseAsync(Path.Combine(PATH, FILENAME))).MustNotHaveHappened(); + A.CallTo(() => _configReader.ParseAsync(_fullFilename)).MustNotHaveHappened(); } [Fact]