Skip to content
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
22 changes: 11 additions & 11 deletions src/RepoM.Api/IO/CustomEnvironmentVariableVariableProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ public static Dictionary<string, string> Get(Repository _)
{
return _envVars.Value ?? new Dictionary<string, string>(0);
}
}

public class ExecuteOnDisposed : IDisposable
{
private readonly Func<Dictionary<string, string>>? _func;

public ExecuteOnDisposed(Func<Dictionary<string, string>>? func)
private sealed class ExecuteOnDisposed : IDisposable
{
_func = func;
}
private readonly Func<Dictionary<string, string>>? _func;

public void Dispose()
{
_func?.Invoke();
public ExecuteOnDisposed(Func<Dictionary<string, string>>? func)
{
_func = func;
}

public void Dispose()
{
_func?.Invoke();
}
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/RepoM.Api/IO/ExpressionEvaluator/RepositoryContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace RepoM.Api.IO.ExpressionEvaluator;

using System;
using System.Collections.Generic;
using System.Linq;
using RepoM.Api.Git;

public class RepositoryContext
{
public RepositoryContext()
{
Repositories = Array.Empty<Repository>();
}

public RepositoryContext(params Repository[] repositories)
{
Repositories = repositories.ToArray();
}

public RepositoryContext(IEnumerable<Repository> repositories)
{
Repositories = repositories.ToArray();
}

public Repository[] Repositories { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,6 @@ namespace RepoM.Api.IO.ExpressionEvaluator;
using ExpressionStringEvaluator.VariableProviders;
using RepoM.Api.Git;

public class RepositoryContext
{
public RepositoryContext()
{
Repositories = Array.Empty<Repository>();
}

public RepositoryContext(params Repository[] repositories)
{
Repositories = repositories.ToArray();
}

public RepositoryContext(IEnumerable<Repository> repositories)
{
Repositories = repositories.ToArray();
}

public Repository[] Repositories { get; }
}

public class RepositoryExpressionEvaluator
{
private readonly ExpressionExecutor _expressionExecutor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider;
using System.Text;
using DotNetEnv;
using ExpressionStringEvaluator.Methods;
using Microsoft.Extensions.Logging;
using RepoM.Api.Common;
using RepoM.Api.Git;
using RepoM.Api.IO.ExpressionEvaluator;
Expand All @@ -25,6 +26,7 @@ public class RepositoryConfigurationReader
private readonly JsonDynamicRepositoryActionDeserializer _jsonAppSettingsDeserializer;
private readonly YamlDynamicRepositoryActionDeserializer _yamlAppSettingsDeserializer;
private readonly RepositoryExpressionEvaluator _repoExpressionEvaluator;
private readonly ILogger _logger;

private const string FILENAME = "RepositoryActions.";
public const string FILENAME_JSON = FILENAME + "json";
Expand All @@ -34,13 +36,15 @@ public RepositoryConfigurationReader(
IFileSystem fileSystem,
JsonDynamicRepositoryActionDeserializer jsonAppSettingsDeserializer,
YamlDynamicRepositoryActionDeserializer yamlAppSettingsDeserializer,
RepositoryExpressionEvaluator repoExpressionEvaluator)
RepositoryExpressionEvaluator repoExpressionEvaluator,
ILogger logger)
{
_appDataPathProvider = appDataPathProvider ?? throw new ArgumentNullException(nameof(appDataPathProvider));
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
_jsonAppSettingsDeserializer = jsonAppSettingsDeserializer ?? throw new ArgumentNullException(nameof(jsonAppSettingsDeserializer));
_yamlAppSettingsDeserializer = yamlAppSettingsDeserializer ?? throw new ArgumentNullException(nameof(yamlAppSettingsDeserializer));
_repoExpressionEvaluator = repoExpressionEvaluator ?? throw new ArgumentNullException(nameof(repoExpressionEvaluator));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

private string GetRepositoryActionsFilename(string basePath)
Expand Down Expand Up @@ -116,6 +120,7 @@ private string GetRepositoryActionsFilename(string basePath)
}
catch (Exception e)
{
_logger.LogWarning(e, "Could not read and deserialize file '{file}'", filename);
throw new InvalidConfigurationException(filename, e.Message, e);
}
}
Expand Down Expand Up @@ -149,11 +154,6 @@ List<EvaluatedVariable> EvaluateVariables(IEnumerable<Variable>? vars)
// load repo specific environment variables
foreach (FileReference fileRef in rootFile.RepositorySpecificEnvironmentFiles.Where(fileRef => fileRef != null))
{
if (envVars != null)
{
continue;
}

if (!IsEnabled(fileRef.When, true, repository))
{
continue;
Expand All @@ -168,11 +168,28 @@ List<EvaluatedVariable> EvaluateVariables(IEnumerable<Variable>? vars)

try
{
envVars = DotNetEnv.Env.Load(f, new DotNetEnv.LoadOptions(setEnvVars: false)).ToDictionary();
IEnumerable<KeyValuePair<string, string>>? currentEnvVars = Env.Load(f, new LoadOptions(setEnvVars: false));
if (envVars == null || !envVars.Any())
{
envVars = currentEnvVars.ToDictionary();
continue;
}

foreach (KeyValuePair<string, string> item in currentEnvVars)
{
if (!envVars.ContainsKey(item.Key))
{
envVars.Add(item.Key, item.Value);
}
else
{
_logger.LogTrace("Environment key was '{Key}' already set.", item.Key);
}
}
}
catch (Exception)
catch (Exception e)
{
// log warning
_logger.LogWarning(e, "Something went wrong loading an environment file");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace RepoM.Api.Tests.IO.ModuleBasedRepositoryActionProvider;
using ExpressionStringEvaluator.VariableProviders.DateTime;
using FakeItEasy;
using FluentAssertions;
using Microsoft.Extensions.Logging.Abstractions;
using RepoM.Api.Common;
using RepoM.Api.Git;
using RepoM.Api.IO;
Expand Down Expand Up @@ -145,7 +146,8 @@ public async Task Create_ShouldRespectMultiSelectRepos()
_fileSystem,
_jsonAppsettingsDeserializer,
_yamlAppsettingsDeserializer,
_repositoryExpressionEvaluator));
_repositoryExpressionEvaluator,
NullLogger.Instance));

// act
IEnumerable<RepositoryActionBase> result = sut.CreateActions(new Repository(), new Repository());
Expand All @@ -171,7 +173,8 @@ public async Task Create_ShouldNotCareAboutMultiSelectRepos_WhenSingleRepo()
_fileSystem,
_jsonAppsettingsDeserializer,
_yamlAppsettingsDeserializer,
_repositoryExpressionEvaluator));
_repositoryExpressionEvaluator,
NullLogger.Instance));

// act
IEnumerable<RepositoryActionBase> result = sut.CreateActions(new Repository());
Expand All @@ -197,7 +200,8 @@ public async Task Create_ShouldOnlyProcessActiveItems()
_fileSystem,
_jsonAppsettingsDeserializer,
_yamlAppsettingsDeserializer,
_repositoryExpressionEvaluator));
_repositoryExpressionEvaluator,
NullLogger.Instance));

// act
IEnumerable<RepositoryActionBase> result = sut.CreateActions(new Repository());
Expand All @@ -223,7 +227,8 @@ public async Task Create_ShouldProcessSeparator1()
_fileSystem,
_jsonAppsettingsDeserializer,
_yamlAppsettingsDeserializer,
_repositoryExpressionEvaluator));
_repositoryExpressionEvaluator,
NullLogger.Instance));

// act
IEnumerable<RepositoryActionBase> result = sut.CreateActions(new Repository());
Expand Down