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

add setting for commit message prefix --commitmessageprefix #1147

Open
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface ICommitWorder
{
string MakePullRequestTitle(IReadOnlyCollection<PackageUpdateSet> updates);

string MakeCommitMessage(PackageUpdateSet updates);
string MakeCommitMessage(PackageUpdateSet updates, string commitMessagePrefix);

string MakeCommitDetails(IReadOnlyCollection<PackageUpdateSet> updates);
}
Expand Down
7 changes: 7 additions & 0 deletions NuKeeper.Abstractions/Configuration/CommitSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace NuKeeper.Abstractions.Configuration
{
public class CommitSettings
{
public string CommitMessagePrefix { get; set; }
}
}
2 changes: 2 additions & 0 deletions NuKeeper.Abstractions/Configuration/FileSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class FileSettings
public string BranchNameTemplate { get; set; }
public bool? DeleteBranchAfterMerge { get; set; }

public string CommitMessagePrefix { get; set; }

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

Expand Down
2 changes: 2 additions & 0 deletions NuKeeper.Abstractions/Configuration/SettingsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class SettingsContainer

public BranchSettings BranchSettings { get; set; }

public CommitSettings CommitSettings { get; set; }

public IFolder WorkingFolder { get; set; }
}
}
4 changes: 2 additions & 2 deletions NuKeeper.AzureDevOps/AzureDevOpsCommitWorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ private static string PackageTitle(PackageUpdateSet updates)
return $"{CommitEmoji} Automatic update of {updates.SelectedId} to {updates.SelectedVersion}";
}

public string MakeCommitMessage(PackageUpdateSet updates)
public string MakeCommitMessage(PackageUpdateSet updates, string commitMessagePrefix)
{
if (updates == null)
{
throw new ArgumentNullException(nameof(updates));
}

return $"{PackageTitle(updates)}";
return $"{commitMessagePrefix}{PackageTitle(updates)}";
}

public string MakeCommitDetails(IReadOnlyCollection<PackageUpdateSet> updates)
Expand Down
4 changes: 2 additions & 2 deletions NuKeeper.BitBucket/BitbucketCommitWorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ private static string PackageTitle(PackageUpdateSet updates)
return $"Automatic update of {updates.SelectedId} to {updates.SelectedVersion}";
}

public string MakeCommitMessage(PackageUpdateSet updates)
public string MakeCommitMessage(PackageUpdateSet updates, string commitMessagePrefix)
{
if (updates == null)
{
throw new ArgumentNullException(nameof(updates));
}

return $":{CommitEmoji}: {PackageTitle(updates)}";
return $"{commitMessagePrefix}:{CommitEmoji}: {PackageTitle(updates)}";
}

public string MakeCommitDetails(IReadOnlyCollection<PackageUpdateSet> updates)
Expand Down
6 changes: 3 additions & 3 deletions NuKeeper.Integration.Tests/Engine/ExistingCommitFilterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task DoFilter()

var subject = MakeExistingCommitFilter();

var result = await subject.Filter(git, updates.AsReadOnly(), "base", "head");
var result = await subject.Filter(git, updates.AsReadOnly(), "base", "head", string.Empty);

Assert.AreEqual(1, result.Count);
Assert.AreEqual("First.Nuget", result.FirstOrDefault()?.SelectedId);
Expand All @@ -64,7 +64,7 @@ public async Task DoNotFilter()

var subject = MakeExistingCommitFilter();

var result = await subject.Filter(git, updates.AsReadOnly(), "base", "head");
var result = await subject.Filter(git, updates.AsReadOnly(), "base", "head", string.Empty);

Assert.AreEqual(2, result.Count);
}
Expand All @@ -77,7 +77,7 @@ private IExistingCommitFilter MakeExistingCommitFilter()
collaborationFactory.CollaborationPlatform.Returns(gitClient);

