Skip to content

Commit

Permalink
Return compute-history --commit-history
Browse files Browse the repository at this point in the history
This should not have been removed in an earlier commit as this option is used by the analyse command (yet to be implemented).
  • Loading branch information
Edwin Kortman committed Aug 30, 2022
1 parent 53bb63b commit 3030120
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void Verify_argument_configuration()
private static TheoryData<string, ArgumentArity, int> DataForVerifyOptionConfiguration() =>
new()
{
{ "history-interval", ArgumentArity.ZeroOrOne, 0 },
{ "git-path", ArgumentArity.ZeroOrOne, 1 }
{ "commit-history", ArgumentArity.ZeroOrOne, 0 },
{ "history-interval", ArgumentArity.ZeroOrOne, 1 },
{ "git-path", ArgumentArity.ZeroOrOne, 2 }
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ public ComputeHistoryTest(ITestOutputHelper output) : base(output)
});
}

[Theory]
[MethodData(nameof(ExpectedStopsForCommitHistory))]
public void Verify_it_can_find_sha_identifiers_and_dates_for_the_all_commits(List<HistoryIntervalStop> expectedStops)
{
var analysisLocation = new Mock<IAnalysisLocation>();

Assert.Equivalent(expectedStops,
_computeHistory.ComputeCommitHistory(analysisLocation.Object, "git")
);
}

[Theory]
[MethodData(nameof(ExpectedStopsForDayInterval))]
[MethodData(nameof(ExpectedStopsForWeekInterval))]
Expand Down Expand Up @@ -132,4 +143,36 @@ private static TheoryData<List<HistoryIntervalStop>, string> ExpectedStopsForYea
"year"
}
};

private static TheoryData<List<HistoryIntervalStop>> ExpectedStopsForCommitHistory() =>
new()
{
new List<HistoryIntervalStop>
{
new(
"9cd8467fe93714da66bce9056d527d360c6389df",
new DateTimeOffset(2021, 2, 1, 19, 26, 16, TimeSpan.Zero)
),
new(
"a4792063da2ebb7628b66b9f238cba300b18ab00",
new DateTimeOffset(2021, 2, 1, 19, 27, 42, TimeSpan.Zero)
),
new(
"57e5112ae54b7bec8a5294b7cbba2fd9bbd0a75c",
new DateTimeOffset(2021, 2, 2, 10, 13, 46, TimeSpan.Zero)
),
new(
"b2bd95f16a8587dd0bd618ea3415fc8928832c91",
new DateTimeOffset(2021, 2, 2, 13, 17, 05, TimeSpan.Zero)
),
new(
"75c7fcc7336ee718050c4a5c8dfb5598622787b2",
new DateTimeOffset(2021, 2, 20, 12, 31, 34, TimeSpan.Zero)
),
new(
"583d813db3e28b9b44a29db352e2f0e1b4c6e420",
new DateTimeOffset(2021, 5, 19, 15, 24, 24, TimeSpan.Zero)
)
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Corgibytes.Freshli.Cli.CommandOptions;
public class ComputeHistoryCommandOptions : CommandOptions
{
public string RepositoryId { get; set; } = null!;
public bool CommitHistory { get; set; }
public string HistoryInterval { get; set; } = null!;
public string GitPath { get; set; } = null!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public ComputeHistoryCommandRunner(IServiceProvider serviceProvider, Runner runn

public override int Run(ComputeHistoryCommandOptions options, InvocationContext context)
{
if (options.CommitHistory)
{
WriteStopsToLines(
_computeHistory.ComputeCommitHistory(new AnalysisLocation(options.RepositoryId, options.CacheDir), options.GitPath),
context);
return 0;
}

var historyIntervalDuration = options.HistoryInterval switch
{
"d" => "day",
Expand Down
8 changes: 8 additions & 0 deletions Corgibytes.Freshli.Cli/Commands/Git/ComputeHistoryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public ComputeHistoryCommand() : base("compute-history",

AddArgument(repositoryIdentifier);

var commitHistory = new Option<bool>("--commit-history",
"Analyzes only the points in time when files have changed in the commit history")
{
AllowMultipleArgumentsPerToken = false,
Arity = ArgumentArity.ZeroOrOne
};
AddOption(commitHistory);

var historyInterval = new Option<string>("--history-interval",
description:
"As the analyze command moves backwards in time through the history of the project, what time interval should it use to determine the points in time that are sampled. Possible values: y(ears), m(onths), w(eeks), d(ays)",
Expand Down
7 changes: 7 additions & 0 deletions Corgibytes.Freshli.Cli/Functionality/Git/ComputeHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,11 @@ into mostRecentCommitForThisGroupedPeriod
mostRecentCommitForThisGroupedPeriod.CommittedAt))
.ToList();
}

public IEnumerable<HistoryIntervalStop> ComputeCommitHistory(IAnalysisLocation analysisLocation, string gitPath)
{
var commitHistory = _listCommits.ForRepository(analysisLocation, gitPath);
return commitHistory
.Select(gitCommit => new HistoryIntervalStop(gitCommit.ShaIdentifier, gitCommit.CommittedAt)).ToList();
}
}
2 changes: 2 additions & 0 deletions Corgibytes.Freshli.Cli/Functionality/Git/IComputeHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public IEnumerable<HistoryIntervalStop> ComputeWithHistoryInterval(
string gitPath,
string historyInterval
);

public IEnumerable<HistoryIntervalStop> ComputeCommitHistory(IAnalysisLocation analysisLocation, string gitPath);
}
12 changes: 12 additions & 0 deletions features/compute_history.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ Feature: Compute history
05/19/2021 15:24:24 -04:00 583d813db3e28b9b44a29db352e2f0e1b4c6e420
"""

Scenario: Entire commit history
When I run `freshli git clone https://github.com/corgibytes/freshli-fixture-csharp-test.git`
When I run `freshli git compute-history --commit-history 6a2c5b97bc5113bda4845c09637043aef3d499f5b62eb252314a6bbcc7afd589`
Then the output should contain:
"""
05/19/2021 15:24:24 -04:00 583d813db3e28b9b44a29db352e2f0e1b4c6e420
02/20/2021 12:31:34 -05:00 75c7fcc7336ee718050c4a5c8dfb5598622787b2
02/02/2021 13:17:05 -05:00 b2bd95f16a8587dd0bd618ea3415fc8928832c91
02/02/2021 10:13:46 -05:00 57e5112ae54b7bec8a5294b7cbba2fd9bbd0a75c
02/01/2021 19:27:42 -05:00 a4792063da2ebb7628b66b9f238cba300b18ab00
02/01/2021 19:26:16 -05:00 9cd8467fe93714da66bce9056d527d360c6389df
"""

0 comments on commit 3030120

Please sign in to comment.