Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove required translate method in yaml #130

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions docs_new/Tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
9 changes: 9 additions & 0 deletions src/RepoM.ActionMenu.Core/Model/InitialialFunctions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace RepoM.ActionMenu.Core.Model;

internal static class InitialFunctions
{
public static string? Translate(string? input)
{
return input;
}
}
5 changes: 0 additions & 5 deletions src/RepoM.Api/Resources/RepositoryActionsV2.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/RepoM.Api/Resources/TagsV2.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 0 additions & 12 deletions tests/RepoM.ActionMenu.Core.Tests/ScribanActionMenuTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,7 +57,7 @@ public HeidiConfigurationServiceTests()
A.CallTo(() => _fileSystem.FileSystemWatcher.New(A<string>._, A<string>._)).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<Remote>
Expand Down Expand Up @@ -123,11 +125,11 @@ public static IEnumerable<object[]> CtorNullArguments
var hre = A.Dummy<IHeidiRepositoryExtractor>();
var hs = A.Dummy<IHeidiSettings>();

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,];
}
}

Expand All @@ -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<HeidiSingleDatabaseConfiguration> result = _sut.GetAllDatabases();
Expand All @@ -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;
Expand All @@ -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<RepositoryHeidiConfiguration> result = _sut.GetByRepository(_repository);
Expand All @@ -217,20 +219,20 @@ public async Task GetByRepository_ShouldReturnEmpty_WhenInitializationIsFinished
{
// arrange
A.CallTo(() => _repository.Remotes)
.Returns(new List<Remote>
{
.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<RepositoryHeidiConfiguration> result = _sut.GetByRepository(_repository);
Expand All @@ -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<RepositoryHeidiConfiguration> result = _sut.GetByKey(key!);
Expand All @@ -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<string>._, A<string>._)).MustHaveHappened();
A.CallTo(() => _configReader.ParseAsync(Path.Combine(PATH, FILENAME))).MustHaveHappenedOnceExactly();
A.CallTo(() => _configReader.ParseAsync(_fullFilename)).MustHaveHappenedOnceExactly();
}

[Fact]
Expand Down Expand Up @@ -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()
{
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -367,18 +369,18 @@ public async Task Dispose_ShouldRemoveSubscription()
.Returns(Task.FromResult(new List<HeidiSingleDatabaseConfiguration>()));

await _sut.InitializeAsync();
mre.WaitOne(TimeSpan.FromSeconds(1));
mre.WaitOne(_initTimeout);

Fake.ClearRecordedCalls(_configReader);

// act
_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]
Expand Down
Loading