Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Add failongiterror as parameter to report any git error as NuKeeper e… #1140

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NuKeeper.Abstractions/Configuration/FileSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class FileSettings

public string GitCliPath { get; set; }
public int? MaxOpenPullRequests { get; set; }
public bool? ThrowOnGitError { get; set; }

public static FileSettings Empty()
{
Expand Down
2 changes: 2 additions & 0 deletions NuKeeper.Abstractions/Configuration/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class UserSettings

public UsePrerelease UsePrerelease { get; set; }

public bool ThrowOnGitError { get; set; }


public OutputFormat OutputFormat { get; set; }
public OutputDestination OutputDestination { get; set; }
Expand Down
17 changes: 12 additions & 5 deletions NuKeeper.Git/LibGit2SharpDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,19 @@ public Task Commit(string message)
{
return Task.Run(() =>
{
_logger.Detailed($"Git commit with message '{message}'");
using (var repo = MakeRepo())
try
{
_logger.Detailed($"Git commit with message '{message}'");
using (var repo = MakeRepo())
{
var signature = GetSignature(repo);
GitCommands.Stage(repo, "*");
repo.Commit(message, signature, signature);
}
}
catch (EmptyCommitException)
{
var signature = GetSignature(repo);
GitCommands.Stage(repo, "*");
repo.Commit(message, signature, signature);
_logger.Normal($"Empty commit with message '{message}' is ignored");
}
});
}
Expand Down
17 changes: 11 additions & 6 deletions NuKeeper.Inspection.Tests/NuGetApi/ApiPackageLookupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public async Task WhenNoPackagesAreFound()
CurrentVersion123("TestPackage"),
NuGetSources.GlobalFeed,
VersionChange.Major,
UsePrerelease.FromPrerelease);
UsePrerelease.FromPrerelease,
true);

Assert.That(updates, Is.Not.Null);
Assert.That(updates.Major, Is.Null);
Expand All @@ -48,7 +49,8 @@ public async Task WhenThereIsOnlyOneVersion()
CurrentVersion123("TestPackage"),
NuGetSources.GlobalFeed,
VersionChange.Major,
UsePrerelease.FromPrerelease);
UsePrerelease.FromPrerelease,
true);

Assert.That(updates, Is.Not.Null);

Expand All @@ -74,7 +76,8 @@ public async Task WhenMajorVersionChangesAreAllowed(VersionChange dataRange,
CurrentVersion123("TestPackage"),
NuGetSources.GlobalFeed,
VersionChange.Major,
UsePrerelease.FromPrerelease);
UsePrerelease.FromPrerelease,
true);

AssertPackagesIdentityIs(updates, "TestPackage");
Assert.That(updates.Selected().Identity.Version, Is.EqualTo(expectedUpdate));
Expand All @@ -98,7 +101,8 @@ public async Task WhenMinorVersionChangesAreAllowed(VersionChange dataRange,
CurrentVersion123("TestPackage"),
NuGetSources.GlobalFeed,
VersionChange.Minor,
UsePrerelease.FromPrerelease);
UsePrerelease.FromPrerelease,
true);

AssertPackagesIdentityIs(updates, "TestPackage");
Assert.That(updates.Selected().Identity.Version, Is.EqualTo(expectedUpdate));
Expand All @@ -122,7 +126,8 @@ public async Task WhenPatchVersionChangesAreAllowed(VersionChange dataRange,
CurrentVersion123("TestPackage"),
NuGetSources.GlobalFeed,
VersionChange.Patch,
UsePrerelease.FromPrerelease);
UsePrerelease.FromPrerelease,
true);

