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
2 changes: 1 addition & 1 deletion src/RepoM.Api/IO/DefaultRepositoryActionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public DefaultRepositoryActionProvider(
public RepositoryActionBase? GetSecondaryAction(Repository repository)
{
RepositoryActionBase[] actions = GetContextMenuActions(new[] { repository, }).Take(2).ToArray();
return actions.Length > 1 ? actions.ElementAt(1) : null;
return actions.Length > 1 ? actions[1] : null;
}

public IEnumerable<RepositoryActionBase> GetContextMenuActions(IEnumerable<Repository> repositories)
Expand Down
9 changes: 5 additions & 4 deletions src/RepoM.Api/IO/GitRepositoryFinderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public IGitRepositoryFinder Create()
{
if (!string.IsNullOrWhiteSpace(enabledSearchProviderName))
{
factory = _factories.FirstOrDefault(searchProviderFactory => searchProviderFactory.IsActive
&&
searchProviderFactory.Name.Equals(enabledSearchProviderName, StringComparison.CurrentCultureIgnoreCase));
factory = _factories.Find(searchProviderFactory =>
searchProviderFactory.IsActive
&&
searchProviderFactory.Name.Equals(enabledSearchProviderName, StringComparison.CurrentCultureIgnoreCase));
}

if (factory != null)
Expand All @@ -37,7 +38,7 @@ public IGitRepositoryFinder Create()
}

// Default, fallback
factory = _factories.FirstOrDefault(searchProviderFactory => searchProviderFactory is GravellGitRepositoryFinderFactory);
factory = _factories.Find(searchProviderFactory => searchProviderFactory is GravellGitRepositoryFinderFactory);
if (factory != null)
{
return factory.Create();
Expand Down
15 changes: 9 additions & 6 deletions src/RepoM.Api/IO/Methods/FindFilesMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace RepoM.Api.IO.Methods;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using ExpressionStringEvaluator.Methods;
using JetBrains.Annotations;
Expand All @@ -11,10 +12,12 @@ namespace RepoM.Api.IO.Methods;
[UsedImplicitly]
public class FindFilesMethod : IMethod
{
private readonly IFileSystem _fileSystem;
private readonly ILogger _logger;

public FindFilesMethod(ILogger logger)
public FindFilesMethod(IFileSystem fileSystem, ILogger logger)
{
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

Expand Down Expand Up @@ -57,15 +60,15 @@ public bool CanHandle(string method)
}
}

private static IEnumerable<string> GetFileEnumerator(string path, string searchPattern)
private IEnumerable<string> GetFileEnumerator(string path, string searchPattern)
{
// prefer EnumerateFileSystemInfos() over EnumerateFiles() to include packaged folders like
// .app or .xcodeproj on macOS
IDirectoryInfo directory = _fileSystem.DirectoryInfo.New(path);

var directory = new DirectoryInfo(path);
return directory
.EnumerateFileSystemInfos(searchPattern, SearchOption.AllDirectories)
.Select(f => f.FullName)
.Where(f => !f.StartsWith("."));
.EnumerateFileSystemInfos(searchPattern, SearchOption.AllDirectories)
.Select(f => f.FullName)
.Where(f => !f.StartsWith('.'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ private static IEnumerable<string> GetFileEnumerator(IRepository repository, str
return directory
.EnumerateFileSystemInfos(searchPattern, SearchOption.AllDirectories)
.Select(f => f.FullName)
.Where(f => !f.StartsWith("."));
.Where(f => !f.StartsWith('.'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool IActionToRepositoryActionMapper.CanHandleMultipleRepositories()
IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(RepositoryAction action, IEnumerable<Repository> repositories, ActionMapperComposition actionMapperComposition)
{
Repository[] repos = repositories as Repository[] ?? repositories.ToArray();
if (repos.Any(r => !_expressionEvaluator.EvaluateBooleanExpression(action.Active, r)))
if (Array.Exists(repos, r => !_expressionEvaluator.EvaluateBooleanExpression(action.Active, r)))
{
yield break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool IActionToRepositoryActionMapper.CanHandleMultipleRepositories()
IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(RepositoryAction action, IEnumerable<Repository> repositories, ActionMapperComposition actionMapperComposition)
{
Repository[] repos = repositories as Repository[] ?? repositories.ToArray();
if (repos.Any(r => !_expressionEvaluator.EvaluateBooleanExpression(action.Active, r)))
if (Array.Exists(repos, r => !_expressionEvaluator.EvaluateBooleanExpression(action.Active, r)))
{
yield break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool IActionToRepositoryActionMapper.CanHandleMultipleRepositories()
IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(RepositoryAction action, IEnumerable<Repository> repositories, ActionMapperComposition actionMapperComposition)
{
Repository[] repos = repositories as Repository[] ?? repositories.ToArray();
if (repos.Any(r => !_expressionEvaluator.EvaluateBooleanExpression(action.Active, r)))
if (Array.Exists(repos, r => !_expressionEvaluator.EvaluateBooleanExpression(action.Active, r)))
{
yield break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool IActionToRepositoryActionMapper.CanHandleMultipleRepositories()
IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(Data.RepositoryAction action, IEnumerable<Repository> repositories, ActionMapperComposition actionMapperComposition)
{
Repository[] repos = repositories as Repository[] ?? repositories.ToArray();
if (repos.Any(r => !_expressionEvaluator.EvaluateBooleanExpression(action.Active, r)))
if (Array.Exists(repos, r => !_expressionEvaluator.EvaluateBooleanExpression(action.Active, r)))
{
yield break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,6 @@ public RepositoryActionConfiguration Deserialize(string rawContent)
DeserializeRepositoryActions(token, configuration);
}

// if (version == 2)
// {
// token = jsonObject["env-files"];
// configuration.RepositorySpecificEnvironmentFiles.AddRange(TryDeserializeEnumerable<FileReference>(token));
//
// token = jsonObject["variables"];
// configuration.Variables.AddRange(TryDeserializeEnumerableVariable(token));
//
// token = jsonObject["tags"];
// DeserializeRepositoryTags(token, ref configuration);
//
// token = jsonObject["repository-actions"];
// DeserializeRepositoryActions(token, configuration);
// }

return configuration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private bool IsEnabled(string? booleanExpression, bool defaultWhenNullOrEmpty, I

private RepositoryActionConfiguration Deserialize(string extension, string rawContent)
{
if (extension.StartsWith("."))
if (extension.StartsWith('.'))
{
extension = extension[1..];
}
Expand Down Expand Up @@ -353,7 +353,7 @@ List<EvaluatedVariable> EvaluateVariables(IEnumerable<Variable>? vars)
using IDisposable d1 = RepoMVariableProviderStore.Push(variables ?? new List<EvaluatedVariable>(0));
using IDisposable d2 = EnvironmentVariableStore.Set(repositoryEnvVars);

foreach (TagsCollection tagsCollection in tags?.Where(t => t != null) ?? Array.Empty<TagsCollection>())
foreach (TagsCollection tagsCollection in ((IEnumerable<TagsCollection>?)tags) ?? Array.Empty<TagsCollection>())
{
using IDisposable d3 = RepoMVariableProviderStore.Push(EvaluateVariables(tagsCollection.Variables));

Expand Down Expand Up @@ -463,7 +463,7 @@ public IEnumerable<RepositoryActionBase> CreateActions(params Repository[] repos
using IDisposable d2 = EnvironmentVariableStore.Set(repositoryEnvVars ?? new Dictionary<string, string>());

// load variables global
foreach (ActionsCollection actionsCollection in actions?.Where(action => action != null) ?? Array.Empty<ActionsCollection>())
foreach (ActionsCollection actionsCollection in ((IEnumerable<ActionsCollection>?)actions) ?? Array.Empty<ActionsCollection>())
{
using IDisposable d3 = RepoMVariableProviderStore.Push(EvaluateVariables(actionsCollection.Variables, singleRepository));

Expand All @@ -473,7 +473,7 @@ public IEnumerable<RepositoryActionBase> CreateActions(params Repository[] repos

if (multiSelectRequired)
{
var actionNotCapableForMultipleRepos = repositories.Any(repo => !IsEnabled(action.MultiSelectEnabled, false, repo));
var actionNotCapableForMultipleRepos = Array.Exists(repositories, repo => !IsEnabled(action.MultiSelectEnabled, false, repo));
if (actionNotCapableForMultipleRepos)
{
continue;
Expand Down Expand Up @@ -535,7 +535,7 @@ private IEnumerable<RepositoryAction> CreateFailing(Exception ex, string? filena
}
}

private object? Evaluate(object? input, Repository repository)
private object? Evaluate(object? input, IRepository repository)
{
if (input is string s)
{
Expand All @@ -545,7 +545,7 @@ private IEnumerable<RepositoryAction> CreateFailing(Exception ex, string? filena
return input;
}

private bool IsEnabled(string? booleanExpression, bool defaultWhenNullOrEmpty, Repository repository)
private bool IsEnabled(string? booleanExpression, bool defaultWhenNullOrEmpty, IRepository repository)
{
return string.IsNullOrWhiteSpace(booleanExpression)
? defaultWhenNullOrEmpty
Expand Down
2 changes: 1 addition & 1 deletion src/RepoM.Api/IO/WindowsPathSkipper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public WindowsPathSkipper()

public bool ShouldSkip(string path)
{
return _exclusions.Any(ex => path.IndexOf(ex, StringComparison.OrdinalIgnoreCase) > -1);
return _exclusions.Exists(ex => path.IndexOf(ex, StringComparison.OrdinalIgnoreCase) > -1);
}
}
2 changes: 1 addition & 1 deletion src/RepoM.App/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace RepoM.App;
using RepoM.App.Plugins;
using RepoM.App.Services.HotKey;

public static class Bootstrapper // this should be internal, but made public because of test.
internal static class Bootstrapper
{
public static readonly Container Container = new();

Expand Down
1 change: 1 addition & 0 deletions src/RepoM.App/InternalsVisisbleTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("RepoM.App.Tests")]
23 changes: 12 additions & 11 deletions src/RepoM.App/RepositoryFiltering/DefaultINamedQueryParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,27 @@ internal class DefaultQueryParser : INamedQueryParser

public IQuery Parse(string text)
{
List<IQuery> q = new();
IQuery? isPinnedQuery = null;
if (text.StartsWith("is:pinned"))
{
q.Add(new SimpleTerm("is", "pinned"));
text = text.Replace("is:pinned", " ");
isPinnedQuery = new SimpleTerm("is", "pinned");
text = text.Replace("is:pinned", string.Empty);
}
else if(text.StartsWith("is:unpinned"))
{
q.Add(new SimpleTerm("is", "unpinned"));
text = text.Replace("is:unpinned", " ");
isPinnedQuery = new SimpleTerm("is", "unpinned");
text = text.Replace("is:unpinned", string.Empty);
}

q.Add(new FreeText(text));

if (q.Any())
if (isPinnedQuery != null && string.IsNullOrWhiteSpace(text))
{
return new AndQuery(q.ToArray());

return isPinnedQuery;
}

return q.First();
var freeTextQuery = new FreeText(text);

return isPinnedQuery == null
? freeTextQuery
: new AndQuery(isPinnedQuery, freeTextQuery);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public FreeTextMatcher(bool ignoreCase, bool ignoreCaseTag)
return null;
}

if (repository.Tags.Any(x => x.Equals(st.Value, _stringComparisonTag)))
if (Array.Exists(repository.Tags, x => x.Equals(st.Value, _stringComparisonTag)))
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static bool CheckTerm(in string term)
}

var value = term.Value;
return repository.Tags.Any(tag =>
return Array.Exists(repository.Tags, tag =>
tag.Equals(value, StringComparison.CurrentCulture)
||
tag.StartsWith(value, StringComparison.CurrentCulture));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ private Guid FindRepositoryGuid(IRepository repository)
}

GitRepository[] selectedRepos = _devOpsGitRepositories.Values
.Where(x => x.ValidRemoteUrls.Any(u => u.Equals(searchRepoUrl, StringComparison.CurrentCultureIgnoreCase)))
.Where(x => Array.Exists(x.ValidRemoteUrls, u => u.Equals(searchRepoUrl, StringComparison.CurrentCultureIgnoreCase)))
.ToArray();

if (selectedRepos.Length == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ namespace RepoM.Plugin.AzureDevOps.RepositoryFiltering;

using RepoM.Core.Plugin.RepositoryFiltering.Clause.Terms;
using RepoM.Core.Plugin.RepositoryFiltering;
using System.Linq;
using System;
using RepoM.Core.Plugin.Repository;
using RepoM.Plugin.AzureDevOps.Internal;
Expand Down Expand Up @@ -43,7 +42,7 @@ public HasPullRequestsMatcher(IAzureDevOpsPullRequestService azureDevOpsPullRequ
return null;
}

if (_values.Any(x => x.Equals(st.Value, _stringComparisonValue)))
if (Array.Exists(_values, x => x.Equals(st.Value, _stringComparisonValue)))
{
return HasPullRequests(repository);
}
Expand Down
56 changes: 56 additions & 0 deletions tests/RepoM.Api.Tests/IO/GitRepositoryFinderFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace RepoM.Api.Tests.IO;

using System;
using System.Collections.Generic;
using FakeItEasy;
using FluentAssertions;
using RepoM.Api.Common;
using RepoM.Api.IO;
using RepoM.Core.Plugin.RepositoryFinder;
using Xunit;

public class GitRepositoryFinderFactoryTests
{
private readonly IAppSettingsService _appSettingsService;
private readonly ISingleGitRepositoryFinderFactory _singleGitRepositoryFinderFactory1;
private readonly ISingleGitRepositoryFinderFactory _singleGitRepositoryFinderFactory2;

public GitRepositoryFinderFactoryTests()
{
_appSettingsService = A.Fake<IAppSettingsService>();
_singleGitRepositoryFinderFactory1 = A.Fake<ISingleGitRepositoryFinderFactory>();
_singleGitRepositoryFinderFactory2 = A.Fake<ISingleGitRepositoryFinderFactory>();
}

[Fact]
public void Ctor_ShouldThrow_WhenArgumentNull()
{
// arrange

// act
Func<GitRepositoryFinderFactory> act1 = () => new GitRepositoryFinderFactory(A.Dummy<IAppSettingsService>(), null!);
Func<GitRepositoryFinderFactory> act2 = () => new GitRepositoryFinderFactory(null!, new[] { A.Dummy<ISingleGitRepositoryFinderFactory>(), });

// assert
act1.Should().Throw<ArgumentNullException>();
act2.Should().Throw<ArgumentNullException>();
}

[Fact]
public void Create_ShouldReturnCreationOfFirstFactory_WhenFirstFactoryIsEnabled()
{
// arrange
IGitRepositoryFinder gitRepositoryFinder = A.Fake<IGitRepositoryFinder>();
A.CallTo(() => _appSettingsService.EnabledSearchProviders).Returns(new List<string>() { "Dummy123", "Dummy555", });
A.CallTo(() => _singleGitRepositoryFinderFactory1.IsActive).Returns(true);
A.CallTo(() => _singleGitRepositoryFinderFactory1.Name).Returns("Dummy123");
A.CallTo(() => _singleGitRepositoryFinderFactory1.Create()).Returns(gitRepositoryFinder);
var sut = new GitRepositoryFinderFactory(_appSettingsService, new[] { _singleGitRepositoryFinderFactory1, _singleGitRepositoryFinderFactory2, });

// act
IGitRepositoryFinder result = sut.Create();

// assert
result.Should().BeSameAs(gitRepositoryFinder);
}
}
Loading