From eedb1f24866e331b8d40261483cd438bd0f06b61 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Sat, 4 Apr 2026 04:46:00 +0000 Subject: [PATCH] Run ReSharper code cleanup --- .../Configuration/AppSettings.cs | 2 +- .../VersionCalculatorFactory.cs | 8 +- .../WhenCalculatingVersionFromShallowClone.cs | 89 ++++++++++++++++--- 3 files changed, 80 insertions(+), 19 deletions(-) diff --git a/source/OctoVersion.Core/Configuration/AppSettings.cs b/source/OctoVersion.Core/Configuration/AppSettings.cs index 7c00f18..51b9aa1 100644 --- a/source/OctoVersion.Core/Configuration/AppSettings.cs +++ b/source/OctoVersion.Core/Configuration/AppSettings.cs @@ -88,4 +88,4 @@ public IEnumerable Validate(ValidationContext validationContex if (string.IsNullOrWhiteSpace(CurrentBranch) && string.IsNullOrWhiteSpace(FullSemVer)) yield return new ValidationResult($"At least one of {nameof(CurrentBranch)} or {nameof(FullSemVer)} must be provided.", new[] { nameof(CurrentBranch), nameof(FullSemVer) }); } -} +} \ No newline at end of file diff --git a/source/OctoVersion.Core/VersionNumberCalculation/VersionCalculatorFactory.cs b/source/OctoVersion.Core/VersionNumberCalculation/VersionCalculatorFactory.cs index 2bd3dd8..ce2c853 100644 --- a/source/OctoVersion.Core/VersionNumberCalculation/VersionCalculatorFactory.cs +++ b/source/OctoVersion.Core/VersionNumberCalculation/VersionCalculatorFactory.cs @@ -15,7 +15,7 @@ public class VersionCalculatorFactory readonly bool _allowShallowClone; public VersionCalculatorFactory(string repositorySearchPath) - : this(repositorySearchPath, allowShallowClone: false) + : this(repositorySearchPath, false) { } @@ -67,12 +67,12 @@ public VersionCalculator Create() if (!commits.TryGetValue(parent.Sha, out var simpleParent)) { // In a shallow clone, boundary commits may reference parents outside the available history. Skip them rather than blowing up with a KeyNotFoundException. - if (_allowShallowClone) + if (_allowShallowClone) continue; throw new KeyNotFoundException("Unable to find parent commit with hash " + parent.Sha); } - + simpleCommit.AddParent(simpleParent); } } @@ -104,4 +104,4 @@ public VersionCalculator Create() var calculator = new VersionCalculator(commits.Values.ToArray(), currentCommitHash); return calculator; } -} +} \ No newline at end of file diff --git a/source/OctoVersion.Tests/WhenCalculatingVersionFromShallowClone.cs b/source/OctoVersion.Tests/WhenCalculatingVersionFromShallowClone.cs index 645fe84..3176f3a 100644 --- a/source/OctoVersion.Tests/WhenCalculatingVersionFromShallowClone.cs +++ b/source/OctoVersion.Tests/WhenCalculatingVersionFromShallowClone.cs @@ -12,14 +12,32 @@ namespace OctoVersion.Tests; /// public class WhenCalculatingVersionFromShallowClone { - static SimpleCommit MakeCommit(string hash, DateTimeOffset timestamp, string message = "normal commit") - => new(hash, message, timestamp, false, false); + static SimpleCommit MakeCommit(string hash, DateTimeOffset timestamp, string message = "normal commit") + { + return new SimpleCommit(hash, + message, + timestamp, + false, + false); + } - static SimpleCommit MakeMajorBumpCommit(string hash, DateTimeOffset timestamp) - => new(hash, "+semver: major", timestamp, true, false); + static SimpleCommit MakeMajorBumpCommit(string hash, DateTimeOffset timestamp) + { + return new SimpleCommit(hash, + "+semver: major", + timestamp, + true, + false); + } - static SimpleCommit MakeMinorBumpCommit(string hash, DateTimeOffset timestamp) - => new(hash, "+semver: minor", timestamp, false, true); + static SimpleCommit MakeMinorBumpCommit(string hash, DateTimeOffset timestamp) + { + return new SimpleCommit(hash, + "+semver: minor", + timestamp, + false, + true); + } [Fact] public void WhenShallowBoundaryHasVersionTag_VersionIsCalculatedRelativeToTag() @@ -30,7 +48,13 @@ public void WhenShallowBoundaryHasVersionTag_VersionIsCalculatedRelativeToTag() // A (parent: B) ← HEAD // Expected: HEAD = 2.0.2 - var baseTime = new DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero); + var baseTime = new DateTimeOffset(2024, + 1, + 1, + 0, + 0, + 0, + TimeSpan.Zero); var commitC = MakeCommit("ccc", baseTime); var commitB = MakeCommit("bbb", baseTime.AddMinutes(1)); @@ -56,7 +80,13 @@ public void WhenShallowBoundaryHasNoTag_VersionCountsFromZero() // A (parent: B) ← HEAD // The shallow boundary commit itself counts as 0.0.1, so HEAD = 0.0.2 - var baseTime = new DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero); + var baseTime = new DateTimeOffset(2024, + 1, + 1, + 0, + 0, + 0, + TimeSpan.Zero); var commitB = MakeCommit("bbb", baseTime); var commitA = MakeCommit("aaa", baseTime.AddMinutes(1)); @@ -78,7 +108,14 @@ public void WhenShallowBoundaryIsTheCurrentCommit_VersionIsCalculatedFromZero() // A (no parents — shallow boundary) ← HEAD // Expected: 0.0.1 - var commitA = MakeCommit("aaa", new DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero)); + var commitA = MakeCommit("aaa", + new DateTimeOffset(2024, + 1, + 1, + 0, + 0, + 0, + TimeSpan.Zero)); var calculator = new VersionCalculator([commitA], commitA.Hash); var version = calculator.GetVersion(); @@ -98,7 +135,13 @@ public void WhenMergeCommitHasOneParentCutByShallowClone_VersionUsesRemainingPar // B (parent: C) // A (parent: B — the other merge parent was outside shallow history) ← HEAD - var baseTime = new DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero); + var baseTime = new DateTimeOffset(2024, + 1, + 1, + 0, + 0, + 0, + TimeSpan.Zero); var commitC = MakeCommit("ccc", baseTime); var commitB = MakeCommit("bbb", baseTime.AddMinutes(1)); @@ -130,7 +173,13 @@ public void WhenVersionTagExistsWithinShallowHistory_TagTakesPrecedenceOverCount // A (parent: B) ← HEAD // Expected: HEAD = 1.5.2 - var baseTime = new DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero); + var baseTime = new DateTimeOffset(2024, + 1, + 1, + 0, + 0, + 0, + TimeSpan.Zero); var commitD = MakeCommit("ddd", baseTime); var commitC = MakeCommit("ccc", baseTime.AddMinutes(1)); @@ -161,7 +210,13 @@ public void WhenMajorBumpCommitIsAboveShallowBoundary_MajorVersionIsIncremented( // A (parent: B) ← HEAD // Expected: B = 2.0.0, HEAD = 2.0.1 - var baseTime = new DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero); + var baseTime = new DateTimeOffset(2024, + 1, + 1, + 0, + 0, + 0, + TimeSpan.Zero); var commitC = MakeCommit("ccc", baseTime); var commitB = MakeMajorBumpCommit("bbb", baseTime.AddMinutes(1)); @@ -190,7 +245,13 @@ public void WhenMinorBumpCommitIsAboveShallowBoundary_MinorVersionIsIncremented( // A (parent: B) ← HEAD // Expected: B = 1.1.0, HEAD = 1.1.1 - var baseTime = new DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero); + var baseTime = new DateTimeOffset(2024, + 1, + 1, + 0, + 0, + 0, + TimeSpan.Zero); var commitC = MakeCommit("ccc", baseTime); var commitB = MakeMinorBumpCommit("bbb", baseTime.AddMinutes(1)); @@ -207,4 +268,4 @@ public void WhenMinorBumpCommitIsAboveShallowBoundary_MinorVersionIsIncremented( version.Minor.ShouldBe(1); version.Patch.ShouldBe(1); } -} +} \ No newline at end of file