chore: improvements
This commit is contained in:
@@ -19,13 +19,23 @@ namespace Cli
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
public async Task Run(string repoPath)
|
||||
public async Task Run(string workingDir)
|
||||
{
|
||||
// Check if git dir
|
||||
var repoBasePath = "";
|
||||
try
|
||||
{
|
||||
repoBasePath = await _mediator.Send(new GetRepoBasePath.Query(workingDir));
|
||||
}
|
||||
catch (CliWrap.Exceptions.CommandExecutionException)
|
||||
{
|
||||
AnsiConsole.Markup("[red]Error:[/] Unable to extract Versions. Are we running inside a git repository?\n\n");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
var services = new List<string>();
|
||||
try
|
||||
{
|
||||
services = await _mediator.Send(new GetServicesFromGitRepo.Query(repoPath));
|
||||
services = await _mediator.Send(new GetServicesFromGitRepo.Query(repoBasePath));
|
||||
}
|
||||
catch (LibGit2Sharp.RepositoryNotFoundException)
|
||||
{
|
||||
@@ -45,7 +55,7 @@ namespace Cli
|
||||
}
|
||||
|
||||
|
||||
var versionInfo = await _mediator.Send(new GetVersionInformationFromRepo.Query(repoPath, chosenService));
|
||||
var versionInfo = await _mediator.Send(new GetVersionInformationFromRepo.Query(repoBasePath, chosenService));
|
||||
Selection selection;
|
||||
if (versionInfo != null)
|
||||
{
|
||||
@@ -82,7 +92,7 @@ namespace Cli
|
||||
|
||||
try
|
||||
{
|
||||
await _mediator.Send(new AddTagToGitRepo.Command(repoPath, selection.Version.ToString()));
|
||||
await _mediator.Send(new AddTagToGitRepo.Command(workingDir, selection.Version.ToString()));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -93,7 +103,7 @@ namespace Cli
|
||||
|
||||
try
|
||||
{
|
||||
await _mediator.Send(new PushCommitsToRemote.Command(repoPath));
|
||||
await _mediator.Send(new PushCommitsToRemote.Command(workingDir));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Commands
|
||||
{
|
||||
public class PushCommitsToRemote : RequestHandler<PushCommitsToRemote.Command>
|
||||
public class PushCommitsToRemote : AsyncRequestHandler<PushCommitsToRemote.Command>
|
||||
{
|
||||
private readonly IGitRepoWriteService _gitRepoWriteService;
|
||||
|
||||
@@ -22,10 +24,9 @@ namespace Application.Commands
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void Handle(Command request)
|
||||
protected override async Task Handle(Command request, CancellationToken cancellationToken)
|
||||
{
|
||||
_gitRepoWriteService.Push(request.RepoPath);
|
||||
await _gitRepoWriteService.Push(request.RepoPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Models;
|
||||
|
||||
namespace Application.Interfaces
|
||||
{
|
||||
public interface IGitRepoReadService
|
||||
{
|
||||
public IEnumerable<Version> GetAllVersions(string repoPath);
|
||||
IEnumerable<Version> GetAllVersions(string repoPath);
|
||||
Task<string> GetRepoBasePath(string workingDir);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Application.Interfaces
|
||||
{
|
||||
public interface IGitRepoWriteService
|
||||
{
|
||||
void AddTag(string repoPath, string tag);
|
||||
void Push(string repoPath);
|
||||
Task Push(string repoPath);
|
||||
}
|
||||
}
|
||||
33
src/Core/Queries/GetRepoBasePath.cs
Normal file
33
src/Core/Queries/GetRepoBasePath.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Queries
|
||||
{
|
||||
public class GetRepoBasePath : IRequestHandler<GetRepoBasePath.Query, string>
|
||||
{
|
||||
public class Query : IRequest<string>
|
||||
{
|
||||
public Query(string workingDir)
|
||||
{
|
||||
WorkingDir = workingDir;
|
||||
}
|
||||
|
||||
public string WorkingDir { get; }
|
||||
}
|
||||
|
||||
private readonly IGitRepoReadService _gitRepoReadService;
|
||||
|
||||
public GetRepoBasePath(IGitRepoReadService gitRepoReadService)
|
||||
{
|
||||
_gitRepoReadService = gitRepoReadService;
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> Handle(Query request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _gitRepoReadService.GetRepoBasePath(request.WorkingDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CliWrap" Version="3.3.3" />
|
||||
<PackageReference Include="LibGit2Sharp" Version="0.26.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
|
||||
<PackageReference Include="semver" Version="2.0.6" />
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using CliWrap;
|
||||
using CliWrap.Buffered;
|
||||
using LibGit2Sharp;
|
||||
using Semver;
|
||||
using Version = Application.Models.Version;
|
||||
@@ -8,6 +11,15 @@ namespace Infrastructure.Services
|
||||
{
|
||||
public class GitRepoReadService : IGitRepoReadService
|
||||
{
|
||||
public async Task<string> GetRepoBasePath(string workingDir)
|
||||
{
|
||||
var result = await Cli.Wrap("git")
|
||||
.WithArguments("rev-parse --show-toplevel")
|
||||
.WithWorkingDirectory(workingDir)
|
||||
.ExecuteBufferedAsync();
|
||||
return result.StandardOutput.Trim();
|
||||
}
|
||||
|
||||
public IEnumerable<Version> GetAllVersions(string repoPath)
|
||||
{
|
||||
using var repo = new Repository(repoPath);
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using CliWrap;
|
||||
using CliWrap.Buffered;
|
||||
using LibGit2Sharp;
|
||||
|
||||
namespace Infrastructure.Services
|
||||
@@ -11,10 +14,12 @@ namespace Infrastructure.Services
|
||||
repo.ApplyTag(tag);
|
||||
}
|
||||
|
||||
public void Push(string repoPath)
|
||||
public async Task Push(string repoPath)
|
||||
{
|
||||
using var repo = new Repository(repoPath);
|
||||
repo.Network.Push(repo.Head);
|
||||
await Cli.Wrap("git")
|
||||
.WithArguments("push --tags")
|
||||
.WithWorkingDirectory(repoPath)
|
||||
.ExecuteBufferedAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user