-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from corgibytes/compute-history
Compute history
- Loading branch information
Showing
15 changed files
with
216 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
Corgibytes.Freshli.Cli.Test/Functionality/History/ComputeHistoryActivityTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Corgibytes.Freshli.Cli.DataModel; | ||
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.History; | ||
|
||
public class ComputeHistoryActivityTest | ||
{ | ||
private readonly Mock<ICacheDb> _cacheDb = new(); | ||
private readonly Mock<IComputeHistory> _computeHistory = new(); | ||
private readonly Mock<IApplicationEventEngine> _eventEngine = new(); | ||
|
||
[Fact] | ||
public void FiresHistoryIntervalStopFoundEvents() | ||
{ | ||
// Arrange | ||
// Have an analysis available | ||
var cachedAnalysis = new CachedAnalysis("https://lorem-ipsum.com", "main", "month"); | ||
_cacheDb.Setup(mock => mock.RetrieveAnalysis(It.IsAny<Guid>())).Returns(cachedAnalysis); | ||
|
||
|
||
// Have interval stops available | ||
var historyIntervalStops = new List<HistoryIntervalStop> | ||
{ | ||
new( | ||
"75c7fcc7336ee718050c4a5c8dfb5598622787b2", | ||
new DateTimeOffset(2021, 2, 20, 12, 31, 34, TimeSpan.Zero) | ||
), | ||
new( | ||
"583d813db3e28b9b44a29db352e2f0e1b4c6e420", | ||
new DateTimeOffset(2021, 5, 19, 15, 24, 24, TimeSpan.Zero) | ||
) | ||
}; | ||
_computeHistory.Setup(mock => mock.ComputeWithHistoryInterval( | ||
It.IsAny<IAnalysisLocation>(), It.IsAny<string>(), It.IsAny<string>()) | ||
) | ||
.Returns(historyIntervalStops); | ||
|
||
var analysisLocation = new Mock<IAnalysisLocation>(); | ||
|
||
// Act | ||
new ComputeHistoryActivity( | ||
"git", | ||
_cacheDb.Object, | ||
_computeHistory.Object, | ||
new Guid("cbc83480-ae47-46de-91df-60747ca8fb09"), | ||
analysisLocation.Object | ||
).Handle(_eventEngine.Object); | ||
|
||
// Assert | ||
_eventEngine.Verify( | ||
mock => mock.Fire( | ||
It.Is<HistoryIntervalStopFoundEvent>( | ||
value => | ||
value.GitCommitIdentifier == "75c7fcc7336ee718050c4a5c8dfb5598622787b2" && value.AnalysisLocation == analysisLocation.Object | ||
) | ||
) | ||
); | ||
_eventEngine.Verify( | ||
mock => mock.Fire( | ||
It.Is<HistoryIntervalStopFoundEvent>( | ||
value => | ||
value.GitCommitIdentifier == "583d813db3e28b9b44a29db352e2f0e1b4c6e420" && value.AnalysisLocation == analysisLocation.Object | ||
) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
Corgibytes.Freshli.Cli/Functionality/Analysis/AnalysisLocation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Corgibytes.Freshli.Cli.Functionality.Analysis; | ||
|
||
public class AnalysisLocation : IAnalysisLocation | ||
{ | ||
private readonly string _repositoryId; | ||
private readonly string _cacheDirectory; | ||
|
||
public AnalysisLocation(string repositoryId, string cacheDirectory) | ||
{ | ||
_repositoryId = repositoryId; | ||
_cacheDirectory = cacheDirectory; | ||
} | ||
|
||
public string Path => _cacheDirectory + "/repositories/" + _repositoryId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
Corgibytes.Freshli.Cli/Functionality/Git/IComputeHistory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections.Generic; | ||
using Corgibytes.Freshli.Cli.Functionality.Analysis; | ||
|
||
namespace Corgibytes.Freshli.Cli.Functionality.Git; | ||
|
||
public interface IComputeHistory | ||
{ | ||
public IEnumerable<HistoryIntervalStop> ComputeWithHistoryInterval( | ||
IAnalysisLocation analysisLocation, | ||
string gitPath, | ||
string historyInterval | ||
); | ||
|
||
public IEnumerable<HistoryIntervalStop> ComputeCommitHistory(IAnalysisLocation analysisLocation, string gitPath); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
using System.Collections.Generic; | ||
using Corgibytes.Freshli.Cli.Functionality.Analysis; | ||
|
||
namespace Corgibytes.Freshli.Cli.Functionality.Git; | ||
|
||
public interface IListCommits | ||
{ | ||
public IEnumerable<GitCommit> ForRepository(string repositoryId, string cacheDir, string gitPath); | ||
public IEnumerable<GitCommit> ForRepository(IAnalysisLocation analysisLocation, string gitPath); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
Corgibytes.Freshli.Cli/Functionality/History/ComputeHistoryActivity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using Corgibytes.Freshli.Cli.Functionality.Analysis; | ||
using Corgibytes.Freshli.Cli.Functionality.Engine; | ||
using Corgibytes.Freshli.Cli.Functionality.Git; | ||
using Newtonsoft.Json; | ||
|
||
namespace Corgibytes.Freshli.Cli.Functionality.History; | ||
|
||
public class ComputeHistoryActivity : IApplicationActivity | ||
{ | ||
[JsonProperty] private readonly Guid _analysisId; | ||
[JsonProperty] private readonly ICacheDb _cacheDb; | ||
[JsonProperty] private readonly IComputeHistory _computeHistoryService; | ||
private readonly string _gitExecutablePath; | ||
[JsonProperty] private readonly IAnalysisLocation _analysisLocation; | ||
|
||
public ComputeHistoryActivity(string gitExecutablePath, ICacheDb cacheDb, IComputeHistory computeHistoryService, | ||
Guid analysisId, IAnalysisLocation analysisLocation) | ||
{ | ||
_gitExecutablePath = gitExecutablePath; | ||
_cacheDb = cacheDb; | ||
_computeHistoryService = computeHistoryService; | ||
_analysisId = analysisId; | ||
_analysisLocation = analysisLocation; | ||
} | ||
|
||
public void Handle(IApplicationEventEngine eventClient) | ||
{ | ||
var analysis = _cacheDb.RetrieveAnalysis(_analysisId); | ||
if (analysis == null) | ||
{ | ||
return; | ||
} | ||
|
||
var historyIntervalStops = | ||
_computeHistoryService.ComputeWithHistoryInterval(_analysisLocation, _gitExecutablePath, analysis.HistoryInterval); | ||
|
||
foreach (var historyIntervalStop in historyIntervalStops) | ||
{ | ||
eventClient.Fire(new HistoryIntervalStopFoundEvent | ||
{ | ||
GitCommitIdentifier = historyIntervalStop.GitCommitIdentifier, | ||
AnalysisLocation = _analysisLocation | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.