var commitWorder = Substitute.For<ICommitWorder>();
commitWorder.MakeCommitMessage(Arg.Any<PackageUpdateSet>()).Returns(p => $"Automatic update of {((PackageUpdateSet)p[0]).SelectedId} to {((PackageUpdateSet)p[0]).SelectedVersion}");
commitWorder.MakeCommitMessage(Arg.Any<PackageUpdateSet>(), Arg.Any<string>()).Returns(p => $"Automatic update of {((PackageUpdateSet)p[0]).SelectedId} to {((PackageUpdateSet)p[0]).SelectedVersion}");
collaborationFactory.CommitWorder.Returns(commitWorder);

return new ExistingCommitFilter(collaborationFactory, NukeeperLogger);
Expand Down
12 changes: 6 additions & 6 deletions NuKeeper.Tests/Engine/DefaultCommitWorderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,35 @@ public void MakeCommitMessage_OneUpdateIsCorrect()
{
var updates = PackageUpdates.For(MakePackageForV110());

var report = _sut.MakeCommitMessage(updates);
var report = _sut.MakeCommitMessage(updates, "someprefix: ");

Assert.That(report, Is.Not.Null);
Assert.That(report, Is.Not.Empty);
Assert.That(report, Is.EqualTo(":package: Automatic update of foo.bar to 1.2.3"));
Assert.That(report, Is.EqualTo("someprefix: :package: Automatic update of foo.bar to 1.2.3"));
}

[Test]
public void MakeCommitMessage_TwoUpdatesIsCorrect()
{
var updates = PackageUpdates.For(MakePackageForV110(), MakePackageForV100());

var report = _sut.MakeCommitMessage(updates);
var report = _sut.MakeCommitMessage(updates, "someprefix: ");

Assert.That(report, Is.Not.Null);
Assert.That(report, Is.Not.Empty);
Assert.That(report, Is.EqualTo(":package: Automatic update of foo.bar to 1.2.3"));
Assert.That(report, Is.EqualTo("someprefix: :package: Automatic update of foo.bar to 1.2.3"));
}

[Test]
public void MakeCommitMessage_TwoUpdatesSameVersionIsCorrect()
{
var updates = PackageUpdates.For(MakePackageForV110(), MakePackageForV110InProject3());

var report = _sut.MakeCommitMessage(updates);
var report = _sut.MakeCommitMessage(updates, "someprefix: ");

Assert.That(report, Is.Not.Null);
Assert.That(report, Is.Not.Empty);
Assert.That(report, Is.EqualTo(":package: Automatic update of foo.bar to 1.2.3"));
Assert.That(report, Is.EqualTo("someprefix: :package: Automatic update of foo.bar to 1.2.3"));
}


Expand Down
6 changes: 6 additions & 0 deletions NuKeeper.Tests/Engine/Packages/PackageUpdaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void Initialize()
Arg.Any<IGitDriver>(),
Arg.Any<IReadOnlyCollection<PackageUpdateSet>>(),
Arg.Any<string>(),
Arg.Any<string>(),
Arg.Any<string>()
)
.Returns(ci => ((IReadOnlyCollection<PackageUpdateSet>)ci[1]));
Expand Down Expand Up @@ -115,6 +116,7 @@ public async Task MakeUpdatePullRequest_UpdateDoesNotCreatePrDueToExistingCommit
Arg.Any<IGitDriver>(),
Arg.Any<IReadOnlyCollection<PackageUpdateSet>>(),
Arg.Any<string>(),
Arg.Any<string>(),
Arg.Any<string>()
)
.Returns(new List<PackageUpdateSet>(), new List<PackageUpdateSet> { packageSetTwo });
Expand Down Expand Up @@ -245,6 +247,10 @@ private static SettingsContainer MakeSettings(
{
MaxPackageUpdates = 3,
MinimumAge = new TimeSpan(7, 0, 0, 0),
},
CommitSettings = new CommitSettings
{
CommitMessagePrefix = string.Empty
}
};
}
Expand Down
6 changes: 5 additions & 1 deletion NuKeeper.Tests/Engine/RepositoryUpdaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int expectedPrs

var filteredUpdates = updates.Skip(existingCommitsPerBranch).ToList().AsReadOnly();