AssertPackagesIdentityIs(updates, "TestPackage");
Assert.That(updates.Selected().Identity.Version, Is.EqualTo(expectedUpdate));
Expand All @@ -132,7 +137,7 @@ public async Task WhenPatchVersionChangesAreAllowed(VersionChange dataRange,
private static IPackageVersionsLookup MockVersionLookup(List<PackageSearchMetadata> actualResults)
{
var allVersions = Substitute.For<IPackageVersionsLookup>();
allVersions.Lookup(Arg.Any<string>(), Arg.Any<bool>(), Arg.Any<NuGetSources>())
allVersions.Lookup(Arg.Any<string>(), Arg.Any<bool>(), Arg.Any<bool>(), Arg.Any<NuGetSources>())
.Returns(actualResults);
return allVersions;
}
Expand Down
30 changes: 18 additions & 12 deletions NuKeeper.Inspection.Tests/NuGetApi/BulkPackageLookupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ public async Task CanLookupEmptyList()
Enumerable.Empty<PackageIdentity>(),
NuGetSources.GlobalFeed,
VersionChange.Major,
UsePrerelease.FromPrerelease);
UsePrerelease.FromPrerelease,
true);

Assert.That(results, Is.Not.Null);
Assert.That(results, Is.Empty);

await apiLookup.DidNotReceive().FindVersionUpdate(
Arg.Any<PackageIdentity>(), Arg.Any<NuGetSources>(), Arg.Any<VersionChange>(), Arg.Any<UsePrerelease>());
Arg.Any<PackageIdentity>(), Arg.Any<NuGetSources>(), Arg.Any<VersionChange>(), Arg.Any<UsePrerelease>(), Arg.Any<bool>());
}

[Test]
Expand All @@ -54,7 +55,8 @@ public async Task CanLookupOnePackage()
var results = await bulkLookup.FindVersionUpdates(queries,
NuGetSources.GlobalFeed,
VersionChange.Major,
UsePrerelease.FromPrerelease);
UsePrerelease.FromPrerelease,
true);

Assert.That(results, Is.Not.Null);
Assert.That(results, Is.Not.Empty);
Expand All @@ -79,10 +81,11 @@ public async Task LookupOnePackageCallsApiOnce()
await bulkLookup.FindVersionUpdates(queries,
NuGetSources.GlobalFeed,
VersionChange.Major,
UsePrerelease.FromPrerelease);
UsePrerelease.FromPrerelease,
true);

await apiLookup.Received(1).FindVersionUpdate(
Arg.Any<PackageIdentity>(), Arg.Any<NuGetSources>(), Arg.Any<VersionChange>(), Arg.Any<UsePrerelease>());
Arg.Any<PackageIdentity>(), Arg.Any<NuGetSources>(), Arg.Any<VersionChange>(), Arg.Any<UsePrerelease>(), Arg.Any<bool>());
}

[Test]
Expand All @@ -104,7 +107,8 @@ public async Task CanLookupTwoPackages()
var results = await bulkLookup.FindVersionUpdates(queries,
NuGetSources.GlobalFeed,
VersionChange.Major,
UsePrerelease.FromPrerelease);
UsePrerelease.FromPrerelease,
true);

var packages = results.Select(kvp => kvp.Key);
Assert.That(results.Count, Is.EqualTo(2));
Expand Down Expand Up @@ -132,10 +136,11 @@ public async Task LookupTwoPackagesCallsApiTwice()
await bulkLookup.FindVersionUpdates(queries,
NuGetSources.GlobalFeed,
VersionChange.Major,
UsePrerelease.FromPrerelease);
UsePrerelease.FromPrerelease,
true);

await apiLookup.Received(2).FindVersionUpdate(
Arg.Any<PackageIdentity>(), Arg.Any<NuGetSources>(), Arg.Any<VersionChange>(), Arg.Any<UsePrerelease>());
Arg.Any<PackageIdentity>(), Arg.Any<NuGetSources>(), Arg.Any<VersionChange>(), Arg.Any<UsePrerelease>(), Arg.Any<bool>());
}

[Test]
Expand All @@ -156,13 +161,14 @@ public async Task WhenThereAreMultipleVersionOfTheSamePackage()
var results = await bulkLookup.FindVersionUpdates(queries,
NuGetSources.GlobalFeed,
VersionChange.Major,
UsePrerelease.FromPrerelease);
UsePrerelease.FromPrerelease,
true);

