Skip to content

Commit

Permalink
Refactoring, moving classes around.
Browse files Browse the repository at this point in the history
  • Loading branch information
coenm committed Sep 11, 2023
1 parent da5fcfb commit b5e9a49
Show file tree
Hide file tree
Showing 35 changed files with 204 additions and 163 deletions.
1 change: 1 addition & 0 deletions src/RepoM.Api/Git/IRepositoryActionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace RepoM.Api.Git;
using System.Diagnostics;
using System.Linq;
using Microsoft.Extensions.Logging;
using RepoM.Api.RepositoryActions;

public interface IRepositoryActionProvider
{
Expand Down
94 changes: 0 additions & 94 deletions src/RepoM.Api/Git/RepositoryAction.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/RepoM.Api/IO/DefaultRepositoryActionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace RepoM.Api.IO;
using Microsoft.Extensions.Logging;
using RepoM.Api.Git;
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider;
using RepoM.Api.RepositoryActions;

public class DefaultRepositoryActionProvider : IRepositoryActionProvider
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionMappers;
using System.Linq;
using RepoM.Api.Git;
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.Actions;
using RepoM.Api.RepositoryActions;
using RepoM.Core.Plugin.Expressions;
using RepoM.Core.Plugin.Repository;
using RepoM.Core.Plugin.RepositoryActions.Actions;
Expand All @@ -30,7 +31,7 @@ IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(Repository
return Map(action as RepositoryActionAssociateFileV1, repository);
}

private IEnumerable<Git.RepositoryAction> Map(RepositoryActionAssociateFileV1? action, Repository repository)
private IEnumerable<RepositoryActions.RepositoryAction> Map(RepositoryActionAssociateFileV1? action, Repository repository)
{
if (action == null)
{
Expand All @@ -49,7 +50,7 @@ IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(Repository

var name = _expressionEvaluator.EvaluateNullStringExpression(action.Name, repository);

Git.RepositoryAction? menuItem = CreateFileAssociationSubMenu(
RepositoryActions.RepositoryAction? menuItem = CreateFileAssociationSubMenu(
repository,
name,
action.Extension);
Expand All @@ -60,14 +61,14 @@ IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(Repository
}
}

private static Git.RepositoryAction? CreateFileAssociationSubMenu(IRepository repository, string actionName, string filePattern)
private static RepositoryActions.RepositoryAction? CreateFileAssociationSubMenu(IRepository repository, string actionName, string filePattern)
{
if (!HasFiles(repository, filePattern))
{
return null;
}

return new Git.DeferredRepositoryAction(actionName, repository, false)
return new DeferredSubActionsRepositoryAction(actionName, repository, false)
{
DeferredSubActionsEnumerator = () =>
GetFiles(repository, filePattern)
Expand All @@ -76,9 +77,9 @@ IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(Repository
};
}

private static Git.RepositoryAction CreateProcessRunnerAction(string name, string process, IRepository repository, string arguments = "")
private static RepositoryActions.RepositoryAction CreateProcessRunnerAction(string name, string process, IRepository repository, string arguments = "")
{
return new Git.RepositoryAction(name, repository)
return new RepositoryActions.RepositoryAction(name, repository)
{
Action = new DelegateAction((_, _) => ProcessHelper.StartProcess(process, arguments)),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionMappers;
using RepoM.Api.Common;
using RepoM.Api.Git;
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.Actions;
using RepoM.Api.RepositoryActions;
using RepoM.Core.Plugin.Expressions;
using RepoM.Core.Plugin.Repository;
using RepoM.Core.Plugin.RepositoryActions.Actions;
Expand Down Expand Up @@ -70,7 +71,7 @@ private IEnumerable<RepositoryAction> Map(RepositoryActionBrowseRepositoryV1? ac
return CreateProcessRunnerAction(actionName, repository.Remotes[0].Url, repository);
}

return new DeferredRepositoryAction(actionName, repository, false)
return new DeferredSubActionsRepositoryAction(actionName, repository, false)
{
DeferredSubActionsEnumerator = () => repository.Remotes
.Take(50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionMappers;
using System.Collections.Generic;
using RepoM.Api.Git;
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.Actions;
using RepoM.Api.RepositoryActions;
using RepoM.Core.Plugin.Expressions;
using RepoM.Core.Plugin.RepositoryActions.Actions;
using RepositoryAction = RepoM.Api.Git.RepositoryAction;
using RepositoryAction = RepoM.Api.RepositoryActions.RepositoryAction;

public class ActionBrowserV1Mapper : IActionToRepositoryActionMapper
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionMappers;
using System.Collections.Generic;
using RepoM.Api.Git;
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.Actions;
using RepoM.Api.RepositoryActions;
using RepoM.Core.Plugin.Expressions;
using RepoM.Core.Plugin.Repository;
using RepoM.Core.Plugin.RepositoryActions.Actions;
Expand All @@ -28,7 +29,7 @@ IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(Repository
return Map(action as RepositoryActionCommandV1, repository);
}

private IEnumerable<Git.RepositoryAction> Map(RepositoryActionCommandV1? action, IRepository repository)
private IEnumerable<RepositoryActions.RepositoryAction> Map(RepositoryActionCommandV1? action, IRepository repository)
{
if (action == null)
{
Expand All @@ -44,7 +45,7 @@ IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(Repository
var command = _expressionEvaluator.EvaluateNullStringExpression(action.Command, repository);
var arguments = _expressionEvaluator.EvaluateNullStringExpression(action.Arguments, repository);

yield return new Git.RepositoryAction(name, repository)
yield return new RepositoryActions.RepositoryAction(name, repository)
{
Action = new DelegateAction((_, _) => ProcessHelper.StartProcess(command, arguments)),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionMappers;
using System.IO.Abstractions;
using RepoM.Api.Git;
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.Actions;
using RepoM.Api.RepositoryActions;
using RepoM.Core.Plugin.Expressions;
using RepoM.Core.Plugin.Repository;
using RepoM.Core.Plugin.RepositoryActions.Actions;
Expand All @@ -31,7 +32,7 @@ IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(Repository
return Map(action as RepositoryActionExecutableV1, repository);
}

private IEnumerable<Git.RepositoryAction> Map(RepositoryActionExecutableV1? action, IRepository repository)
private IEnumerable<RepositoryActions.RepositoryAction> Map(RepositoryActionExecutableV1? action, IRepository repository)
{
if (action == null)
{
Expand Down Expand Up @@ -68,7 +69,7 @@ IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(Repository
arguments = _expressionEvaluator.EvaluateStringExpression(action.Arguments, repository);
}

yield return new Git.RepositoryAction(name, repository)
yield return new RepositoryActions.RepositoryAction(name, repository)
{
Action = new DelegateAction((_, _) => ProcessHelper.StartProcess(normalized, arguments)),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionMappers;
using System.Linq;
using RepoM.Api.Git;
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.Actions;
using RepoM.Api.RepositoryActions;
using RepoM.Core.Plugin.Expressions;
using RepositoryAction = RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.RepositoryAction;

Expand All @@ -27,7 +28,7 @@ IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(Repository
return Map(action as RepositoryActionFolderV1, repository, actionMapperComposition);
}

private IEnumerable<Git.RepositoryAction> Map(RepositoryActionFolderV1? action, Repository repository, ActionMapperComposition actionMapperComposition)
private IEnumerable<RepositoryActions.RepositoryAction> Map(RepositoryActionFolderV1? action, Repository repository, ActionMapperComposition actionMapperComposition)
{
if (action == null)
{
Expand All @@ -49,7 +50,7 @@ IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(Repository

if (deferred)
{
yield return new DeferredRepositoryAction(name, repository, true)
yield return new DeferredSubActionsRepositoryAction(name, repository, true)
{
CanExecute = true,
DeferredSubActionsEnumerator = () =>
Expand All @@ -61,7 +62,7 @@ IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(Repository
}
else
{
yield return new Git.RepositoryAction(name, repository)
yield return new RepositoryActions.RepositoryAction(name, repository)
{
CanExecute = true,
SubActions = action.Items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionMappers;
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data;
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.Actions;
using RepoM.Api.IO.Variables;
using RepoM.Api.RepositoryActions;
using RepoM.Core.Plugin.Expressions;
using RepoM.Core.Plugin.Repository;
using RepositoryAction = RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.RepositoryAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionMappers;
using RepoM.Api.Common;
using RepoM.Api.Git;
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.Actions;
using RepoM.Api.RepositoryActions;
using RepoM.Core.Plugin.Expressions;
using RepoM.Core.Plugin.RepositoryActions.Actions;
using RepositoryAction = Data.RepositoryAction;
Expand Down Expand Up @@ -52,31 +53,31 @@ private IEnumerable<RepositoryActionBase> Map(RepositoryActionGitCheckoutV1? act
name = _translationService.Translate("Checkout");
}

yield return new DeferredRepositoryAction(name, repository, false)
yield return new DeferredSubActionsRepositoryAction(name, repository, false)
{
DeferredSubActionsEnumerator = () =>
repository.LocalBranches
.Take(50)
.Select(branch => new Git.RepositoryAction(branch, repository)
.Select(branch => new RepositoryActions.RepositoryAction(branch, repository)
{
Action = new DelegateAction((_, _) => _repositoryWriter.Checkout(repository, branch)),
CanExecute = !repository.CurrentBranch.Equals(branch, StringComparison.OrdinalIgnoreCase),
})
.Union(new RepositoryActionBase[]
{
new RepositorySeparatorAction(repository), // doesn't work todo
new DeferredRepositoryAction(_translationService.Translate("Remote branches"), repository, false)
new DeferredSubActionsRepositoryAction(_translationService.Translate("Remote branches"), repository, false)
{
DeferredSubActionsEnumerator = () =>
{
Git.RepositoryAction[] remoteBranches = repository
.ReadAllBranches()
.Select(branch => new Git.RepositoryAction(branch, repository)
{
Action = new DelegateAction((_, _) => _repositoryWriter.Checkout(repository, branch)),
CanExecute = !repository.CurrentBranch.Equals(branch, StringComparison.OrdinalIgnoreCase),
})
.ToArray();
RepositoryActions.RepositoryAction[] remoteBranches = repository
.ReadAllBranches()
.Select(branch => new RepositoryActions.RepositoryAction(branch, repository)
{
Action = new DelegateAction((_, _) => _repositoryWriter.Checkout(repository, branch)),
CanExecute = !repository.CurrentBranch.Equals(branch, StringComparison.OrdinalIgnoreCase),
})
.ToArray();
if (remoteBranches.Any())
{
Expand All @@ -85,11 +86,11 @@ private IEnumerable<RepositoryActionBase> Map(RepositoryActionGitCheckoutV1? act
return new RepositoryActionBase[]
{
new Git.RepositoryAction(_translationService.Translate("No remote branches found"), repository)
new RepositoryActions.RepositoryAction(_translationService.Translate("No remote branches found"), repository)
{
CanExecute = false,
},
new Git.RepositoryAction(_translationService.Translate("Try to fetch changes if you're expecting remote branches"), repository)
new RepositoryActions.RepositoryAction(_translationService.Translate("Try to fetch changes if you're expecting remote branches"), repository)
{
CanExecute = false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionMappers;
using RepoM.Api.Common;
using RepoM.Api.Git;
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.Actions;
using RepoM.Api.RepositoryActions;
using RepoM.Core.Plugin.Expressions;
using RepoM.Core.Plugin.RepositoryActions.Actions;
using RepositoryAction = RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.RepositoryAction;
Expand Down Expand Up @@ -39,7 +40,7 @@ IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(Repository
yield break;
}

yield return new Git.RepositoryAction(_translationService.Translate("Fetch"), repository)
yield return new RepositoryActions.RepositoryAction(_translationService.Translate("Fetch"), repository)
{
Action = new DelegateAction((_, _) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider.ActionMappers;
using RepoM.Api.Common;
using RepoM.Api.Git;
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.Actions;
using RepoM.Api.RepositoryActions;
using RepoM.Core.Plugin.Expressions;
using RepoM.Core.Plugin.RepositoryActions.Actions;
using RepositoryAction = RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data.RepositoryAction;
Expand Down Expand Up @@ -39,7 +40,7 @@ IEnumerable<RepositoryActionBase> IActionToRepositoryActionMapper.Map(Repository
yield break;
}

yield return new Git.RepositoryAction(_translationService.Translate("Pull"), repository)
yield return new RepositoryActions.RepositoryAction(_translationService.Translate("Pull"), repository)
{
Action = new DelegateAction((_, _) =>
{
Expand Down
Loading

0 comments on commit b5e9a49

Please sign in to comment.