Skip to content

Commit

Permalink
feat: added hook command runner
Browse files Browse the repository at this point in the history
  • Loading branch information
biohazard999 committed Dec 14, 2022
1 parent 059afdb commit 45badcd
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
19 changes: 18 additions & 1 deletion Xenial.RTool.Tests/ReleaseApplicationTests.cs
Expand Up @@ -16,17 +16,24 @@ public sealed class ReleaseApplicationTests
);
private TestConsole Console { get; } = new TestConsole();
private IGitCommandRunner CommandRunner { get; } = A.Fake<IGitCommandRunner>();
private IHookCommandRunner HookCommandRunner { get; } = A.Fake<IHookCommandRunner>();

private ReleaseContext CreateTestContext(string? cd = null)
=> new ReleaseContext(
FileSystem,
Console,
CommandRunner,
HookCommandRunner,
cd ?? Environment.CurrentDirectory
);

private (ReleaseApplication app, ReleaseContext ctx) CreateApplication()
=> (new ReleaseApplication(FileSystem, Console, CommandRunner), CreateTestContext());
=> (new ReleaseApplication(
FileSystem,
Console,
CommandRunner,
HookCommandRunner
), CreateTestContext());

[Fact]
public async Task CheckForGitMustNotCallNextWhenNotInGitRepo()
Expand Down Expand Up @@ -90,4 +97,14 @@ public async Task ConfirmBranches(string currentBranch, bool mustConfirm, bool c
await Verify(Console.Output)
.UseParameters(currentBranch, mustConfirm, confirm);
}

[Fact]
public async Task RunPreReleaseHooks()
{
var next = A.Fake<ReleaseApplicationDelegate>();
var (app, ctx) = CreateApplication();

//await app.RunPreReleaseHoocks(next, ctx);

}
}
17 changes: 16 additions & 1 deletion Xenial.RTool/GitCommandRunner.cs
@@ -1,6 +1,8 @@
using static SimpleExec.Command;

namespace Xenial.RTool; public sealed class GitCommandRunner : IGitCommandRunner
namespace Xenial.RTool;

public sealed class GitCommandRunner : IGitCommandRunner
{
public Task RunCommand(string command, string? cd = null)
=> RunAsync("git", command, workingDirectory: cd ?? Environment.CurrentDirectory);
Expand All @@ -12,3 +14,16 @@ public async Task<string> ReadCommand(string command, string? cd = null)
return result;
}
}

public sealed class HookCommandRunner : IHookCommandRunner
{
public Task RunCommand(string command, string args, string? cd = null)
=> RunAsync(command, args, workingDirectory: cd ?? Environment.CurrentDirectory);

public async Task<string> ReadCommand(string command, string args, string? cd = null)
{
var (stdOut, _) = (await ReadAsync(command, args, workingDirectory: cd ?? Environment.CurrentDirectory));
var result = stdOut.Trim();
return result;
}
}
6 changes: 6 additions & 0 deletions Xenial.RTool/IGitCommandRunner.cs
Expand Up @@ -5,3 +5,9 @@ public interface IGitCommandRunner
Task<string> ReadCommand(string command, string? cd = null);
Task RunCommand(string command, string? cd = null);
}

public interface IHookCommandRunner
{
Task<string> ReadCommand(string command, string args, string? cd = null);
Task RunCommand(string command, string args, string? cd = null);
}
7 changes: 6 additions & 1 deletion Xenial.RTool/Program.cs
Expand Up @@ -4,6 +4,11 @@

using Xenial.RTool;

var app = new ReleaseApplication(new FileSystem(), AnsiConsole.Console, new GitCommandRunner());
var app = new ReleaseApplication(
new FileSystem(),
AnsiConsole.Console,
new GitCommandRunner(),
new HookCommandRunner()
);

await app.Release();
11 changes: 9 additions & 2 deletions Xenial.RTool/ReleaseApplication.cs
Expand Up @@ -9,7 +9,8 @@ namespace Xenial.RTool;
public sealed record ReleaseApplication(
IFileSystem FileSystem,
IAnsiConsole AnsiConsole,
IGitCommandRunner CommandRunner
IGitCommandRunner CommandRunner,
IHookCommandRunner HookCommandRunner
)
{
public enum VersionIncrement
Expand Down Expand Up @@ -41,7 +42,12 @@ public Task Release()

var app = middleware.Build();

var context = new ReleaseContext(FileSystem, AnsiConsole, CommandRunner, CurrentDirectory);
var context = new ReleaseContext(
FileSystem,
AnsiConsole,
CommandRunner,
HookCommandRunner,
CurrentDirectory);

return app(context);
}
Expand Down Expand Up @@ -251,6 +257,7 @@ public sealed record ReleaseContext(
IFileSystem FileSystem,
IAnsiConsole Console,
IGitCommandRunner CommandRunner,
IHookCommandRunner HookCommandRunner,
string CurrentDirectory
)
{
Expand Down

0 comments on commit 45badcd

Please sign in to comment.