await apiLookup.Received(1).FindVersionUpdate(
Arg.Any<PackageIdentity>(), Arg.Any<NuGetSources>(), Arg.Any<VersionChange>(), Arg.Any<UsePrerelease>());
Arg.Any<PackageIdentity>(), Arg.Any<NuGetSources>(), Arg.Any<VersionChange>(), Arg.Any<UsePrerelease>(), Arg.Any<bool>());
await apiLookup.Received(1).FindVersionUpdate(Arg.Is<PackageIdentity>(
pi => pi.Id == "foo" && pi.Version == new NuGetVersion(1, 3, 4)),
Arg.Any<NuGetSources>(), Arg.Any<VersionChange>(), Arg.Any<UsePrerelease>());
Arg.Any<NuGetSources>(), Arg.Any<VersionChange>(), Arg.Any<UsePrerelease>(), Arg.Any<bool>());

var packages = results.Select(kvp => kvp.Key);
Assert.That(results.Count, Is.EqualTo(1));
Expand All @@ -177,7 +183,7 @@ private static void ApiHasNewVersionForPackage(IApiPackageLookup lookup, string
DateTimeOffset.Now, null);

lookup.FindVersionUpdate(Arg.Is<PackageIdentity>(pm => pm.Id == packageName),
Arg.Any<NuGetSources>(), Arg.Any<VersionChange>(), Arg.Any<UsePrerelease>())
Arg.Any<NuGetSources>(), Arg.Any<VersionChange>(), Arg.Any<UsePrerelease>(), Arg.Any<bool>())
.Returns(new PackageLookupResult(VersionChange.Major, responseMetaData, responseMetaData, responseMetaData));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public void Initialize()
Arg.Any<PackageIdentity>(),
Arg.Any<NuGetSources>(),
VersionChange.Minor,
Arg.Any<UsePrerelease>()
Arg.Any<UsePrerelease>(),
Arg.Any<bool>()
)
.Returns(ci =>
GetPackageLookupResult(
Expand All @@ -54,7 +55,8 @@ public async Task FindUpdatesForPackages_OnePackageDifferentVersionsInDifferentP
packagesInProjects,
new NuGetSources("https://api.nuget.com/"),
VersionChange.Minor,
UsePrerelease.Never
UsePrerelease.Never,
true
);

var versionUpdates = result.Select(p => p.SelectedVersion.ToNormalizedString()).ToList();
Expand Down
22 changes: 14 additions & 8 deletions NuKeeper.Inspection.Tests/NuGetApi/UsePrereleaseLookupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public async Task WhenFromPrereleaseIsAllowedFromPrereleaseAndCurrentVersionIsPr
CurrentVersion123Prerelease("TestPackage"),
NuGetSources.GlobalFeed,
VersionChange.Major,
UsePrerelease.FromPrerelease);
UsePrerelease.FromPrerelease,
true);

AssertPackagesIdentityIs(updates, "TestPackage");
Assert.That(updates.Selected().Identity.Version, Is.EqualTo(expectedUpdate));
Expand All @@ -67,7 +68,8 @@ public async Task WhenFromPrereleaseIsAllowedFromPrereleaseAndCurrentVersionIsSt
CurrentVersion123("TestPackage"),
NuGetSources.GlobalFeed,
VersionChange.Major,
UsePrerelease.FromPrerelease);
UsePrerelease.FromPrerelease,
true);

AssertPackagesIdentityIs(updates, "TestPackage");
Assert.That(updates.Selected().Identity.Version, Is.EqualTo(expectedUpdate));
Expand Down Expand Up @@ -102,7 +104,8 @@ public async Task WhenFromPrereleaseIsAlwaysAllowedAndCurrentVersionIsPrerelease
CurrentVersion123Prerelease("TestPackage"),
NuGetSources.GlobalFeed,
VersionChange.Major,
UsePrerelease.Always);
UsePrerelease.Always,
true);

AssertPackagesIdentityIs(updates, "TestPackage");
Assert.That(updates.Selected().Identity.Version, Is.EqualTo(expectedUpdate));
Expand Down Expand Up @@ -137,7 +140,8 @@ public async Task WhenFromPrereleaseIsAlwaysAllowedAndCurrentVersionIsStable(
CurrentVersion123("TestPackage"),
NuGetSources.GlobalFeed,
VersionChange.Major,
UsePrerelease.Always);
UsePrerelease.Always,
true);

