From ccc55150d1db0fb167dd47f10b46ef2063d3c2f2 Mon Sep 17 00:00:00 2001 From: Kimarie Hoot Date: Thu, 1 Sep 2022 23:21:59 +0000 Subject: [PATCH 1/7] Dispatches ComputeHistoryActivity from GitRepositoryClonedEvent --- .../Git/CloneGitRepositoryActivity.cs | 3 ++- .../Functionality/Git/GitRepositoryClonedEvent.cs | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs b/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs index da5fb4fd5..cf9cdf264 100644 --- a/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs +++ b/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs @@ -55,7 +55,8 @@ public void Handle(IApplicationEventEngine eventClient) eventClient.Fire(new GitRepositoryClonedEvent { GitRepositoryId = gitRepository.Id, - AnalysisId = _analysisId + AnalysisId = _analysisId, + GitPath = _gitPath }); } catch (GitException e) diff --git a/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs b/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs index c80ef0167..38a1cefb0 100644 --- a/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs +++ b/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs @@ -1,17 +1,27 @@ using System; +using Corgibytes.Freshli.Cli.Functionality.Analysis; using Corgibytes.Freshli.Cli.Functionality.Engine; +using Corgibytes.Freshli.Cli.Functionality.History; +using Microsoft.Extensions.DependencyInjection; namespace Corgibytes.Freshli.Cli.Functionality.Git; public class GitRepositoryClonedEvent : IApplicationEvent { + public IServiceProvider ServiceProvider = null!; + public string GitRepositoryId { get; init; } = null!; - // ReSharper disable once UnusedAutoPropertyAccessor.Global public Guid AnalysisId { get; init; } + public string GitPath { get; init; } = null!; + public void Handle(IApplicationActivityEngine eventClient) { - // TODO - Dispatch(ComputeHistoryActivity) + var cacheDb = ServiceProvider.GetRequiredService(); + var computeHistoryService = ServiceProvider.GetRequiredService(); + var analysisLocation = ServiceProvider.GetRequiredService(); + + eventClient.Dispatch(new ComputeHistoryActivity(GitPath, cacheDb, computeHistoryService, AnalysisId, analysisLocation)); } } From 783cf4217deedbb27a30ed2dfcd606556356d368 Mon Sep 17 00:00:00 2001 From: Kimarie Hoot Date: Fri, 2 Sep 2022 00:07:56 +0000 Subject: [PATCH 2/7] Adds GitRepositoryClonedEventTest.cs --- .../Git/GitRepositoryClonedEventTest.cs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs diff --git a/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs b/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs new file mode 100644 index 000000000..564d05e48 --- /dev/null +++ b/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs @@ -0,0 +1,46 @@ +using System; +using Corgibytes.Freshli.Cli.Functionality; +using Corgibytes.Freshli.Cli.Functionality.Analysis; +using Corgibytes.Freshli.Cli.Functionality.Engine; +using Corgibytes.Freshli.Cli.Functionality.Git; +using Corgibytes.Freshli.Cli.Functionality.History; +using Moq; +using Xunit; + +namespace Corgibytes.Freshli.Cli.Test.Functionality.Git; + +[UnitTest] +public class GitRepositoryClonedEventTest +{ + [Fact] + public void CorrectlyDispatchesComputeHistoryActivity() + { + var serviceProvider = new Mock(); + + var gitPath = "test"; + var analysisId = new Guid(); + var clonedEvent = new GitRepositoryClonedEvent + { + ServiceProvider = serviceProvider.Object, + GitRepositoryId = "example", + AnalysisId = analysisId, + GitPath = gitPath + }; + + var cacheDb = new Mock(); + serviceProvider.Setup(mock => mock.GetService(typeof(ICacheDb))).Returns(cacheDb.Object); + + var computeHistoryService = new Mock(); + serviceProvider.Setup(mock => mock.GetService(typeof(IComputeHistory))).Returns(computeHistoryService.Object); + + var analysisLocation = new Mock(); + serviceProvider.Setup(mock => mock.GetService(typeof(IAnalysisLocation))).Returns(analysisLocation.Object); + + var engine = new Mock(); + + clonedEvent.Handle(engine.Object); + + // Verify that it dispatches ComputeHistoryActivity + engine.Verify(mock => mock.Dispatch(It.Is(value => true))); + } +} From 7a63f75614b5b76020cadebb61bae8e948010c5a Mon Sep 17 00:00:00 2001 From: Kimarie Hoot Date: Thu, 8 Sep 2022 10:03:46 -0600 Subject: [PATCH 3/7] Updates git clone repository to use new service provider injection Co-Authored-By: Dona Pop <50669675+donabp@users.noreply.github.com> Co-Authored-By: Edwin Kortman <7047894+edwinkortman@users.noreply.github.com> --- .../Git/GitRepositoryClonedEventTest.cs | 10 ++++------ .../Functionality/Git/CloneGitRepositoryActivity.cs | 3 ++- .../Functionality/Git/GitRepositoryClonedEvent.cs | 12 ++++++------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs b/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs index 564d05e48..77f058049 100644 --- a/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs +++ b/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs @@ -21,22 +21,20 @@ public void CorrectlyDispatchesComputeHistoryActivity() var analysisId = new Guid(); var clonedEvent = new GitRepositoryClonedEvent { - ServiceProvider = serviceProvider.Object, GitRepositoryId = "example", AnalysisId = analysisId, GitPath = gitPath }; - var cacheDb = new Mock(); - serviceProvider.Setup(mock => mock.GetService(typeof(ICacheDb))).Returns(cacheDb.Object); + var cacheManager = new Mock(); + cacheManager.Setup(mock => mock.GetCacheDb(It.IsAny())).Returns(new CacheDb("example")); + serviceProvider.Setup(mock => mock.GetService(typeof(ICacheManager))).Returns(cacheManager.Object); var computeHistoryService = new Mock(); serviceProvider.Setup(mock => mock.GetService(typeof(IComputeHistory))).Returns(computeHistoryService.Object); - var analysisLocation = new Mock(); - serviceProvider.Setup(mock => mock.GetService(typeof(IAnalysisLocation))).Returns(analysisLocation.Object); - var engine = new Mock(); + engine.Setup(mock => mock.ServiceProvider).Returns(serviceProvider.Object); clonedEvent.Handle(engine.Object); diff --git a/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs b/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs index cf9cdf264..5eb3fa4b9 100644 --- a/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs +++ b/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs @@ -56,7 +56,8 @@ public void Handle(IApplicationEventEngine eventClient) { GitRepositoryId = gitRepository.Id, AnalysisId = _analysisId, - GitPath = _gitPath + GitPath = _gitPath, + CacheDir = _cacheDir }); } catch (GitException e) diff --git a/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs b/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs index 38a1cefb0..b5b2e6a26 100644 --- a/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs +++ b/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs @@ -8,20 +8,20 @@ namespace Corgibytes.Freshli.Cli.Functionality.Git; public class GitRepositoryClonedEvent : IApplicationEvent { - public IServiceProvider ServiceProvider = null!; - public string GitRepositoryId { get; init; } = null!; public Guid AnalysisId { get; init; } public string GitPath { get; init; } = null!; + public string CacheDir { get; init; } = null!; + public void Handle(IApplicationActivityEngine eventClient) { - var cacheDb = ServiceProvider.GetRequiredService(); - var computeHistoryService = ServiceProvider.GetRequiredService(); - var analysisLocation = ServiceProvider.GetRequiredService(); + var cacheManager = eventClient.ServiceProvider.GetRequiredService(); + var computeHistoryService = eventClient.ServiceProvider.GetRequiredService(); + var analysisLocation = new AnalysisLocation(CacheDir, GitRepositoryId); - eventClient.Dispatch(new ComputeHistoryActivity(GitPath, cacheDb, computeHistoryService, AnalysisId, analysisLocation)); + eventClient.Dispatch(new ComputeHistoryActivity(GitPath, cacheManager.GetCacheDb(CacheDir), computeHistoryService, AnalysisId, analysisLocation)); } } From c735533a2c6212cba713acd0215cb9592ddd3a2e Mon Sep 17 00:00:00 2001 From: Kimarie Hoot Date: Thu, 8 Sep 2022 10:07:10 -0600 Subject: [PATCH 4/7] Removes unused 'using' statement in GitRepositoryClonedEventTest.cs Co-authored-by: Dona Pop Co-authored-by: Edwin Kortman --- .../Functionality/Git/GitRepositoryClonedEventTest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs b/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs index 77f058049..cc33fa40e 100644 --- a/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs +++ b/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs @@ -1,6 +1,5 @@ using System; using Corgibytes.Freshli.Cli.Functionality; -using Corgibytes.Freshli.Cli.Functionality.Analysis; using Corgibytes.Freshli.Cli.Functionality.Engine; using Corgibytes.Freshli.Cli.Functionality.Git; using Corgibytes.Freshli.Cli.Functionality.History; From adf5af30fe9f752efa2204150a8aad2046a9794c Mon Sep 17 00:00:00 2001 From: Kimarie Hoot Date: Fri, 9 Sep 2022 12:52:07 -0600 Subject: [PATCH 5/7] Addresses code review comments This commit moves the service injection from GitRepositoryClonedEvent.cs to ComputeHistoryActivity.cs and updates the unit tests. This commit also makes fields in ComputeHistoryActivity.cs public so they can be checked by GitRepositoryClonedEventTest.cs --- .../Git/GitRepositoryClonedEventTest.cs | 20 ++++------- .../History/ComputeHistoryActivityTest.cs | 13 +++++-- .../Git/GitRepositoryClonedEvent.cs | 6 +--- .../History/ComputeHistoryActivity.cs | 35 +++++++++++-------- 4 files changed, 39 insertions(+), 35 deletions(-) diff --git a/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs b/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs index cc33fa40e..87191c4e0 100644 --- a/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs +++ b/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs @@ -1,5 +1,4 @@ using System; -using Corgibytes.Freshli.Cli.Functionality; using Corgibytes.Freshli.Cli.Functionality.Engine; using Corgibytes.Freshli.Cli.Functionality.Git; using Corgibytes.Freshli.Cli.Functionality.History; @@ -14,30 +13,25 @@ public class GitRepositoryClonedEventTest [Fact] public void CorrectlyDispatchesComputeHistoryActivity() { - var serviceProvider = new Mock(); - var gitPath = "test"; + var cacheDir = "example"; var analysisId = new Guid(); var clonedEvent = new GitRepositoryClonedEvent { GitRepositoryId = "example", AnalysisId = analysisId, - GitPath = gitPath + GitPath = gitPath, + CacheDir = cacheDir }; - var cacheManager = new Mock(); - cacheManager.Setup(mock => mock.GetCacheDb(It.IsAny())).Returns(new CacheDb("example")); - serviceProvider.Setup(mock => mock.GetService(typeof(ICacheManager))).Returns(cacheManager.Object); - - var computeHistoryService = new Mock(); - serviceProvider.Setup(mock => mock.GetService(typeof(IComputeHistory))).Returns(computeHistoryService.Object); - var engine = new Mock(); - engine.Setup(mock => mock.ServiceProvider).Returns(serviceProvider.Object); clonedEvent.Handle(engine.Object); // Verify that it dispatches ComputeHistoryActivity - engine.Verify(mock => mock.Dispatch(It.Is(value => true))); + engine.Verify(mock => mock.Dispatch(It.Is(value => + value.AnalysisId == analysisId && + value.CacheDir == cacheDir && + value.GitExecutablePath == gitPath))); } } diff --git a/Corgibytes.Freshli.Cli.Test/Functionality/History/ComputeHistoryActivityTest.cs b/Corgibytes.Freshli.Cli.Test/Functionality/History/ComputeHistoryActivityTest.cs index fc7aa94ac..2f3cbcfda 100644 --- a/Corgibytes.Freshli.Cli.Test/Functionality/History/ComputeHistoryActivityTest.cs +++ b/Corgibytes.Freshli.Cli.Test/Functionality/History/ComputeHistoryActivityTest.cs @@ -45,11 +45,20 @@ public void FiresHistoryIntervalStopFoundEvents() var analysisLocation = new Mock(); + var serviceProvider = new Mock(); + _eventEngine.Setup(mock => mock.ServiceProvider).Returns(serviceProvider.Object); + + var cacheDir = "example"; + var cacheManager = new Mock(); + cacheManager.Setup(mock => mock.GetCacheDb(It.IsAny())).Returns(_cacheDb.Object); + serviceProvider.Setup(mock => mock.GetService(typeof(ICacheManager))).Returns(cacheManager.Object); + + serviceProvider.Setup(mock => mock.GetService(typeof(IComputeHistory))).Returns(_computeHistory.Object); + // Act new ComputeHistoryActivity( "git", - _cacheDb.Object, - _computeHistory.Object, + cacheDir, new Guid("cbc83480-ae47-46de-91df-60747ca8fb09"), analysisLocation.Object ).Handle(_eventEngine.Object); diff --git a/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs b/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs index b5b2e6a26..38748e9ca 100644 --- a/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs +++ b/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs @@ -2,7 +2,6 @@ using Corgibytes.Freshli.Cli.Functionality.Analysis; using Corgibytes.Freshli.Cli.Functionality.Engine; using Corgibytes.Freshli.Cli.Functionality.History; -using Microsoft.Extensions.DependencyInjection; namespace Corgibytes.Freshli.Cli.Functionality.Git; @@ -18,10 +17,7 @@ public class GitRepositoryClonedEvent : IApplicationEvent public void Handle(IApplicationActivityEngine eventClient) { - var cacheManager = eventClient.ServiceProvider.GetRequiredService(); - var computeHistoryService = eventClient.ServiceProvider.GetRequiredService(); var analysisLocation = new AnalysisLocation(CacheDir, GitRepositoryId); - - eventClient.Dispatch(new ComputeHistoryActivity(GitPath, cacheManager.GetCacheDb(CacheDir), computeHistoryService, AnalysisId, analysisLocation)); + eventClient.Dispatch(new ComputeHistoryActivity(GitPath, CacheDir, AnalysisId, analysisLocation)); } } diff --git a/Corgibytes.Freshli.Cli/Functionality/History/ComputeHistoryActivity.cs b/Corgibytes.Freshli.Cli/Functionality/History/ComputeHistoryActivity.cs index 43771c3a6..7634759e6 100644 --- a/Corgibytes.Freshli.Cli/Functionality/History/ComputeHistoryActivity.cs +++ b/Corgibytes.Freshli.Cli/Functionality/History/ComputeHistoryActivity.cs @@ -2,38 +2,43 @@ using Corgibytes.Freshli.Cli.Functionality.Analysis; using Corgibytes.Freshli.Cli.Functionality.Engine; using Corgibytes.Freshli.Cli.Functionality.Git; -using Newtonsoft.Json; +using Microsoft.Extensions.DependencyInjection; namespace Corgibytes.Freshli.Cli.Functionality.History; public class ComputeHistoryActivity : IApplicationActivity { - [JsonProperty] private readonly Guid _analysisId; - [JsonProperty] private readonly IAnalysisLocation _analysisLocation; - [JsonProperty] private readonly ICacheDb _cacheDb; - [JsonProperty] private readonly IComputeHistory _computeHistoryService; - private readonly string _gitExecutablePath; + public Guid AnalysisId; - public ComputeHistoryActivity(string gitExecutablePath, ICacheDb cacheDb, IComputeHistory computeHistoryService, + // ReSharper disable once MemberCanBePrivate.Global + public readonly IAnalysisLocation AnalysisLocation; + + public readonly string GitExecutablePath; + + public readonly string CacheDir; + + public ComputeHistoryActivity(string gitExecutablePath, string cacheDir, Guid analysisId, IAnalysisLocation analysisLocation) { - _gitExecutablePath = gitExecutablePath; - _cacheDb = cacheDb; - _computeHistoryService = computeHistoryService; - _analysisId = analysisId; - _analysisLocation = analysisLocation; + GitExecutablePath = gitExecutablePath; + CacheDir = cacheDir; + AnalysisId = analysisId; + AnalysisLocation = analysisLocation; } public void Handle(IApplicationEventEngine eventClient) { - var analysis = _cacheDb.RetrieveAnalysis(_analysisId); + var computeHistoryService = eventClient.ServiceProvider.GetRequiredService(); + var cacheManager = eventClient.ServiceProvider.GetRequiredService(); + var cacheDb = cacheManager.GetCacheDb(CacheDir); + var analysis = cacheDb.RetrieveAnalysis(AnalysisId); if (analysis == null) { return; } var historyIntervalStops = - _computeHistoryService.ComputeWithHistoryInterval(_analysisLocation, _gitExecutablePath, + computeHistoryService.ComputeWithHistoryInterval(AnalysisLocation, GitExecutablePath, analysis.HistoryInterval); foreach (var historyIntervalStop in historyIntervalStops) @@ -41,7 +46,7 @@ public void Handle(IApplicationEventEngine eventClient) eventClient.Fire(new HistoryIntervalStopFoundEvent { GitCommitIdentifier = historyIntervalStop.GitCommitIdentifier, - AnalysisLocation = _analysisLocation + AnalysisLocation = AnalysisLocation }); } } From 744d8af0f8fc498f2f2f3e024a67339ea944e838 Mon Sep 17 00:00:00 2001 From: Kimarie Hoot Date: Mon, 12 Sep 2022 11:37:51 -0600 Subject: [PATCH 6/7] Refactors CloneGitRepositoryActivity to pass the AnalysisLocation This uses the analysis location to access the cache dir and the repository ID instead passing them as separate parameters. --- .../Git/CloneGitRepositoryActivityTest.cs | 3 ++- .../Functionality/Git/GitRepositoryClonedEventTest.cs | 11 +++++++---- .../History/ComputeHistoryActivityTest.cs | 2 -- .../CommandRunners/Git/GitCloneCommandRunner.cs | 2 +- .../Functionality/Git/CloneGitRepositoryActivity.cs | 5 +++-- .../Functionality/Git/GitRepositoryClonedEvent.cs | 7 ++----- .../Functionality/History/ComputeHistoryActivity.cs | 10 +++------- 7 files changed, 18 insertions(+), 22 deletions(-) diff --git a/Corgibytes.Freshli.Cli.Test/Functionality/Git/CloneGitRepositoryActivityTest.cs b/Corgibytes.Freshli.Cli.Test/Functionality/Git/CloneGitRepositoryActivityTest.cs index 7907f2390..e5d410cee 100644 --- a/Corgibytes.Freshli.Cli.Test/Functionality/Git/CloneGitRepositoryActivityTest.cs +++ b/Corgibytes.Freshli.Cli.Test/Functionality/Git/CloneGitRepositoryActivityTest.cs @@ -56,7 +56,8 @@ public void HandlerFiresGitRepositoryClonedEventWhenInvokedFromCli() activity.Handle(_eventEngine.Object); _eventEngine.Verify(mock => - mock.Fire(It.Is(value => value.GitRepositoryId == _repositoryId))); + mock.Fire(It.Is(value => + value.AnalysisLocation.RepositoryId == _repositoryId))); } [Fact] diff --git a/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs b/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs index 87191c4e0..8c89c64c5 100644 --- a/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs +++ b/Corgibytes.Freshli.Cli.Test/Functionality/Git/GitRepositoryClonedEventTest.cs @@ -1,4 +1,5 @@ using System; +using Corgibytes.Freshli.Cli.Functionality.Analysis; using Corgibytes.Freshli.Cli.Functionality.Engine; using Corgibytes.Freshli.Cli.Functionality.Git; using Corgibytes.Freshli.Cli.Functionality.History; @@ -15,13 +16,15 @@ public void CorrectlyDispatchesComputeHistoryActivity() { var gitPath = "test"; var cacheDir = "example"; + var gitRepositoryId = "example"; var analysisId = new Guid(); + var analysisLocation = new AnalysisLocation(cacheDir, gitRepositoryId); + var clonedEvent = new GitRepositoryClonedEvent { - GitRepositoryId = "example", AnalysisId = analysisId, GitPath = gitPath, - CacheDir = cacheDir + AnalysisLocation = analysisLocation }; var engine = new Mock(); @@ -31,7 +34,7 @@ public void CorrectlyDispatchesComputeHistoryActivity() // Verify that it dispatches ComputeHistoryActivity engine.Verify(mock => mock.Dispatch(It.Is(value => value.AnalysisId == analysisId && - value.CacheDir == cacheDir && - value.GitExecutablePath == gitPath))); + value.GitExecutablePath == gitPath && + value.AnalysisLocation == analysisLocation))); } } diff --git a/Corgibytes.Freshli.Cli.Test/Functionality/History/ComputeHistoryActivityTest.cs b/Corgibytes.Freshli.Cli.Test/Functionality/History/ComputeHistoryActivityTest.cs index 2f3cbcfda..3ff926aba 100644 --- a/Corgibytes.Freshli.Cli.Test/Functionality/History/ComputeHistoryActivityTest.cs +++ b/Corgibytes.Freshli.Cli.Test/Functionality/History/ComputeHistoryActivityTest.cs @@ -48,7 +48,6 @@ public void FiresHistoryIntervalStopFoundEvents() var serviceProvider = new Mock(); _eventEngine.Setup(mock => mock.ServiceProvider).Returns(serviceProvider.Object); - var cacheDir = "example"; var cacheManager = new Mock(); cacheManager.Setup(mock => mock.GetCacheDb(It.IsAny())).Returns(_cacheDb.Object); serviceProvider.Setup(mock => mock.GetService(typeof(ICacheManager))).Returns(cacheManager.Object); @@ -58,7 +57,6 @@ public void FiresHistoryIntervalStopFoundEvents() // Act new ComputeHistoryActivity( "git", - cacheDir, new Guid("cbc83480-ae47-46de-91df-60747ca8fb09"), analysisLocation.Object ).Handle(_eventEngine.Object); diff --git a/Corgibytes.Freshli.Cli/CommandRunners/Git/GitCloneCommandRunner.cs b/Corgibytes.Freshli.Cli/CommandRunners/Git/GitCloneCommandRunner.cs index 5453d8f03..2c0a73711 100644 --- a/Corgibytes.Freshli.Cli/CommandRunners/Git/GitCloneCommandRunner.cs +++ b/Corgibytes.Freshli.Cli/CommandRunners/Git/GitCloneCommandRunner.cs @@ -36,7 +36,7 @@ public override int Run(GitCloneCommandOptions options, InvocationContext contex _eventEngine.On(clonedEvent => { // Output the id to the command line for use by the caller. - context.Console.Out.WriteLine(clonedEvent.GitRepositoryId); + context.Console.Out.WriteLine(clonedEvent.AnalysisLocation.RepositoryId); }); _eventEngine.On(clonedEvent => diff --git a/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs b/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs index 5eb3fa4b9..196b920de 100644 --- a/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs +++ b/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs @@ -1,5 +1,6 @@ using System; using Corgibytes.Freshli.Cli.Exceptions; +using Corgibytes.Freshli.Cli.Functionality.Analysis; using Corgibytes.Freshli.Cli.Functionality.Engine; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; @@ -52,12 +53,12 @@ public void Handle(IApplicationEventEngine eventClient) try { var gitRepository = _gitSourceRepository.CloneOrPull(_repoUrl, _branch, _cacheDir, _gitPath); + var analysisLocation = new AnalysisLocation(_cacheDir, gitRepository.Id); eventClient.Fire(new GitRepositoryClonedEvent { - GitRepositoryId = gitRepository.Id, AnalysisId = _analysisId, GitPath = _gitPath, - CacheDir = _cacheDir + AnalysisLocation = analysisLocation }); } catch (GitException e) diff --git a/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs b/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs index 38748e9ca..039fcaaae 100644 --- a/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs +++ b/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs @@ -7,17 +7,14 @@ namespace Corgibytes.Freshli.Cli.Functionality.Git; public class GitRepositoryClonedEvent : IApplicationEvent { - public string GitRepositoryId { get; init; } = null!; - public Guid AnalysisId { get; init; } public string GitPath { get; init; } = null!; - public string CacheDir { get; init; } = null!; + public AnalysisLocation AnalysisLocation { get; init; } = null!; public void Handle(IApplicationActivityEngine eventClient) { - var analysisLocation = new AnalysisLocation(CacheDir, GitRepositoryId); - eventClient.Dispatch(new ComputeHistoryActivity(GitPath, CacheDir, AnalysisId, analysisLocation)); + eventClient.Dispatch(new ComputeHistoryActivity(GitPath, AnalysisId, AnalysisLocation)); } } diff --git a/Corgibytes.Freshli.Cli/Functionality/History/ComputeHistoryActivity.cs b/Corgibytes.Freshli.Cli/Functionality/History/ComputeHistoryActivity.cs index 7634759e6..10f2d3f3c 100644 --- a/Corgibytes.Freshli.Cli/Functionality/History/ComputeHistoryActivity.cs +++ b/Corgibytes.Freshli.Cli/Functionality/History/ComputeHistoryActivity.cs @@ -10,18 +10,14 @@ public class ComputeHistoryActivity : IApplicationActivity { public Guid AnalysisId; - // ReSharper disable once MemberCanBePrivate.Global public readonly IAnalysisLocation AnalysisLocation; public readonly string GitExecutablePath; - public readonly string CacheDir; - - public ComputeHistoryActivity(string gitExecutablePath, string cacheDir, - Guid analysisId, IAnalysisLocation analysisLocation) + public ComputeHistoryActivity(string gitExecutablePath, Guid analysisId, + IAnalysisLocation analysisLocation) { GitExecutablePath = gitExecutablePath; - CacheDir = cacheDir; AnalysisId = analysisId; AnalysisLocation = analysisLocation; } @@ -30,7 +26,7 @@ public void Handle(IApplicationEventEngine eventClient) { var computeHistoryService = eventClient.ServiceProvider.GetRequiredService(); var cacheManager = eventClient.ServiceProvider.GetRequiredService(); - var cacheDb = cacheManager.GetCacheDb(CacheDir); + var cacheDb = cacheManager.GetCacheDb(AnalysisLocation.CacheDirectory); var analysis = cacheDb.RetrieveAnalysis(AnalysisId); if (analysis == null) { From 844d4ede2789d3dd8cb027b34128d7b2ea2e771a Mon Sep 17 00:00:00 2001 From: Kimarie Hoot Date: Tue, 13 Sep 2022 09:20:00 -0600 Subject: [PATCH 7/7] Formats git clone repository and compute history changes --- .../Functionality/Git/CloneGitRepositoryActivity.cs | 9 +++++---- .../Functionality/Git/GitRepositoryClonedEvent.cs | 4 +--- .../Functionality/History/ComputeHistoryActivity.cs | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs b/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs index bcaef2b9b..f05d210fb 100644 --- a/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs +++ b/Corgibytes.Freshli.Cli/Functionality/Git/CloneGitRepositoryActivity.cs @@ -14,9 +14,6 @@ public class CloneGitRepositoryActivity : IApplicationActivity [JsonProperty] private readonly string _cacheDir; [JsonProperty] private readonly string _gitPath; - [JsonProperty] private string? Branch { get; set; } - [JsonProperty] private string RepoUrl { get; set; } - public CloneGitRepositoryActivity(string repoUrl, string? branch, string cacheDir, string gitPath, Guid analysisId = new()) { @@ -27,6 +24,9 @@ public CloneGitRepositoryActivity(string repoUrl, string? branch, string cacheDi _analysisId = analysisId; } + [JsonProperty] private string? Branch { get; set; } + [JsonProperty] private string RepoUrl { get; set; } + public void Handle(IApplicationEventEngine eventClient) { // Clone or pull the given repository and branch. @@ -42,7 +42,8 @@ public void Handle(IApplicationEventEngine eventClient) } var gitRepository = - eventClient.ServiceProvider.GetRequiredService().CloneOrPull(RepoUrl, Branch, _cacheDir, _gitPath); + eventClient.ServiceProvider.GetRequiredService() + .CloneOrPull(RepoUrl, Branch, _cacheDir, _gitPath); var analysisLocation = new AnalysisLocation(_cacheDir, gitRepository.Id); diff --git a/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs b/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs index 039fcaaae..4b02bed34 100644 --- a/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs +++ b/Corgibytes.Freshli.Cli/Functionality/Git/GitRepositoryClonedEvent.cs @@ -13,8 +13,6 @@ public class GitRepositoryClonedEvent : IApplicationEvent public AnalysisLocation AnalysisLocation { get; init; } = null!; - public void Handle(IApplicationActivityEngine eventClient) - { + public void Handle(IApplicationActivityEngine eventClient) => eventClient.Dispatch(new ComputeHistoryActivity(GitPath, AnalysisId, AnalysisLocation)); - } } diff --git a/Corgibytes.Freshli.Cli/Functionality/History/ComputeHistoryActivity.cs b/Corgibytes.Freshli.Cli/Functionality/History/ComputeHistoryActivity.cs index f4a76490f..5b07fbcb6 100644 --- a/Corgibytes.Freshli.Cli/Functionality/History/ComputeHistoryActivity.cs +++ b/Corgibytes.Freshli.Cli/Functionality/History/ComputeHistoryActivity.cs @@ -9,11 +9,10 @@ namespace Corgibytes.Freshli.Cli.Functionality.History; public class ComputeHistoryActivity : IApplicationActivity { - public Guid AnalysisId; - public readonly IAnalysisLocation AnalysisLocation; public readonly string GitExecutablePath; + public Guid AnalysisId; public ComputeHistoryActivity(string gitExecutablePath, Guid analysisId, IAnalysisLocation analysisLocation)