existingCommitFilder.Filter(Arg.Any<IGitDriver>(), Arg.Any<IReadOnlyCollection<PackageUpdateSet>>(), Arg.Any<string>(), Arg.Any<string>()).Returns(filteredUpdates);
existingCommitFilder.Filter(Arg.Any<IGitDriver>(), Arg.Any<IReadOnlyCollection<PackageUpdateSet>>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>()).Returns(filteredUpdates);

var settings = MakeSettings(consolidateUpdates);

Expand Down Expand Up @@ -358,6 +358,10 @@ private static SettingsContainer MakeSettings(
{
MaxPackageUpdates = 3,
MinimumAge = new TimeSpan(7, 0, 0, 0),
},
CommitSettings = new CommitSettings
{
CommitMessagePrefix = string.Empty
}
};
}
Expand Down
9 changes: 9 additions & 0 deletions NuKeeper/Commands/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ internal abstract class CommandBase
Description = "Template used for creating the branch name.")]
public string BranchNameTemplate { get; set; }

[Option(CommandOptionType.SingleValue, ShortName = "", LongName = "commitmessageprefix",
Description = "Prefix used for the package update commit messages, e. g. an issue number")]
public string CommitMessagePrefix { get; set; }

[Option(CommandOptionType.SingleValue, ShortName = "git", LongName = "gitclipath",
Description = "Path to git to use instead of lib2gitsharp implementation")]
public string GitCliPath { get; set; }
Expand Down Expand Up @@ -131,6 +135,7 @@ private SettingsContainer MakeSettings()
var allowedChange = Concat.FirstValue(AllowedChange, fileSettings.Change, VersionChange.Major);
var usePrerelease = Concat.FirstValue(UsePrerelease, fileSettings.UsePrerelease, Abstractions.Configuration.UsePrerelease.FromPrerelease);
var branchNameTemplate = Concat.FirstValue(BranchNameTemplate, fileSettings.BranchNameTemplate);
var commitMessagePrefix = Concat.FirstValue(CommitMessagePrefix, fileSettings.CommitMessagePrefix);
var gitpath = Concat.FirstValue(GitCliPath, fileSettings.GitCliPath);

var settings = new SettingsContainer
Expand All @@ -147,6 +152,10 @@ private SettingsContainer MakeSettings()
BranchSettings = new BranchSettings
{
BranchNameTemplate = branchNameTemplate
},
CommitSettings = new CommitSettings
{
CommitMessagePrefix = commitMessagePrefix
}
};

Expand Down
4 changes: 2 additions & 2 deletions NuKeeper/Engine/DefaultCommitWorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ private static string PackageTitle(PackageUpdateSet updates)
return $"Automatic update of {updates.SelectedId} to {updates.SelectedVersion}";
}

public string MakeCommitMessage(PackageUpdateSet updates)
public string MakeCommitMessage(PackageUpdateSet updates, string commitMessagePrefix)
{
if (updates == null)
{
throw new ArgumentNullException(nameof(updates));
}

return $":{CommitEmoji}: {PackageTitle(updates)}";
return $"{commitMessagePrefix}:{CommitEmoji}: {PackageTitle(updates)}";
}

public string MakeCommitDetails(IReadOnlyCollection<PackageUpdateSet> updates)
Expand Down
4 changes: 2 additions & 2 deletions NuKeeper/Engine/Packages/ExistingCommitFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ExistingCommitFilter(ICollaborationFactory collaborationFactory, INuKeepe
_logger = logger;
}