AssertPackagesIdentityIs(updates, "TestPackage");
Assert.That(updates.Selected().Identity.Version, Is.EqualTo(expectedUpdate));
Expand All @@ -162,7 +166,8 @@ public async Task WhenFromPrereleaseIsNeverAllowedAndCurrentVersionIsPrerelease(
CurrentVersion123Prerelease("TestPackage"),
NuGetSources.GlobalFeed,
VersionChange.Major,
UsePrerelease.Never);
UsePrerelease.Never,
true);

AssertPackagesIdentityIs(updates, "TestPackage");
Assert.That(updates.Selected().Identity.Version, Is.EqualTo(expectedUpdate));
Expand All @@ -187,7 +192,8 @@ public async Task WhenFromPrereleaseIsNeverAllowedAndCurrentVersionIsStable(
CurrentVersion123("TestPackage"),
NuGetSources.GlobalFeed,
VersionChange.Major,
UsePrerelease.Never);
UsePrerelease.Never,
true);

AssertPackagesIdentityIs(updates, "TestPackage");
Assert.That(updates.Selected().Identity.Version, Is.EqualTo(expectedUpdate));
Expand All @@ -197,9 +203,9 @@ public async Task WhenFromPrereleaseIsNeverAllowedAndCurrentVersionIsStable(
private static IPackageVersionsLookup MockVersionLookup(List<PackageSearchMetadata> actualResults)
{
var allVersions = Substitute.For<IPackageVersionsLookup>();
allVersions.Lookup(Arg.Any<string>(), false, Arg.Any<NuGetSources>())
allVersions.Lookup(Arg.Any<string>(), false, true, Arg.Any<NuGetSources>())
.Returns(actualResults.Where(x => !x.Identity.Version.IsPrerelease).ToList());
allVersions.Lookup(Arg.Any<string>(), true, Arg.Any<NuGetSources>())
allVersions.Lookup(Arg.Any<string>(), true, true, Arg.Any<NuGetSources>())
.Returns(actualResults);
return allVersions;
}
Expand Down
17 changes: 9 additions & 8 deletions NuKeeper.Inspection.Tests/UpdateFinderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task FindWithoutResults()
var finder = new UpdateFinder(scanner, updater, logger);

var results = await finder.FindPackageUpdateSets(
folder, NuGetSources.GlobalFeed, VersionChange.Major, UsePrerelease.FromPrerelease);
folder, NuGetSources.GlobalFeed, VersionChange.Major, UsePrerelease.FromPrerelease, true);

Assert.That(results, Is.Not.Null);
Assert.That(results.Count, Is.EqualTo(0));
Expand Down Expand Up @@ -63,7 +63,7 @@ public async Task FindWithOneResult()
var finder = new UpdateFinder(scanner, updater, logger);

var results = await finder.FindPackageUpdateSets(
folder, NuGetSources.GlobalFeed, VersionChange.Major, UsePrerelease.FromPrerelease);
folder, NuGetSources.GlobalFeed, VersionChange.Major, UsePrerelease.FromPrerelease, true);

Assert.That(results, Is.Not.Null);
Assert.That(results.Count, Is.EqualTo(1));
Expand Down Expand Up @@ -93,7 +93,7 @@ public async Task FindOneFilteredIncludeResult()
var finder = new UpdateFinder(scanner, updater, logger);

var results = await finder.FindPackageUpdateSets(
folder, NuGetSources.GlobalFeed, VersionChange.Major, UsePrerelease.FromPrerelease, new Regex("^somePackage"), null);
folder, NuGetSources.GlobalFeed, VersionChange.Major, UsePrerelease.FromPrerelease, true, new Regex("^somePackage"), null);

Assert.That(results, Is.Not.Null);
Assert.That(results.Count, Is.EqualTo(1));
Expand Down Expand Up @@ -124,7 +124,7 @@ public async Task FindTwoFilteredExcludeIncludeResults()
var finder = new UpdateFinder(scanner, updater, logger);

