Skip to content

Commit

Permalink
preserve arguments check when executing hook
Browse files Browse the repository at this point in the history
Signed-off-by: sriv <srikanth.ddit@gmail.com>
  • Loading branch information
sriv committed Feb 6, 2024
1 parent ff37a99 commit 335624d
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/HookExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public HookExecutor(IAssemblyLoader assemblyLoader, IReflectionWrapper reflectio
_executionInfoMapper = mapper;
}

public async Task<ExecutionResult> Execute(string hookType, IHooksStrategy strategy,
IList<string> applicableTags,
public async Task<ExecutionResult> Execute(string hookType, IHooksStrategy strategy, IList<string> applicableTags,
ExecutionInfo info)
{
var methods = GetHookMethods(hookType, strategy, applicableTags);
Expand All @@ -47,7 +46,7 @@ public async Task<ExecutionResult> Execute(string hookType, IHooksStrategy strat
try
{
var context = _executionInfoMapper.ExecutionContextFrom(info);
await Execute(methodInfo, context);
await ExecuteHook(methodInfo, context);
}
catch (Exception ex)
{
Expand All @@ -62,14 +61,32 @@ public async Task<ExecutionResult> Execute(string hookType, IHooksStrategy strat

return executionResult;
}


private async Task ExecuteHook(MethodInfo method, params object[] objects)
{
if (HasArguments(method, objects))
await Execute(method, objects);
else
await Execute(method);
}


private static bool HasArguments(MethodInfo method, object[] args)
{
if (method.GetParameters().Length != args.Length)
return false;
return !args.Where((t, i) => t.GetType() != method.GetParameters()[i].ParameterType).Any();
}


private IEnumerable<string> GetHookMethods(string hookType, IHooksStrategy strategy,
IEnumerable<string> applicableTags)
{
var hooksFromRegistry = GetHooksFromRegistry(hookType);
return strategy.GetApplicableHooks(applicableTags, hooksFromRegistry);
}



private IEnumerable<IHookMethod> GetHooksFromRegistry(string hookType)
{
_registry = _registry ?? new HookRegistry(_assemblyLoader);
Expand Down

0 comments on commit 335624d

Please sign in to comment.