public async Task<IReadOnlyCollection<PackageUpdateSet>> Filter(IGitDriver git, IReadOnlyCollection<PackageUpdateSet> updates, string baseBranch, string headBranch)
public async Task<IReadOnlyCollection<PackageUpdateSet>> Filter(IGitDriver git, IReadOnlyCollection<PackageUpdateSet> updates, string baseBranch, string headBranch, string commitMessagePrefix)
{
if (git == null)
{
Expand All @@ -41,7 +41,7 @@ public async Task<IReadOnlyCollection<PackageUpdateSet>> Filter(IGitDriver git,

foreach (var update in updates)
{
var updateCommitMessage = _collaborationFactory.CommitWorder.MakeCommitMessage(update);
var updateCommitMessage = _collaborationFactory.CommitWorder.MakeCommitMessage(update, commitMessagePrefix);
var compactUpdateCommitMessage = new string(updateCommitMessage.Where(c => !char.IsWhiteSpace(c)).ToArray());

if (!compactCommitMessages.Contains(compactUpdateCommitMessage))
Expand Down
3 changes: 2 additions & 1 deletion NuKeeper/Engine/Packages/IExistingCommitFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Task<IReadOnlyCollection<PackageUpdateSet>> Filter(
IGitDriver git,
IReadOnlyCollection<PackageUpdateSet> updates,
string baseBranch,
string headBranch);
string headBranch,
string commitMessagePrefix);
}
}
6 changes: 3 additions & 3 deletions NuKeeper/Engine/Packages/PackageUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,18 @@ SettingsContainer settings
await git.CheckoutRemoteToLocal(branchWithChanges);
}

var filteredUpdates = await _existingCommitFilter.Filter(git, updates, repository.DefaultBranch, branchWithChanges);
var filteredUpdates = await _existingCommitFilter.Filter(git, updates, repository.DefaultBranch, branchWithChanges, settings.CommitSettings.CommitMessagePrefix);

foreach (var filtered in updates.Where(u => !filteredUpdates.Contains(u)))
{
var commitMessage = _collaborationFactory.CommitWorder.MakeCommitMessage(filtered);
var commitMessage = _collaborationFactory.CommitWorder.MakeCommitMessage(filtered, settings.CommitSettings.CommitMessagePrefix);
_logger.Normal($"Commit '{commitMessage}' already in branch '{branchWithChanges}'");
}

var haveUpdates = filteredUpdates.Any();
foreach (var updateSet in filteredUpdates)
{
var commitMessage = _collaborationFactory.CommitWorder.MakeCommitMessage(updateSet);
var commitMessage = _collaborationFactory.CommitWorder.MakeCommitMessage(updateSet, settings.CommitSettings.CommitMessagePrefix);

await _updateRunner.Update(updateSet, sources);

Expand Down
12 changes: 6 additions & 6 deletions Nukeeper.AzureDevOps.Tests/AzureDevOpsCommitWorderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,35 @@ public void MakeCommitMessage_OneUpdateIsCorrect()
{
var updates = PackageUpdates.For(MakePackageForV110());

var report = _sut.MakeCommitMessage(updates);
var report = _sut.MakeCommitMessage(updates, "someprefix: ");

Assert.That(report, Is.Not.Null);
Assert.That(report, Is.Not.Empty);
Assert.That(report, Is.EqualTo($"{CommitEmoji} Automatic update of foo.bar to 1.2.3"));
Assert.That(report, Is.EqualTo($"someprefix: {CommitEmoji} Automatic update of foo.bar to 1.2.3"));
}

[Test]
public void MakeCommitMessage_TwoUpdatesIsCorrect()
{
var updates = PackageUpdates.For(MakePackageForV110(), MakePackageForV100());

var report = _sut.MakeCommitMessage(updates);
var report = _sut.MakeCommitMessage(updates, "someprefix: ");

Assert.That(report, Is.Not.Null);
Assert.That(report, Is.Not.Empty);
Assert.That(report, Is.EqualTo($"{CommitEmoji} Automatic update of foo.bar to 1.2.3"));
Assert.That(report, Is.EqualTo($"someprefix: {CommitEmoji} Automatic update of foo.bar to 1.2.3"));
}

[Test]
public void MakeCommitMessage_TwoUpdatesSameVersionIsCorrect()
{
var updates = PackageUpdates.For(MakePackageForV110(), MakePackageForV110InProject3());

var report = _sut.MakeCommitMessage(updates);
var report = _sut.MakeCommitMessage(updates, "someprefix: ");

Assert.That(report, Is.Not.Null);
Assert.That(report, Is.Not.Empty);
Assert.That(report, Is.EqualTo($"{CommitEmoji} Automatic update of foo.bar to 1.2.3"));
Assert.That(report, Is.EqualTo($"someprefix: {CommitEmoji} Automatic update of foo.bar to 1.2.3"));
}

[Test]
Expand Down