var results = await finder.FindPackageUpdateSets(
folder, NuGetSources.GlobalFeed, VersionChange.Major, UsePrerelease.FromPrerelease, new Regex("^andAnotherPackage"), new Regex("^anotherPackage"));
folder, NuGetSources.GlobalFeed, VersionChange.Major, UsePrerelease.FromPrerelease, true, new Regex("^andAnotherPackage"), new Regex("^anotherPackage"));

Assert.That(results, Is.Not.Null);
Assert.That(results.Count, Is.EqualTo(1));
Expand Down Expand Up @@ -154,7 +154,7 @@ public async Task FindOneFilteredExcludeResult()
var finder = new UpdateFinder(scanner, updater, logger);

var results = await finder.FindPackageUpdateSets(
folder, NuGetSources.GlobalFeed, VersionChange.Major, UsePrerelease.FromPrerelease, null, new Regex("^anotherPackage"));
folder, NuGetSources.GlobalFeed, VersionChange.Major, UsePrerelease.FromPrerelease, true, null, new Regex("^anotherPackage"));

Assert.That(results, Is.Not.Null);
Assert.That(results.Count, Is.EqualTo(1));
Expand Down Expand Up @@ -184,7 +184,7 @@ public async Task FindSkipsMetapackageResult()
var finder = new UpdateFinder(scanner, updater, logger);

var results = await finder.FindPackageUpdateSets(
folder, NuGetSources.GlobalFeed, VersionChange.Major, UsePrerelease.FromPrerelease);
folder, NuGetSources.GlobalFeed, VersionChange.Major, UsePrerelease.FromPrerelease, true);

Assert.That(results, Is.Not.Null);
Assert.That(results.Count, Is.EqualTo(1));
Expand Down Expand Up @@ -216,7 +216,7 @@ public async Task FindSkipsBothMetapackageResult()
var finder = new UpdateFinder(scanner, updater, logger);

var results = await finder.FindPackageUpdateSets(
folder, NuGetSources.GlobalFeed, VersionChange.Major, UsePrerelease.FromPrerelease);
folder, NuGetSources.GlobalFeed, VersionChange.Major, UsePrerelease.FromPrerelease, true);

Assert.That(results, Is.Not.Null);
Assert.That(results.Count, Is.EqualTo(1));
Expand All @@ -236,7 +236,8 @@ private void ReturnsUpdateSetForEachPackage(IPackageUpdatesLookup updater)
Arg.Any<IReadOnlyCollection<PackageInProject>>(),
Arg.Any<NuGetSources>(),
Arg.Any<VersionChange>(),
Arg.Any<UsePrerelease>())
Arg.Any<UsePrerelease>(),
Arg.Any<bool>())
.Returns(a => a.ArgAt<IReadOnlyCollection<PackageInProject>>(0)
.Select(BuildPackageUpdateSet)
.ToList());
Expand Down
1 change: 1 addition & 0 deletions NuKeeper.Inspection/IUpdateFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Task<IReadOnlyCollection<PackageUpdateSet>> FindPackageUpdateSets(
NuGetSources sources,
VersionChange allowedChange,
UsePrerelease usePrerelease,
bool throwOnGitError,
Regex include = null,
Regex exclude = null);
}
Expand Down
5 changes: 3 additions & 2 deletions NuKeeper.Inspection/NuGetApi/ApiPackageLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public async Task<PackageLookupResult> FindVersionUpdate(
PackageIdentity package,
NuGetSources sources,
VersionChange allowedChange,
UsePrerelease usePrerelease)
UsePrerelease usePrerelease,
bool throwOnGitError)
{
if (package == null)
{
Expand All @@ -30,7 +31,7 @@ public async Task<PackageLookupResult> FindVersionUpdate(

var includePrerelease = ShouldAllowPrerelease(package, usePrerelease);

var foundVersions = await _packageVersionsLookup.Lookup(package.Id, includePrerelease, sources);
var foundVersions = await _packageVersionsLookup.Lookup(package.Id, includePrerelease, throwOnGitError, sources);
return VersionChanges.MakeVersions(package.Version, foundVersions, allowedChange);
}

Expand Down
Loading